Posts Tagged ‘ containers ’

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:



lenny $cache/partial-$arch


squeeze $cache/partial-$arch



(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 @@
@@ -110,7 +110,7 @@
     echo "Downloading debian minimal ..."
     debootstrap --verbose --variant=minbase --arch=$arch \
 	--include $packages \
-	lenny $cache/partial-$arch
+	squeeze $cache/partial-$arch
     if [ $? -ne 0 ]; then
 	echo "Failed to download the rootfs, aborting."
 	return 1
@@ -136,7 +136,7 @@
-    cache="/var/cache/lxc/debian"
+    cache="/var/cache/lxc/debian-squeeze"
     mkdir -p /var/lock/subsys/
@@ -220,7 +220,7 @@
-    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

Install fuse powered filesystems within an LXC container

I’m running a Debian Squeeze in an LXC container, and i needed to install SSHFS within the container, a FUSE based filesystem which lets you to mount remote filesystems through SSH. It shouldn’t be a problem, but fuse-utils depends on udev, and as you may know, LXC containers do not support udev, which will cause problems during the install.
While installing the udev package you’ll get some errors related with device creation like the following one:

Populating the new /dev filesystem temporarily mounted on /tmp/udev.EgkS50/...
mknod: `//tmp/udev.EgkS50/ppp': Operation not permitted

In order to solve this i had to allow those new devices to be created in your container’s configuration file by adding the following lines:

lxc.cgroup.devices.allow = c 108:0 rwm
lxc.cgroup.devices.allow = c 10:229 rwm
lxc.cgroup.devices.allow = b 7:0 rwm
lxc.cgroup.devices.allow = c 10:200 rwm

Now start your container and login.
Then, because the udev install will break your created devices, you should backup them:

user@host:~$ sudo cp -a /dev /dev.old

Go and install your fuse based filesystem, i’ll be installing sshfs:

user@host:~$ sudo apt-get install sshfs

Restore your old devices:

user@host:~$ sudo cp -a /dev.old/* /dev/

Create the fuse device:

user@host:~$ sudo mknod /dev/fuse c 10 229

Avoid udev to boot by disabling its init scripts:

user@host:~$ sudo update-rc.d -f udev disable

And that’s it, you should now be able to mount your fuse powered filesystem :-)