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:
- 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.
- We'll just use the same solutions as with root over nfs (see above):
- 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.
- /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:
- For starters just take one of the machines which you want to use and put in a big disk and a cd-burner.
- 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.
- 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
- Boot the test setup.
- 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.
- 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.
- Test that the test setup automagicly boots into the apllication and everything works.
- Boot the main install and mount the 650 mb partition on /test of the main install.
- 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
- 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
- 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`
- Remove the creation of /etc/issue* from /test/etc/rc.local it will only fail.
- 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.
- Get boot.img from a redhat cd
- Mount boot.img somewhere through loopback by typing:
mount boot.img somewhere -o loop -t vfat
- Remove everything from boot.img except for:
- ldlinux.sys
- syslinux.cfg
- Cp the kernel-image from the test partition to boot.img.
- 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>
- Umount boot.img:
umount somewhere
- 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:
- Copy boot.img to /test
- Cd to the directory where you want to store the image make sure it's on a partition with enough free space.
- Now generate the image by typing:
mkisofs -R -b boot.img -c boot.catalog -o boot.iso /test
Verifying the iso image
- Mounting the image throug the loopbackdevice by typing:
mount boot.iso somewhere -o loop -t iso9660
- Now verify that the contents is ok.
- Umount boot.iso:
umount somewhere
- 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