Created
August 16, 2011 22:01
-
-
Save vvuksan/1150301 to your computer and use it in GitHub Desktop.
LXC (Linux Containers Installation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This works under Ubuntu 10.10. I tried under 10.04 LTS but the Ubuntu templates are not there. Investigating. | |
[ Leaving this link here for reference in case I need to do apt-get upgrade. @ohloh recommends it | |
http://sourceforge.net/mailarchive/message.php?msg_id=26885493 ] | |
To make things easy have libvirt installed ie. | |
sudo apt-get install libvirt-bin | |
Otherwise you will need to set up bridges, iptables, dnsmasq. | |
Once that is done. Back up | |
/etc/libvirt/qemu/networks/default.xml | |
Then type | |
virsh net-destroy default | |
then change the 192.168.122 in default.xml to your net of choice | |
copy to /etc/libvirt/qemu/networks/default.xml | |
virsh net-create default | |
virsh net-autostart default | |
Make sure | |
ifconfig virbr0 | |
has the right IP | |
Then | |
apt-get install lxc | |
mkdir /cgroup | |
echo "none /cgroup cgroup defaults 0 0" >> /etc/fstab | |
mount /cgroup | |
==> Create a base box | |
- lxc-create -n base -t ubuntu | |
- let it rip | |
If you want additional bridges | |
- add a bridge e.g. | |
- brctl addbr br100 | |
- ifconfig br100 inet 172.16.100.1/24 | |
To configure networking for the box in | |
/var/lib/lxc/basebox/config add these lines | |
lxc.network.type = veth | |
lxc.network.flags = up | |
lxc.network.name = eth0 | |
lxc.network.link = virbr0 | |
You can add additional network interfaces by adding more e.g. | |
lxc.network.type = veth | |
lxc.network.flags = up | |
lxc.network.name = eth1 | |
lxc.network.link = br100 | |
then lxc-start -n basebox machine should boot up within | |
a second or so :D. Root password is root. | |
================================================================================== | |
To create boxes I use a following Bash script | |
#!/bin/sh | |
if [ $# -ne 1 ]; then | |
echo "Enter box name " | |
exit 1 | |
fi | |
ORIG_BOX="base" | |
cp -a $ORIG_BOX ${1} | |
sed -i "s/$ORIG_BOX/${1}/g" ${1}/config ${1}/fstab ${1}/rootfs/etc/hostname | |
sh mounts.sh ${1} | |
=============================================== | |
mounts.sh mounts file systems from a local box onto the new box. That way I can avoid using NFS | |
mount -B /local/cache/apt /home/lxc/${1}/rootfs/var/cache/apt/archives |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment