[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]

"Linux Gazette...making Linux just a little more fun!"

First Attempt at Creating a Bootable Live Filesystem on a CDROM

By Mark Nielsen

If this document changes, it will be available at


  1. References
  2. Introduction to cdrom burning and bootable cdroms.
  3. Creating an EXT2 cdrom and a bootable floppy disk
  4. Creating a bootable installation CDROM using ISO9660 and Rock-Ridge extensions (for my MILAS project). This is the preferred way of making CDROMs.
  5. Configuring the boot-up process so that the computer is useable.
  6. Conclusions and future articles
  7. A crude Perl script to make a bootable iso9660 formatted cdrom of RedHat 5.1 from my computer.
  8. My rc.sysinit file for RedHat 6
  9. My example lilo.conf file.
  10. My example fstab.
  11. My old script. This is where MILAS came from. This Perl scripts will eventually be integrated with the bootable cdrom.


  1. CD-Writing HOWTO by Winfried Trümper
  2. Lilo mini-Howto
  3. Xcdroast  -- read about cdrecord with "man cdrecord".

Introduction to cdrom burning.

First off, you should read the previous article Creating Installation Cds from various Linux Distributions. This article will assume you know how to make cdroms using cdrecord. Now the, the next step. Why make a Live Linux Filesystem for a cdrom?
  1. You want to make an installation cdrom (like MILAS).
  2. You want to boot off the cdrom and use it for most of the core files for your operating system and use your hard drive for other stuff.
  3. You want to make it real easy to do upgrades. Use a rewritable cdrom and just swap out the old cdrom with a new one.
The long term direction is to use a cdrom to create computers without hard drives. You use the cdrom for most of the core filesystem, a ramdisk for /tmp, and NFS for everything else. I really really dislike professional network computers that are diskless and hope that creating your own diskless workstations will be the way of the future.

STRING NOTE: The perl scripts and methods I use to make bootable cdroms is NOT NOT NOT very clean yet. I am still working to perfect the process. I want to have it all run in Python or Perl (preferrably Python). Once making bootable cdroms is well documented, I am going to merge this with my MILAS project.

Creating an EXT2 cdrom and a bootable floppy disk

For this exersize, we will do something a little strange. We will make an ext2 formatted cdrom and a floppy disk that is bootable. For people want to use the easier iso9660 format, skip this section.

What advantages do you have by doing this in my strange way? Well, first, realize something before I answer that question. Realize that a floppy, cdrom, or a hard drive partition can be treated the same in most respects. Okay, now I will answer the question:

  1. You can use a spare partition on your hard drive to test the image you want to put on your cdrom. If you boot off of a floppy disk, you can point it to the hard drive partition, and if it works out great, then on the next floppy disk you make bootable, have it point to your cdrom. Remember to mount the hard-drive partition read-only to simulate a read-only cdrom. Hard drive partitions are a good way to test images before you put them on your cdrom (especially when it is a write-once cdrom).
OPTIONAL: First, create an ext2 filesystem (using the hard drive for testing purposes):
  1. Have a spare partition on your hard drive to use for your image for the cdrom.
  2. Format the partition as an ext2 format. Example: "mkfs -t ext2 /dev/hda3". This formats the third partition on your primary hard drive. Make sure you change the number "3" to the correct number used for your spare partition.
  3. Copy over all critical directories and configure the files in ROOT/etc to correctly reflect your new installation.
  4. Use a ramdisk for "/tmp" and point "/var" to "/tmp/var".
  5. Make a bootable floppy disk, and either configure it to use the cdrom drive as "root" or "/" or if you get lilo installed on the floppy drive, you can type in a command at boottime to use a different partition for "/". You can do this with the command

  6. lilo root=/dev/hdc
    if your cdrom drive is "/dev/hdc". Notice I did not specify a partition number. There is none.
    There are also other ways to make bootable floppies. For my redhat installation
       ### Make a copy of the kernel
    cp /boot/vmlinuz-2.2.12-32 /tmp/Vmlinuz
       ### Make the copy boot from the cdrom on /dev/hdc
    rdev /tmp/Vmlinuz /dev/hdc
    ramsize /tmp/Vmlinuz 20000
       ### copy the kernel directly to the floppy disk, you might have to format it first, mkfs -t ext2 /dev/fd0
    dd if=/tmp/Vmlinuz of=/dev/fd0
