Roll-up Your Own


Table of Contents

How to create a live boot CD containing your favorite Linux Distro 
Motivation - Why? 
Before we start - What you'll need 
Steps involved - Overview 
The Linux boot process in a nutshell 
Roll your Desktop into a USB stick/CD 
Comments 

How to create a live boot CD containing your favorite Linux Distro 

http://www.babytux.org/articles/howto/how2livecd.php

Buddhika Siddhisena
Updated : September 16, 2003
Created : August 7, 2003

Motivation - Why? 

Wouldn't it be cool to have a bootable version of Linux running totally off a CD, no hard disk required!. You could probably pack your collection of mp3s along with a small linux desktop containing xmms. Perhaps load a couple of games like Tuxracer, Tuxpuck or Frozen Bubble to play at a friends house who doesn't have linux. May be your friends hard disk running that NO GOOD OS, crashed with a blue screen and wont boot and needs to be rescued. Better yet you want to introduce your friends to the wonderful world of Linux.

But most of the above mentioned can be achieved using some great projects such as Knoppix (www.knoppix.org) and Demo Linux (www.demolinux.org). So why go through all the trouble to build your own live CD from scratch? For one thing its great learning experience that can help you to get an insight into what makes linux tick, under the hood! Then there is the advantage of being familiar with your favorite distro and the tools it provides and a chance to let your friends try it out too.

Before we start - What you'll need 

  1. Installation CDs of your favorite distro.
  2. Free hard disk space - 1 partition will be used to install a full linux distro 1 partition will be used to install the distro to be put on the CD (about 700MB) 1 partition for swap
  3. Download the latest version of Busybox from http://www.busybox.net. It enables us to run a few essential linux commands easily requiring less hard disk space.
  4. A CD-RW to test burning various images and a CD burner (duuuh!)
  5. Optionally a virtual machine like VMware (commercial www.vmware.com) or Bochs (opensource bochs.sourceforge.net) will help in testing the iso image
  6. Optionally download my sample scripts and initrd file to save some time.
  7. Working knowledge on using linux at a command line level.
  8. Lots of patience :)

DISCLAIMER: The steps outlined in this document come with no guarantee (or warranty) that it will work, and what ever you do to your system is at your own risk! I hold no responsibility. Please back up your data always (or better yet use a different hard disk).If this makes you uncomfortable stop reading any further!

phew! now thats out of the way lets get to it!

Steps involved - Overview 

I've made my linux LiveCD using Mandrake Linux 9.0 (and later 9.1 with some changes), so I will explain it for that. I doubt it will be any different for Redhat. For other distros such as Debian or Suse you will have to improvise as necessary (commands for package management, file paths etc.)

  1. Install a full version of Mandrake Linux with kernel sources,development tools (such as gcc, make, etc.), cd burning tools (cdrecord, mkisofs) (Lets call $MAIN)
  2. Install a 700MB version of Mandrake Linux to a fresh partition containing only the required packages for the LiveCD (Lets call $LIVECD)
  3. Boot into $MAIN and compile a new kernel with support for ISO9660, initrd and ramdisk built in.
  4. Create an entry in the boot loader (lilo) to use the new kernel we compiled to boot $LIVECD
  5. Compile busy box so that it can later be copied to our $INITRD
  6. Create an initial RAM disk (initrd), format it using ext2 (lets call $INITRD) and mount it
  7. Make necessary changes to $LIVECD so that it boot in read-only mode as required for a Live CD and test setup
  8. Modify $INITRD so that it can boot off a $LIVECD and test it
  9. Make a bootable Linux CD ISO image of $LIVECD using the isolinux/syslinux method and burn it.
  10. Put in further configuration/optimization scripts to streamline and improve the system

    [ ... rest ommited ...]

The Linux boot process in a nutshell 

An understanding of the linux boot process is important before we continue as it will help us to understand and debug if something doesn't work.

First lets see how the usual linux boot process works.

  • When you turn on the machine as part of the boot process the BIOS looks for a bootable media and loads the bootloader from a special area in the disk called the MBR (Master Boot Record). The bootloader in the case of linux will usually be LILO or GRUB.
  • LILO (or GRUB) will attempt to load the kernel and an initial RAM disk (initrd) if that was defined in the config file (/etc/lilo.conf).
  • Control is passed to the kernel, which will decompress the initrd and mount it as root device. You have to enable INITRD and Ram disk support in the kernel to have this happen.
  • The kernel executes /linuxrc if it exists in the root device which will perform various pre-boot tasks such as the loading of additional drivers.
  • Once linuxrc exits control is passed back to the kernel which will then mount the real root device as the root file system (like /dev/hda1). The real root device of the kernel can either be hard coded to the kernel using the rdev command or passed an argument from lilo (root=/dev/hda1)
  • /sbin/init from the real root system is executed which uses /etc/inittab configuration to boot rest of the system. The important thing to note here is that /etc/inittab defines the default runlevel (usually 3 or 5) and as part of the boot process all scripts in /etc/rcX.d/ are executed.

Next lets see how our LiveCD boot process works.

  • Similar to the usual boot process, the BIOS finds a bootable CDROM and loads the bootloader (ISOLINUX). Before the ISOLINUX bootloader was available, you needed to create a special bootable floppy image called an El Torito image (more on this later)
  • ISOLINUX will load the initrd and the kernel image and transfer control to the kernel
  • The kernel decompresses initrd and mounts it as root and executes our custom /linuxrc script.
  • Our /linuxrc script will attempt to guess the CDROM device containing our LIVECD and will mount it (this is where busybox comes in handy!). /linuxrc will finally change the real root device of the kernel to that of the initrd itself and exit.
  • Since the real root device is initrd it self the kernel will load /sbin/init from initrd which will be symlinked to the LIVECD.

    [ ... rest ommited ...]

documented on: 2007-08-08