(Tutorials) Virtual boxes

April 17, 2010

Use lxc to create virtual boxes on ubuntu

Source: http://lxc.sourceforge.net/

Here I show you how to create virtual ubuntu (hardy) boxes on a
ubuntu 10.04 lucid (beta 2) system using lxc.

Lxc is more sophisticated and probably easier to install then chrooted boxes.
I used to use OpenVZ to easily create virtual boxes but OpenVZ is not really supported
anymore with ubuntu: the needed kernel patch probably caused to much headaches…
Lxc seems to be a logical successor.

First I installed lucid on my eee box pc (type EB1012).
This is done by creating a bootable lucid usb stick, put the stick in one of the
six usb ports on the eeebox, press F2 and keep it pressed while powering on the eeebox.
Change harddrive order and bootorder in the bios and reboot from your usb.
Choose install, fdisk whole disk and install a ssh-server.

Goal is to create, say, 3 hardy boxes (box1, box2 and box3) using lxc.
box1 will be an apache server and will be named “lxc-apache”
box2 wil be a backup server using backupPC and will be named “lxc-backuppc”
box3 will be a slave dns-server and will be named “lxc-bind”
The steps:
Login to your fresh lucid beta 2 install

$ sudo -s
# apt-get update
# apt-get dist-upgrade
# apt-get install lxc
# apt-get install bridge-utils
# mkdir -p /var/lib/lxc/
# cd !$
# wget http://www.stgraber.org/download/lxc-ubuntu-8.04-i386.tar.gz
# tar xf lxc-ubuntu-8.04-i386.tar.gz
# mv ubuntu lxc-apache
# tar xf lxc-ubuntu-8.04-i386.tar.gz
# mv ubuntu lxc-backuppc
# tar xf lxc-ubuntu-8.04-i386.tar.gz
# mv ubuntu lxc-bind
# mv lxc-ubuntu-8.04-i386.tar.gz template-lxc-ubuntu-8.04-i386.tar.gz

Now create a script to edit some settings of all three boxes: config_boxes

# ./config_boxes
# sudo mkdir /dev/cgroup && mount -t cgroup none /dev/cgroup
# vi /etc/network/interfaces :

    auto lo eth0 br0
    iface lo inet loopback
    iface br0 inet static
      address 192.168.1.x
      bridge_ports eth0
      bridge_maxwait 0

# /etc/init.d/networking restart (reboot?)

Now login to one of the three boxes:

# lxc-start -d -n lxc_apache
# lxc-console -n lxc_apache
Type <Ctrl+a q> to exit the console
lxc-ubuntu login: root
Password: secret
root@lxc-apache:# apt-get update
root@lxc-apache:# apt-get dist-upgrade
root@lxc-apache:# apt-get install apache2
root@lxc-apache:# apt-get install …

Have fun!

"Why is lemon juice made with artificial flavor, and dishwashing liquid made with real lemons?"

Powered by Wordpress. Theme by Shlomi Noach, openark.org
© 2017 KwaLinux Trainingen | Algemene voorwaarden | KvK: 10147727 | Disclaimer