A live CD is a bootable CD that contains the whole operating system and any applications you want to run from the CD. With the increasing popularity of DVD and Blu-ray drives, there is even a live DVD. A live CD is useful when you want to copy your existing Linux system to a CD and run it on multiple computers. In this post, I show how I normally create a live CD.
Rebuild a kernel with SquashFS and UnionFS patch
A new kernel should be built with SquashFS and UnionFS patches. The live CD will have a huge file that is actually a SquashFS image containing a copy of your existing Linux system. We will use UnionFS so that any changes to the read-only SquashFS will be saved to the volatile memory. Download the patches from the following locations.
After patching the kernel and rebuilding it, install the new kernel.
Make a SquashFS image of an existing Linux system
A SquashFS image needs to be created from an existing Linux system. Copy the contents of the Linux filesystem to an empty directory, assuming the filesystem is mounted at /mnt.
mkdir /tmp/livecd cd /mnt tar cf - . | (cd /tmp/livecd; tar xf -)
Empty the contents of fstab so that the live CD will not mount any hard disk partition, including the original root partition.
cp /dev/null /tmp/livecd/etc/fstab
Create a squashfs image.
mksquashfs /tmp/livecd /tmp/linuxfs.sqz -comp xz -b 262144 -Xdict-size 196608 -no-xattrs -e boot lost+found selinux srv
Create a Custom InitRamFS image
This is a tricky part of the job. Basically, the init script of the initramfs image will mount the CD-ROM, then mount the SquashFS image, and then mount a UnionFS. Refer to this post on building an initramfs image.
Create a Live CD structure.
Create an empty directory which will be the contents of live CD. The live CD will contain:
- SquashFS image (named linuxfs.sqz, for example)
- isolinux.bin and isolinux.cfg
- initramfs image
Finally, create an ISO image for the live CD.
genisoimage -V LIVECD -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table /tmp/isofs > ~/livecd.iso
Burn the ISO image.
cdrskin -v dev=/dev/sr0 speed=8 driveropts=burnfree ~/livecd.iso