LFS LiveCD Documentation

Introduction

The main purpose of this page is to document the process of making the official LFS livecd. Specifically, how it differs from previous cds produced from existing LFS hints. The notes here will deal mostly with the x86 cd, as the ppc cd is a bit different in some areas and is still under development. This page should not be considered a full hint, although it may progress to that point in the future.

The process of making an LFS livecd is actually fairly straightforward. I've broken it down into six basic steps:

  1. Build a base LFS system according to the usual procedure.
  2. Add wanted additional packages with the help of BLFS.
  3. Modify your bootscripts and tweak system settings to meet your needs.
  4. Create an initial script/program that will set up your special environment.
  5. Configure your bootloader.
  6. Package it all up into an iso.

Of course, that is simplifying it a bit, but you get the idea. The official cd uses two new concepts that are not, to my knowledge, included in any of the hints. They are: Squashfs and Initramfs. These two technologies are central to what makes the official LFS cd work.

Squashfs

Project homepage: http://squashfs.sourceforge.net

Squashfs is a compressed read-only filesystem for Linux. It is mounted as a loop device and files are uncompressed and read from the squashfs archive as they are needed. I've seen squashfs produce nearly 50% compression. Needless to say, squashfs is what allows me to pack so many packages onto the cd. The documentation for squashfs is pretty good and it is easy to get yourself up and running with it. Using it basically amounts to patching your kernel to support the squashfs filesystem and creating squashfs archives. From the top of the lfs partition, what will become the iso, I ran these commands:

mksquashfs usr usr_sqfs

mksquashfs opt opt_sqfs

That creates two squashfs archives containing all of the usr and opt directories from your new LFS system. The /usr directory will by far be your largest after building LFS according to the book. You can now delete (or better yet, move to a safe location) the /usr and /opt directories from the lfs partiton. You will also need to add a bootscript that mounts those directories early on in the boot process. You would mount them like this:

mount usr_sqfs /usr -o loop

mount opt_sqfs /opt -o loop

Initramfs

As you know, a cdrom is read-only. That presents a bit of a challenge for producing a working Linux system based entirely on a cd. You need some writable directories to be able to do anything. If you are already familiar with creating live cds you know that one of the best ways to solve this problem is to use ramdisks and mount them to your tree. Often, this was done using a script called linuxrc that the kernel would invoke after it scans your hardware. To get everything exactly as we wanted, we would have to chroot and pivot_root and all sorts of other little tricks.

With the 2.6 kernels initramfs becomes available. The documentation for initramfs is a little scarce, but it basically boils down to a replacement for initrd. It's a filesystem that is compiled into the kernel itself and should contain at the root level a file called 'init'. The kernel will mount your initramfs image to / in RAM and when it is finished probing your hardware it will look for init and run it. The init should contain instructions for setting up your custom environment.

The LFS LiveCD uses a C file for init. It sets up your directory structure under /, finds and mounts the LFS LiveCD, makes essential symlinks to read-only directories on the cd and starts udev to create device nodes for the system. Finally, it passes control over to sysvinit to finish the boot process.

You can view the init file here: init.c

If you wish to build the entire initramfs for inclusion in your custom kernel, you can do so like this (Note: these commands assume you have subversion and cpio installed. If you don't you can build them according to the instructions in BLFS):

svn co svn://svn.linuxfromscratch.org/livecd/trunk/initramfs/

cd initramfs

make

Now you will want to copy the new initramfs over to your kernel source to be included in the kernel image.

cp initramfs_data.cpio.gz [path_to_kernel_source]/usr/

touch [path_to_kernel_source]/usr/initramfs_data.cpio.gz

Now when you make your kernel, the new initramfs will be included in the image. If you use the official init.c as I've shown above, be sure to create a file named 'LFS' in the root of your iso tree like so:

echo "LFS-6.0-LIVECD" > LFS

This is necessary because the init looks for that file containing that string to ensure that it has found the correct cd drive (the one that contains the livecd) before it mounts the cdrom.