Custom Debian live environment

I’ve been working with live CDs and netbooting Debian. There are a lot of common elements, so this covers how to do a basic framework for either system. In this demo, I’ll create a system called “default” which is the bare minimum bootable system.

The host system

The host system is the life support for the chroot. I think it’s a good idea to use a VM.


Debootstrap will install a Debian base system in a directory. I like to create my images in /usr/src.
You only need to install it once.

apt-get install debootstrap

But you use it for every chroot you want to make:

debootstrap --arch=amd64 --variant=minbase wheezy /usr/src/default

In this case I’m using the amd64 architecture but you can also use i386. Man debootstrap for (a little) more information.

Enter the environment

I use a script called “readyroot” to get the chroot environment ready and to enter it. The script is at the bottom of this post. I just save it as /usr/src/readyroot, so I execute

/usr/src/readyroot /usr/src/default open

This will take care of mounting dev, sys and proc, and enter the chroot.

Updating the environment

There are a few things to do now

Set a root password

passwd root

Set a hostname

echo "my-chroot" > /etc/hostname

Update apt

apt-get update

Generate a machine ID

apt-get install dialog dbus --yes && 
dbus-uuidgen > /var/lib/dbus/machine-id

Install a kernel

apt-get install linux-image-amd64

This installs the new kernel meta package, and makes you a little more version independent. It’s going to be something else on x86 systems (486-pae maybe?), so do  apt-cache search linux-image to see what’s available.

Leave the environment

Believe it or not, you now have the absolute bare minimum Debian system. From here you



/usr/src/readyroot /usr/src/default close

And that’s it. From here you can use it for:

  • Creating a custom LiveCD
  • Creating a diskless VM


The readyroot script helps ease into and out of chroot environments. I’ve been playing with diskless systems and LiveCDs lately and cobbled this together to simplify the process. It’s written for Debian 7 systems. The first time you get into your chroot, you should

apt-get install dialog dbus --yes && 
dbus-uuidgen > /var/lib/dbus/machine-id

After that it will just work automatically.

case $2 in
                echo opening chroot $1
                if [ ! -d $1 ]; then
                        echo specified root $1 does not exist
                        exit 1
                echo mounting evnironment
                mount none -t proc $1/proc
                mount none -t sysfs $1/sys
                mount -o bind /dev $1/dev
                mount none -t devpts $1/dev/pts
                chroot $1 /bin/bash -c "export HOME=/root; export LC_ALL=C; dbus-uuidgen > /var/lib/dbus/machine-id; exec bash"
                echo closing chroot $1
                umount -lf $1/dev/pts
                umount -lf $1/sys
                umount -lf $1/dev
                umount -lf $1/proc
                rm -rf $1/tmp/*
                rm -f $1/var/lib/dbus/machine-id
                if [ ! -d $1 ]; then
                        echo specified root $1 does not exist
                        exit 1
                echo usage: readyroot [path] [open/close]

About robertlabrie
DevOps Engineer at The Network Inc in metro Atlanta. Too many interests to list here, check out my posts, or look me up on LinkedIn

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: