Building Your Own Live CD

Create your own special-purpose live CD distribution with these little-known secrets of bootable CDs.
Persistent Storage: Hotplug

The CD-ROM is read-only, and a ramdisk goes away when the power is turned off. People want to save their files, though, or even have access to the files they've created already on existing hard disks or on removable devices, including USB keychains and Zip drives. Again, most of the hard work has been done for us; this time hotplug and autofs are our saviours.

Hotplug listens for new devices being added or removed. When it sees a new USB storage device, it loads any necessary modules and creates an emulated SCSI host. We still need to know what devices are available and mount them, and that's where autofs comes in.

autofs mounts and unmounts filesystems on demand. Using a program map, we can have a Perl script run whenever the user asks for /media/list; it creates a directory with links named after the attached devices. These links point to more autofs mount points to access the filesystems. In the tarball, look at target/etc/auto.master and target/usr/local/sbin/autofs-device-list.

The Kernel

We use basically the same kernel configuration as Knoppix (look at /usr/src/linux/.config in a running Knoppix system, or kernel-config in our tarball), but we remove support for a few obviously unused things, such as ZISOFS. The standard Debian make-kpkg tool patches, builds and installs the kernel. This is a Debian dependency on the host system (you need the cloop-src package), and as it's probably the only nontrivial such dependency, it might be worth moving into the chroot in a later version.

The Filesystem

Most of a UNIX filesystem is happy mounted read-only, but we do need to write files in some places. For example, the X server configuration file needs to be written at boot time according to the hardware in use, the debconf database must be updated and there are various log and lock files too.

We use the tmpfs filesystem to create a RAM-based filesystem. The system is arranged to use this ramdisk for root and expect the cloop image on /ro. Then for read-only directories, we create symlinks, for example, from /usr to /ro/usr.

We keep a list of read-only directories, and we check it twice. First, we create a tarball of the system that excludes all these directories, replacing them with appropriate symlinks. This tarball then is copied into the root filesystem of the running system. Second, when we're writing out the ISO9660 image to be cloop-compressed, this is the list of directories to include.


Before the system proper starts up, there are two important things we must do. First, we need to mount the cloop image, load whatever modules the CD-ROM needs, then find and mount the CD. Next, we install the cloop device and mount the inner filesystem on it. Second, we create a ramdisk for the root filesystem and copy the root_fs.tgz image from the CD into it.

We use the initrd (initial ramdisk) support to create a mini root filesystem that the kernel mounts and runs before the real init starts. This is a gzipped filesystem. When a kernel with initrd support is booted with the command line initrd=filename, it loads the contents of that filename and creates a ramdisk out of it. It then starts running the /linuxrc file in that ramdisk.

When linuxrc has finished, it uses the pivot_root call to change onto the real root directory, which was /ramdisk, and executes the real init.

The initrd and the kernel together need to be small enough to fit in 1.44MB of RAM with all the other files on the boot image. This is not a lot of space, as GNU libc alone is about 1,200K, we're going to have to be pretty creative.

dietlibc, Busybox

Even if you've never wanted a Linux PDA or an in-car MP3 jukebox, you now have a reason to be grateful to embedded Linux hackers. We're going to use Busybox and dietlibc to get our quart into the proverbial pint pot. Busybox is a small shell that can be configured at build time to include many common utilities as built-ins, and dietlibc is an alternative C library optimized for small size. By happy coincidence there turns out to be a Busybox applet for everything we need on the initrd, and by statically linking with dietlibc we can get all this into about 100K. For comparison, the same Busybox options statically linked against glibc get a 500K executable.

Applets for Busybox are enabled using #defines in its Config.h file (in the tarball). Some of the disabled options may seem rather arbitrary, but when you already have a choice of echo * and tar cvf /dev/null to list the current directory, ls really is a luxury.

We create the initrd using genext2fs, avoiding the need for a loopback mount. This generates an ext2 filesystem from a directory tree, which we gzip and copy into the boot floppy image (Figure 1).

Figure 1. Wheels within wheels: the finished CD nests filesystem images inside filesystem images inside filesystem images.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

> use debian or ubuntu This

Anonymous's picture

> use debian or ubuntu

This was true a while back, but recent releases of Ubuntu do not have this setting. Your only hope is to downgrade your kernel to something nice and _old_... Which no-one is really going to do. R.I.P Sandbox

I'm having some trouble with

coddy's picture

I'm having some trouble with it but I'm just starting with linux I've been a windows guru but
Linux is a whole new rought.

Getting KNOPPIX_V3.3-2003-09-24-EN.iso of Knoppix

George Stoianov's picture

Can anyone point me where I can get this version of Knoppix the current one does not have boot-en.img and

Thanks in advance.

You can use this following

Mario's picture

You can use this following command:

mkisofs -pad -l -r -J -v -V "My KNOPPIX" -no-emul-boot -boot-load-size 4 -boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinux/ -hide-rr-moved -o knoppix-backuptools.iso my-knoppix-cd-tree/

ERROR when chroot....bug? i am using FC 2 with 2.6.6 kernel

atthaya's picture

The error message is:

Inconsistency detected by rtld.c: 1192: dl_main: Assertion `(void *) ph->p_vaddr == _rtld_local._dl_sysinfo_dso' failed!

Is it a bug in kernel 2.6.6?
If so, what kernel version would solve it?
Is there anyway i can fix the problem without compiling new kernel?


run this before your command's picture

echo 1 > /proc/sys/vm/vdso_enabled

Inconsistency detected

ali's picture

when you want in Fedora or other redhat linux distributions
to execute chroot command you give "Inconsistency detected"

but you try in debian or other distributions those are in debian base
you don't encounter that problem

use debian or ubuntu