Saturday, May 30, 2015

Running VMs on G4 machines with LXC

It is really fun testing out different distributions. You get to see their differences and their strength/weaknesses. The one drawback is the need to keep installing ISO over and over again. I have seen people with G5 machine run qemu to host VM guests. However on G4 machine I do not think there are enough resources to really to this with taking some type of perfomance hit. Then I came across using Linux Containers (lxc) and it was exactly what I needed! So what lxc offers is virtualazation at OS level rather than on the hardware level via hypervizors. QEMU, Zen, KVM,and VB all viritalize the hardware, meaning each VM has its own dedicated hardware. Now if you have more than one core and few Gigs of RAM than this is no issue. However G4 machines at the max have 2G of ram and most are single CPU. This greatly limits what can be accomplished using hypervizors. Since lxc virtualizes on the OS level you guests will share your resources. On my iBook G4 with a single 1.42 GHz cpu and 1.5G of RAM running an instance of Debian as an lxc container performed really well. Below I will walk you through the install and set of lxc on PowerPC.

Install and Initial Setup

The following packages were the ones I used to get lxc working.
sudo apt-get install lxc bridge-utils libvirt-bin debootstrap
These will get you lxc working and allow to connect to your home network. Once you have these package installed there are somethings you need to check. First you want to be sure your kernel has all the correct configuration for lxc. The command to use is lxc-checkconfig. This will verify your kernel configuration. The output should be same as below,
rican-linux@iBookG4-Debian9:~$ sudo lxc-checkconfig
[sudo] password for rican-linux:
Kernel configuration not found at /proc/config.gz; searching…
          kernel-configuration-found-at-/boot/config-3.16.0-4-powerpc
Namespaces —-
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enablede
Multiple /dev/pts instances: enabled
—- Control groups —-
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
—- Misc —-
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig
rican-linux@iBookG4-Debian9:~$
All the settings should show enabled. LXC comes with predefined templates that you can use to install containers. These templates can be found in the /usr/share/lxc/templates directory. Since this is on a PowerPC machine you can only install templates that support this architecture. Which leaves you with Debian, Ubuntu, Gentoo, and OpenSUSE. Right now I have been able to successfuly create containers for Debain and Ubuntu. There are some issue with the other two that I am looking into. Now to create a container the command to run is lxc-create. So to create a Debian container this is they syntax to use,
sudo lxc-create -n container_name -t debian
One the proces is complete a root password will be given that you should change one you launch the container and login. Before that step you should set up the networking so that you container can access the internet.

Networking

The process I used to manage my network connections is libvirt. It basically creates a vitual bridge so your VMs in the LXC containers can access the network. If you have libvirt already installed then to see if you bridge is ready run this command sudo virsh net-info default. The output should be as below,
rican-linux@iBookG4-Debian9:~$ sudo virsh net-info default
[sudo] password for rican-linux:
Name: default
UUID: d57736ba-96cc-4798-aefa-1a046fdb1de8
Active: yes
Persistent: yes
Autostart: no
Bridge: virbr0
If the active field is set to no then enable the bridge with this command virsh net-start default. The field should be now set to yes and you should see the interface if you run sudo ifconfig -a.
rican-linux@iBookG4-Debian9:~$ sudo ifconfig -a
….
virbr0 Link encap:Ethernet HWaddr 52:54:00:4a:83:be
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:454898 errors:0 dropped:0 overruns:0 frame:0
TX packets:897541 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:77865967 (74.2 MiB) TX bytes:1259670602 (1.1 GiB)
virbr0-nic Link encap:Ethernet HWaddr 52:54:00:4a:83:be
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
….
The ip address shown is controlled by this configuration file, /var/lib/libvirt/network/default.xml. This file also controls the dhcp scope of the virtual network and where you can set static reservations. You can read more on this on the Debian Wiki here.

LXC running and VNC setup

Now that lxc is install, a Debian container is created, and the networking is set,it is time to run the container and set up VNC. The command to start a container is the following,
sudo lxc-start -F -n container_name
The -F option puts you in the console on your terminal session. Once you login you want to be sure you have an ip address and can reach the internet. Once that is verified, next is to run sudo apt-get update && sudo apt-get upgrade so that the latest packages are installed. Then install the DE you want to login to. The best choice that does consume too much resources is LXDE. The command to install is simply sudo apt-get install lxde for Debain or sudo apt-get install lubuntu-desktop for Ubuntu. Finally it is time to install the VNC server. Follow the steps below,
Install the server
sudo apt-get install vnc4server
create a non-privilaged user
adduser test
su test
as the user start and stop the server
vnc4server :1 -geometry 800x600 -depth 24
vnc4server -kill :1 -geometry 800x600 -depth 24
edit the xstartup file
nano ~/.vnc/xstartup
add at the end (Debian)
/usr/bin/lxsession -s LXDE &
add at the end (Ubuntu)
/usr/bin/lxsession -e LXDE -s Lubuntu &
restart the server
vnc4server :1 -geometry 800x600 -depth 24
The server will ask for a password when it is launch for the first time. The password will be used to login via the VNC client. On the host there are a few choices for a vnc client. There are two good command line client vncviewer and vnc4viewer. When they are installed to start the session using vncviewer by entering the following,
vncviewer ip address:1
enter password
The session should open in a window and you are done! If you want a gui client then remmina is a great choice. Below are some screenshots. If you want more info on lxc check out the Debian Wiki here




Tuesday, May 12, 2015

Noobslabs is an awesome site!

I am currently running Debian Testing (Stretch) on my iBook G4. I posted a brief review of the install here.  I like spending time tweaking it out. Putting in new wallpapers, themes, and icons. Another tool I love is conky. This tool is light system monitor that displays statistics on your desktop. It is very customizable and people have shared their configurations for people to use. Sometimes these configurations are hard to implement and require some tweaking. I do not mind tinkering but sometimes I just want something to work on install. Well I came accross Noobslab and found my answer! This site is designed for people who new to Linux specifically Debian based distros like Ubuntu and Mint. They have PPAs to install themes and icon sets which make setting up themes on your Ubuntu or Mint install so much easier. They also have great start up scripts for conky as well that work any distro. They have some really great designs to choose from and you can download a wired or wireless setup depending on which interface you wish to monitor. Getting this working on my iBook was extremely simple. If you are looking for a nice conky set up then this is definitely a place to check out!.