Create a Debian Squeeze LXC template under Debian Squeeze
By default, the Debian container template script installs Debian Lenny, which is no more the current stable release, so it makes sense that your new containers run an up to date release, i tried squeeze so far, didn’t try testing or still in development yet, so i’ll tell you how to create a script to create Debian Squeeze containers.
By default, the lxc package ships with few different template scripts, and they’re located in the directory /usr/lib/lxc/templates/, the debian one is called lxc-debian.
Copy it to the same directory with another name:
user@host:/usr/lib/lxc/templates$ sudo cp lxc-debian lxc-debian-squeeze
Open it with with your favorite text editor and change the following lines:
dhcp-client,\
to
isc-dhcp-client,\
lenny $cache/partial-$arch http://ftp.debian.org/debian
to
squeeze $cache/partial-$arch http://ftp.debian.org/debian
cache="/var/cache/lxc/debian"
to
cache="/var/cache/lxc/debian-squeeze"
(this last appears two times!)
… Or just apply the following patch:
--- lxc-debian 2011-02-08 01:03:22.931566630 +0000 +++ lxc-debian-squeeze 2011-02-08 01:19:46.287573988 +0000 @@ -90,7 +90,7 @@ locales,\ libui-dialog-perl,\ dialog,\ -dhcp-client,\ +isc-dhcp-client,\ netbase,\ net-tools,\ iproute,\ @@ -110,7 +110,7 @@ echo "Downloading debian minimal ..." debootstrap --verbose --variant=minbase --arch=$arch \ --include $packages \ - lenny $cache/partial-$arch http://ftp.debian.org/debian + squeeze $cache/partial-$arch http://ftp.debian.org/debian if [ $? -ne 0 ]; then echo "Failed to download the rootfs, aborting." return 1 @@ -136,7 +136,7 @@ install_debian() { - cache="/var/cache/lxc/debian" + cache="/var/cache/lxc/debian-squeeze" rootfs=$1 mkdir -p /var/lock/subsys/ ( @@ -220,7 +220,7 @@ clean() { - cache="/var/cache/lxc/debian" + cache="/var/cache/lxc/debian-squeeze" if [ ! -e $cache ]; then exit 0
And now you’re ready to create new Debian Squeeze containers :)
user@host:~$ sudo /usr/lib/lxc/templates/lxc-debian-squeeze -p /var/lib/lxc/my-awesome-debian-squeeze-container
There’s also something else you’ll probably need to do in order to login to a tty with lxc-console, the template script does not create any of the /dev/tty’s, so you’ll need to create them by hand, or change the new template script in order to create it:
… cd to your container’s rootfs and execute the following commands:
user@host:~$ sudo mknod -m 666 /dev/tty1 c 4 1 user@host:~$ sudo mknod -m 666 /dev/tty2 c 4 2 user@host:~$ sudo mknod -m 666 /dev/tty3 c 4 3 user@host:~$ sudo mknod -m 666 /dev/tty4 c 4 4
Now you may want to edit your container’s configuration, and then start using it.
For your convenience, you can setup a first container, do your initial configuration on it, and then leave it alone, every new container you want to create could be just a copy of it, this will boost the container’s setup, just don’t forget to edit the new containers configuration accordingly.
user@host:/var/lib/lxc$ sudo cp -a squeeze-base-container new-web-container