For examples of how to copy over directories and files, look at the Perl script at the end of the document.
For examples on how to use a ramdisk, read about this RamDisk article I wrote a while ago, and also "man lilo.conf".

Second, either using the files from a partition you were using for testing purposes, or if you want to start from scratch,

Make an image that is 600 megs but using "dd" and a loopback device. Then copy this image to your cdrom. How do you make an image?
Assume that "/mnt/Partition" is the directory you have all the files that you want to make an image out of.

  ## Create a blank file or image
dd if=/dev/zero of=/tmp/Image bs=1024k count=650
    ### Format this blank image
/sbin/mke2fs  -b 2048 /tmp/Image
   ### Answer "y" to mkfs if it says that it doesn't recognize the device
mkdir -p /mnt/CDROM_IMAGE
   ### Mount the blank formatted image to a directory
mount  -t ext2 -o loop=/dev/loop1 /tmp/Image mnt/CDROM_IMAGE
   ### Copy over the stuff from your hard drive partition to your image for the cdrom.
tar -C /mnt/Partition -pc . | tar -C /mnt/CDROM_IMAGE -xvp
  ### Or just use rsync to copy it over
#    rsync -a /mnt/Partition/* /mnt/CDROM_IMAGE
  ### Umount the image
umount /mnt/CDROM_IMAGE

OR, if you don't mind using an ISO9660 formatted cdrom, which will work the same with rock-ridge extensions, enter this command.
mkisofs -aJlL  -r -o /tmp/Image /mnt/Partition
NOTE: Making an iso9660 cdrom in one step is a lot easier and is described in the section below.

Now burn the image located at "/tmp/Image" to your cdrom.

Actually, I was thinking, you can probably just make a hard drive partition 600 megs and copy it over directlly without having to make an image. If your hard drive partition is "/dev/hda4", then do this.

  ### Note, I never tested this yet.
  ### Unmount our partition that we copied files to
umount /dev/hda4
  ### Make an image of the partition
dd if=/dev/hda4 of=/tmp/Image.raw

Now just take Image.raw and burn it to your cdrom.

For better examples on how to do this, look at my Perl script below. Anybody want to convert this into a Python Script? Perhaps a Python/TK script?

Creating an installation CDROM using ISO9660 and Rock-Ridge extensions (for my MILAS project)

The big deal about make ISO9660 formatted cdroms with Rock-Ridge extensions is that fact that you can make cdroms bootable. This is very useful for creating your own diskless workstations, creating boot-able installation cdroms, creating a cdrom to fix hard drives, and probably other stuff.

With this section, you don't need a to use a loopback device, you don't need to use any partitions, you just need a directory somewhere on your computer and the program "mkisofs". This probably is the easiest way to create an image that you want to use for a cdrom.

     The key to making a bootable cdrom is the "mkisofs" program. Here is a typical command that I use,
mkisofs -aJlL  -r -o /tmp/Boot_Image /CDROM
    "/CDROM" is the directory that you want to burn onto a cdrom. To add the boot file,
mkisofs -aJlL  -r -b /tmp/Boot.image -o /tmp/Boot_Image /CDROM
    In the next section we discuss how to make a bootable floppy disk that you can put on your cdrom.

The key item to remember is that you need a directory for this program. This nice thing is, it doesn't grab the empty space on a partition when it creates its image. You can use a spare

Configuring the boot-up process so that the computer is useable.

