Next Previous Contents

5. Added bonus: booting from cdrom

Much of the above also goes for booting from cdrom. Since I wanted to document howto boot from cdrom anyway, I document it in here to avoid typing a lott of the same twice.

Why would one want to boot a machine from cd-rom? Booting from cdrom is interesting everywhere where one wants to run a very specific application, like a kiosk, a library database program or an intenet cafe, and one doesn't have a network or a server to use a root over nfs setup.

5.1 Basic Principle

The basic principle is wants again simple, boot with a cdrom as root. To make this possible we'll use the rockridge extension to put a unix like filesystem on a cd and the Eltorito extension to make cd's bootable.

Things can't be that simple

Ofcourse this setup also has a few problems. most are the same as above:

  1. We'll need write access to: /dev, /var & /tmp.
    • We'll just use the same solutions as with root over nfs (see above):
      • For /dev we'll use Devfs
      • For /var and /tmp we'll use a shared ramdisk of 1mb. It's shared to use the space as effeciently as possible. /tmp is replaced by a symlink to /var/tmp to make the sharing possible.
      • Populating the ramdisk with tarballs or template dirs, works equally well. But with template dirs it's much easier to make changes, thus we'll use template dirs.
  2. Some apps need write access to /home.
    • Put the homedir of the user's who will be running the application in /var, and populate it wiht the rest of /var every boot.
  3. /etc/mtab needs to be writable:
    • Create a link to /proc/mounts and create an empty file mounts in /proc, see above.

5.2 Creating a test setup.

Now that we know what we want todo and how, it's time to create a test setup:

  1. For starters just take one of the machines which you want to use and put in a big disk and a cd-burner.
  2. Install your linux of choice on this machine, and leave a 650mb partition free for the test setup. This install will be used to make the iso-image and to burn the cd's from, so install the nescesarry tools. It will also be used to restore any booboo's which leave the test setup unbootable.
  3. On the 650 mb partition install your linux of choice with the setup you want to have on the cd, this will be the test setup
  4. Boot the test setup.
  5. Compile a kernel as described in Section 3.1, follow all the steps, the changes need for devfs are still needed! At step 3 of Section 3.1 put in the following:
    • isofs compiled in
    • devfs compiled in
    • cdrom support compiled in
    • everything else you need either compiled in or as module.
  6. Configure the test setup:
    • Create the user which we'll be running the application.
    • Put it's homedir in /var.
    • Install the application if needed.
    • Configure the application if needed.
    • Configure the user so that the application is automagicly run after login.
    • Configure linux so that it automaigcly logs in the user.
    • Configure anything else which needs configuring.
  7. Test that the test setup automagicly boots into the apllication and everything works.
  8. Boot the main install and mount the 650 mb partition on /test of the main install.
  9. Put the following in a file called /test/etc/rc.d/rc.iso, this file we'll be sourced at the begining of rc.sysinit to create /var
    #/var
    echo Creating /var ...
    mke2fs -q -i 1024 /dev/ram1 1024
    mount /dev/ram1 /var -o defaults,rw
    cp -a /lib/var /
    
    #restore devfs settings, needs proc
    mount -t proc /proc /proc
    /etc/rc.d/rc.devfs restore /etc/sysconfig
    umount /proc
      
    

  10. Edit /test/etc/rc.sysinit comment the lines we're the root is remounted rw and add the following 2 lines directly afer setting the PATH:
    #to boot from cdrom
    . /etc/rc.d/rc.iso
      
    

  11. Copying the following to a script and executing it, this wil create a template for /var and make /tmp and /etc/mtab links.
    #!/bin/sh
    echo tmp
    rm -fR /test/tmp
    ln -s var/tmp /test/tmp
    
    ###
    echo mtab
    touch /test/proc/mounts
    rm /test/etc/mtab
    ln -s /proc/mounts /test/etc/mtab
    
    ###
    echo var
    mv /test/var/lib /test/lib/var-lib
    mv /test/var /test/lib
    mkdir /test/var
    ln -s /lib/var-lib /test/lib/var/lib
    rm -fR /test/lib/var/catman
    rm -fR /test/lib/var/log/httpd
    rm -f /test/lib/var/log/samba/*
    for i in `find /test/lib/var/log -type f`; do cat /dev/null > $i; done
    rm `find /test/lib/var/lock -type f`
    rm `find /test/lib/var/run -type f`
    
      
    

  12. Remove the creation of /etc/issue* from /test/etc/rc.local it will only fail.
  13. Now boot the test partition again, it will be read only just like a cdrom. If something doesn't work reboot to the working partition fix it, try again etc. Or you could remount / rw ,fix it then reboot straight into to test partition again. To remount / rw type:
    mount -o remount,rw /

5.3 Creating the cd

Creating a boot image

First of all boot into the workign partition. To create a bootable cd we'll need an image of a bootable floppy. Just dd-ing a zimage doesn't work since the loader at the beginning of the zimage doesn't seem to like the fake floppydrive a bootable cd creates. So we'll use syslinux instead.

  1. Get boot.img from a redhat cd
  2. Mount boot.img somewhere through loopback by typing:
    mount boot.img somewhere -o loop -t vfat
  3. Remove everything from boot.img except for:
    • ldlinux.sys
    • syslinux.cfg
  4. Cp the kernel-image from the test partition to boot.img.
  5. Edit syslinux.cfg so that it contains the following, ofcourse replace zImage by the appropiote image name:
    default linux 
    
    label linux
    kernel zImage
    append root=/dev/<insert your cdrom device here>
      
    

  6. Umount boot.img:
    umount somewhere
  7. If your /etc/mtab is a link to /proc/mounts umount won't automagicly free /dev/loop0 so free it by typing:
    losetup -d /dev/loop0

Creating the iso image

Now that we have the boot image and an install that can boot from a readonly mount it's time to create an iso image of the cd:

  1. Copy boot.img to /test
  2. Cd to the directory where you want to store the image make sure it's on a partition with enough free space.
  3. Now generate the image by typing:
    mkisofs -R -b boot.img -c boot.catalog -o boot.iso /test

Verifying the iso image

  1. Mounting the image throug the loopbackdevice by typing:
    mount boot.iso somewhere -o loop -t iso9660
  2. Now verify that the contents is ok.
  3. Umount boot.iso:
    umount somewhere
  4. If your /etc/mtab is a link to /proc/mounts umount won't automagicly free /dev/loop0 so free it by typing:
    losetup -d /dev/loop0

Writing the actual cd

Assuming that you've got cdrecord installed and configured for your cd-writer type:

cdrecord -v speed=<desired writing speed> dev=<path to your writers generic scsi device> boot.iso

5.4 Boot the cd and test it

Well the title of this paragraph says it all ;)


Next Previous Contents
Copyright © 2010-2024 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout