Build your own ultimate boot disc


Author: Kurt Edelbrock

You turn on your trusty old Linux box, and things are going well as you pass through the boot loader, until the disk check reveals that your hard drive partition table is corrupt, and you are unable to access your machine. You need a good rescue disk — and the best way to get one is to create your own.

You can customize an Ubuntu 8.04 Hardy Heron live CD to make a good bootable utilities disk by adding and removing packages from the standard installation. Specifically, you can remove most of the Ubuntu applications and install antivirus, a partition recover tool, a few disk utilities, and a rootkit checker, among other things. I’m going to create the live CD within an Ubuntu installation, but the directions should work for most Debian-based operating systems, and can be easily ported elsewhere. This guide largely follows the community documentation article on the Ubuntu customization process, which is a good place to look for more advanced information and troubleshooting support, while the wiki is the best place to look for customized directions.

To create and use the Ubuntu-based boot CD, you’ll need a computer with at least 3GB of disk space and 512MB RAM. 1GB of swap is recommended, though I did it with 512 MB.

Create the live CD environment

The first step is to download the Ubuntu 8.04 live CD ISO file for your system type. You can get it from the Web site, or you can use wget on the command line:

wget -v

To work with the image, you’ll need to install a few packages to support the squashfs filesystem format, and mkisofs, the utility to create ISO images. On Ubuntu, you can install them with the command sudo apt-get install squashfs-tools mkisofs.

Now, load the squashfs module, then copy, mount, and extract the contents of the ISO file in order to customize the contents:

sudo modprobe squashfs mkdir rescue mv ubuntu-8.04-desktop-i386.iso rescue cd rescue mkdir mnt sudo mount -o loop ubuntu-8.04-desktop-i386.iso mnt mkdir extract-cd rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd mkdir squashfs sudo mount -t squashfs -o loop mnt/casper/filesystem.squashfs squashfs mkdir edit sudo cp -a squashfs/* edit/

You’ll want to customize the CD in a chroot environment. Chroot changes the root directory of the environment, allowing you to access the files and applications inside the CD directly, which you must do in order to use tools like apt-get. In order to use a network connection inside chroot, which you’ll probably want to do to add new packages, you’ll need to copy in the hosts and resolv.conf files to configure your network settings. You can achieve this with the following:

sudo cp /etc/resolv.conf edit/etc/
sudo cp /etc/hosts edit/etc/

Once you’ve completed these steps, you can start to work inside the live CD. Mount the live CD to the edit/dev mountpoint, then change your root directory into the newly mounted volume. You’ll need to mount /proc and /sys volumes to work with the kernel, and export your settings to avoid locale and GPG problems later on:

sudo mount --bind /dev/ edit/dev sudo chroot edit mount -t proc none /proc mount -t sysfs none /sys export HOME=/root export LC_ALL=C

Free space by removing unneeded packages

You can configure the packages that are included with the live CD using apt-get or Aptitude. You’ll want to free up some space to add the rescue applications; even though the data is compressed, all of it needs to fit on a 700MB CD or on a higher-capacity DVD. You can remove packages and applications that aren’t useful for the recovery. I chose to remove the suite, the GNOME games set, Ekiga, Ubiquity, Evolution, and the GIMP, saving me around 200MB. If you are comfortable without a command-line environment, you might want to get rid of GNOME and Xorg; if you do that, you need not install GParted and the other graphical tools in the next section. In any case, the goal is to get rid of large applications. To sort all of the installed packages by size, run the following command in the chrooted environment:

dpkg-query -W --showformat='${Installed-Size} ${Package}n' | sort -nr | less

You can use apt-get to remove a package. Use it with the --purge argument to get rid of configuration files. The sudo command won’t work in the chroot, and therefore should be omitted:

apt-get remove --purge package-name

Add rescue applications

Once you have removed all of the unneeded applications from the live CD you can start to add rescue and recovery applications. Generally, rescue CDs include a variety of disk utilities and security tools, as well as networking tools to find support and access outside machines. You may not want all of the applications I mention, and you can add some that I don’t. This is your personal boot CD, and should be configured as you see fit. For ideas about what to include on your CD, you might want to check out some of the prebuilt rescue distributions mentioned in the sidebar.

You can install packages from the repositories using apt-get, but you must add the multiverse repository to your /etc/apt/sources.list file:

deb hardy main multiverse deb-src hardy main multiverse

A disk partition tool is the staple of a mature boot disk. Fortunately, the Ubuntu live CD comes with GParted, the GNOME Partition Editor, so adding a package isn’t required. If you chose to forgo a graphical environment, you should make sure that parted is installed instead to handle partition tables from the command line. If you accidentally delete a partition, installing a program like testdisk can help you recover it, as well as provide a few other basic disk tools. If you are using the ext2 filesystem type and you accidentally delete a file, you’ll find the e2undel package helpful in recovering it. If you need to copy an entire partition from a dying disk, or just want to make a backup, partimage is the way to go. You can also use it to restore a partition with a previously made backup.

If you plan to use this disc with Windows machines, you will want to install antivirus and rootkit tools. Clamscan provides quick and easy virus scan with a command-line-based update tool. Chkrootkit is a scanner to find and remove rootkits that could be hiding in your computer. You can use sleuthkit to conduct analysis of your filesystem and browse through hidden files.

After you finish adding packages, clean up your temporary data and unmount the environment:

apt-get clean rm -rf /tmp/* rm /etc/resolv.conf umount /proc umount /sys exit sudo umount edit/dev

Now, regenerate the manifest (which is basically a list of installed packages) and copy in into the correct directory:

chmod +w extract-cd/casper/filesystem.manifest sudo chroot edit dpkg-query -W --showformat='${Package} ${Version}n' > extract-cd/casper/filesystem.manifest sudo cp extract-cd/casper/filesystem.manifest extract-cd/casper/filesystem.manifest-desktop sudo sed -i '/ubiquity/d' extract-cd/casper/filesystem.manifest-desktop

Compress the filesystem to squeeze it onto a disc:

sudo rm extract-cd/casper/filesystem.squashfs sudo mksquashfs edit extract-cd/casper/filesystem.squashfs -nolzma

And finally, create the ISO file:

cd extract-cd sudo mkisofs -r -V "$IMAGE_NAME" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -o ../ubuntu-8.04-desktop-i386.iso

Once the image file is created, you need to burn it to a disc. You can do that pretty easily with K3b or Brasero. If you want, you can do it from the command line:

cdrecord dev=/dev/cdrom ubuntu-8.04-desktop-i386.iso

Once the CD is finished burning, you should be able to put it into your optical drive and boot into the environment you just created.

This should give you more than enough information to start building your ultimate custom rescue CD. Add the packages and tools you need, and hopefully you’ll never be at a loss the next time your computer has a problem during startup.


  • System Administration