The toughest part about creating a live filesystem is copying over the critical files and configuring them. You should have the same directory structure as your Linux filesystem, except the stuff under /usr should not be critical, but perhaps helpful. Remember to mount a ramdisk to /tmp, remember that you should point /var to /tmp/var, and remember to configure the files in /etc correctly. This could be a whole article itself. I try to do it in the Perl script below. If you combine a live filesytem on a cdrom with a hard drive or NFS, you will have more options as to what you can do.

Here is an example of how to copy over files and configure the bootup process.
Assume the directory you are making an image of is, "/tmp/Boot_Image".

cd /tmp/Boot_Image
mkdir root
mkdir mnt
mkdir proc
mkdir tmp
mkdir home
mkdir misc
mkdir opt
### Yes, tmp/var doesn't exist, but it will after bootime
ln -s tmp/var var
mkdir dev
rsync -a /dev/* dev
mkdir lib
rsync -a /lib/* lib
mkdir bin
rsync -a /bin/* bin
mkdir sbin
rsync -a /sbin/* sbin
mkdir usr
mkdir etc
rsync -a /etc/* etc
mkdir boot
rsync -a /boot/* boot

Now, configure etc/inittab to boot at runlevel "1".
in the file etc/inittab

Now, change your etc/fstab to this,

    #### change /dev/hdc to wherever your cdrom is located
/dev/hdc      /        ext2    defaults        1 1
/dev/fd0     /mnt/floppy             ext2    noauto,owner    0 0
none       /proc                   proc    defaults        0 0
none        /dev/pts                devpts  gid=5,mode=620  0 0
        ### Note, this is using a swap partition from a hard drive.
        #### Delete this is or change this
/dev/hda6               swap                    swap    defaults

Now, add to the end of etc/rc.d/rc.local the following commands

mkfs -t ext2 /dev/ram0
mount /dev/ram0 /tmp
chmod 777 /tmp
chmod +t /tmp

Now you need to make a bootdisk with a larger ramdisk on it.
  ### This makes a bootdisk, put a floppy disk in
mkbootdisk `uname -r`
  ### This makes the directory to mount the floppy disk
mkdir  /mnt/floppy_test
  ### Mount the floppy disk
mount /dev/fd0 /mnt/floppy_test
  ### Edit the lilo.conf file and put "ramdisk=35000" in the lilo.conf file, mine looks like

           ### Change /dev/hdc to /dev/hdb or /dev/hdd or wherever your cdrom is
        append="load_ramdisk=2 prompt_ramdisk=1"

   ### Now execute the lilo command on the floppy drive
lilo -r /mnt/floppy_test
  ### Now umount the floppy disk
umount /dev/fd0

Now you have a bootable floppy disk that uses your cdrom as root.
If you are going to burn the floppy disk image onto your cdrom using mkisofs, then change lilo.conf to this,

           ### Change /dev/hdc to /dev/hdb or /dev/hdd or wherever your cdrom is

   ### After you umount the floppy disk, make an image of the floppy disk to burn on a cdrom
dd if=/dev/fd0 of=/tmp/Boot.image

Conclusions and future articles

I wanted to make it easier to create bootable cdroms with a live filesystem. From here, I will make an article on how to use a bootable cdrom to
  1. Create installation cdroms to burn your image of an operating system to your hard drive.
  2. How to use a bootable cdrom and a hard drive and/or NFS.
  3. Finish up my MILAS project. My MILAS project started when I needed a way to configure custom-made computers that I used to sell (and probably will again someday to help force competitors to do cool things).
  4. Make a more accurate Perl script to take the version of Linux you have on your computer and put it on a cdrom. I will probably end up using the iso9660 format for the cdrom.
I apologize for the roughness of this article. It was a pain in the butt to figure out how to make bootable cdroms. I imagine other people have documented it much better than I have. In my next article, I will clean it up a lot.

Mark Nielsen works for The Computer Underground as a clerk and as a book binder at ZING. In his spare time, he does volunteer stuff, like writing articles for The Linux Gazette and developing ZING's website.

Copyright © 2000, Mark Nielsen
Published in Issue 54 of Linux Gazette, June 2000

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]