box.matto.nl

home/

Building a diskless LXC Linux Container server

Last edited
Fun with a diskless Debian LXC Linux Container server

Debian LXC Linux Container server

LXC Linux Containers provide a great and very lightweight virtualisation solution. Containers virtualisation or operating system-level virtualisation is very efficient and very fast.

Debian GNU Linux is a great Linux distro. Debian can run on all kinds of hardware, both big and small.

Recently I turned the servers in my home network into disklessservers.

Diskless LXC Linux Container server

The LXC Linux Containers must have some kind of network connection. On a "normal" LXC Linux Container server this is done by setting up a network bridge on the host.

Bringing up a network bridge on a system is normally done with brctl and require the network interface to brought down.

On a diskless system with it root filesystem mounted over NFS it is not possible to bring down the network interface. So there is the challange in turning a LXC Linux Container server into a diskless system.

The solution is in modifying the initramfs.

brctl in initramfs for a network bridge in a diskless system

To make the diskless system the configuration of the brigde is moved from the "normal" system into the initramfs.

On a Debian system this is done by making /etc/network/interfaces empty and modifying the initramfs.

Busybox for initramfs

Download busybox and build a small busybox system including the brctl busybox-applet. Build a initramfs with this busybox.

I choose to hard code the network settings into the initramfs, but it should be possible to do this through DHCP or through the append command line in the PXE config.

initramfs /init

The following is in the /init file of my initramfs.

I am not sure if the modprobes should be there, but the system works, so I just let them sit there...

#!/bin/busybox sh

echo "Loading, please wait..."

[ -d /dev ] || mkdir -m 0755 /dev
[ -d /root ] || mkdir -m 0700 /root
[ -d /sys ] || mkdir /sys
[ -d /proc ] || mkdir /proc
[ -d /tmp ] || mkdir /tmp
mkdir -p /var/lock
mount -t sysfs -o nodev,noexec,nosuid none /sys
mount -t proc -o nodev,noexec,nosuid none /proc

modprobe r8169
modprobe sunrpc 
modprobe auth_rpcgss
modprobe nfs_acl 
modprobe fscache
modprobe lockd
modprobe nfs
modprobe stp
modprobe bridge

echo  "Bringing up bridge ..."
ifconfig eth0 0.0.0.0 up
brctl addbr br0
brctl addif br0 eth0
brctl bridge_fd 0
brctl bridge_stp off
brctl bridge_maxwait 5

ifconfig br0 192.168.1.2 netmask 255.255.255.0
route add default gw 192.168.1.254

echo "Sleep 40 ..."
sleep 40

echo "Mount nfs ..."
mount -tnfs -onolock 192.168.1.1:/nfs/rootfs/lxc /newroot
mount --move /proc /newroot/proc
mount --move /sysfs /newroot/sys

exec switch_root /newroot /sbin/init

See also other pages

On the ?diskless kvm guest page is more information on building diskless systems.

See my other diskless pages, some are quit old but other are more recent :)

Resources

Some pages that where helpfull: