TITLE: Easy Boot CD of your LFS LFS VERSION: 3.1 AUTHOR: Thomas Foecking SYNOPSIS: How to create an easy Boot CD of your working LFS system. HINT: Version 0.1f 26/02/2002 Contents -------- 1. What do you need and what is the idea? 2. Configure & compile Kernel 3. Move /dev /var /tmp /root /home to /fake/needwrite 4. Create symlinks /... -> /fake/needwrite/... 5. Create boot script which mounts the RAM disk 6. Create boot disk & test your system 7. Burn the Boot CD 8. Reboot and enjoy 1. What do you need and what is the idea? ------------------------------------ What do you need? - LFS system (which you want to burn on CD) - another linux/unix system (to create some stuff and burn the CD) - floppy drive (for boot disk and image) - CD-R(W) drive (to burn your LFS system and boot image on CD) - 1 floppy disk - 1 CD-R (+ 1 CD-RW is very recommend for saving money) First of all you need a running LFS system, which you want to burn on CD. You may want to have a LFS CD for creating new LFS systems on other computers. Whatever your ideas are, you'll first have to create this special system on your LFS partition. (e.g. I have created a LFS system with xfree86 and windowmaker; now I can boot from CD and create new LFS systems without missing xfree86 & windowmaker) What is the idea? - Create kernel with RAM disk support - Move /dev /var /tmp /root /home to /fake/needwrite - Set symlinks /dev -> /fake/needwrite/dev /var -> /fake/needwrite/var /... -> /fake/needwrite/... - Mount /dev/ram0 to /fake/ramdisk - Copy /fake/needwrite/* to /fake/ramdisk/ - Remount /dev/ram0 to /fake/needwrite We'll have read-write access on /dev /var /tmp /root /home because they point to /fake/needwrite which is then a RAM disk You are able to do the most things from the other linux/unix system by setting LFS to your LFS mountpoint. LFS=/path/to/lfs e.g.: LFS=/mnt/lfs Don't forget to set LFS again when you do a reboot! 2. Configure & compile Kernel -------------------------- Boot your LFS system or chroot to it. Configure your kernel: cd /usr/src/linux make mrproper && make menuconfig You need RAM disk support! "Block devices" -> "RAM disk support" "16384" KB should be your standard (you can change this value on lilo prompt by setting "ramdisk_size=n" kB if you need more or less than 16 MB) You need ISO 9660 CDROM file system support! "File systems" -> "ISO 9660 CDROM file system support" You should also think about building some other drivers into kernel or as modules. e.g. You plan to have network support If you want to be able to boot the CD on a lot of PCs with different CPUs (e.g. 468, Pentium, PII, PIII, Athlon) you have to complile the kernel for 486 (then it runs on >= 486). "Processor type and features" -> "Processor Family" -> "486" Save config and compile your kernel: make dep && make bzImage && make modules && make modules_install Then you should copy the new built kernel to /boot: cp arch/i386/boot/bzImage /boot/lfskernel Run Lilo: /sbin/lilo Try to boot the new kernel in order to test RAM disk support: (if you're using devfs you must change: dev_ram=/dev/rd/0) dev_ram=/dev/ram0 mke2fs -m 0 $dev_ram If this fails like > The device apparently does not exist; > did you specify it correctly? you have no RAM disk support in your kernel. You should read this chapter again ;-) Otherwise you have done your work very well! You can check the size of your RAM disk by mounting it to /mnt and doning an "df -h" mount $dev_ram /mnt df -h Now you can boot your other linux/unix system ... 3. Move /dev /var /tmp /root /home to /fake/needwrite -------------------------------------------------- We move all stuff needing write access to /fake/needwrite. First we have to create this directory and the mountpoint for the RAM disk: mkdir -p $LFS/fake/{needwrite,ramdisk} Then we can move it there: cd $LFS/ mv dev/ var/ tmp/ root/ home/ fake/needwrite/ 4. Create symlinks /... -> /fake/needwrite/... ------------------------------------------- We have moved /dev /var /tmp /root /home to /fake/needwrite. Now we must set symlinks so that everything seems to be as before. cd $LFS/ ln -s fake/needwrite/dev dev ln -s fake/needwrite/var var ln -s fake/needwrite/tmp tmp ln -s fake/needwrite/root root ln -s fake/needwrite/home home "ls -l" says: dev -> fake/needwrite/dev home -> fake/needwrite/home root -> fake/needwrite/root tmp -> fake/needwrite/tmp var -> fake/needwrite/var 5. Create boot script which mounts the RAM disk -------------------------------------------- Ok, we have /dev /var /tmp /root /home pointed to /fake/needwrite which is first read-only. To be able to login (and to run services on runlevel x which need write access to /dev /var /tmp /root or /home) we must call a script from our /etc/init.d/ directory which creates a RAM disk to /fake/needwrite with write access. I suggest to boot in runlevel 3 for multi user with network. If you don't want to enable network you can remove the link /etc/rc3.d/S200ethnet and start network manualy after login with /etc/init.d/ethnet start. This is what I prefer. The following script creates a RAM disk to /fake/ramdisk and will copy everything of /fake/needwrite to /fake/ramdisk. Then it remounts the RAM disk to /fake/needwrite. cat > $LFS/etc/init.d/create_ramdisk << EOF #!/bin/sh dev_ram=/dev/ram0 dir_ramdisk=/fake/ramdisk dir_needwrite=/fake/needwrite source /etc/init.d/functions case "\$1" in start) echo -n "Creating ext2fs on \$dev_ram ... " /sbin/mke2fs -m 0 -i 1024 -q \$dev_ram evaluate_retval sleep 1 echo -n "Mounting RAM disk on \$dir_ramdisk ... " mount \$dev_ram \$dir_ramdisk evaluate_retval sleep 1 echo -n "Copying files to RAM disk ... " cp -dpR \$dir_needwrite/* \$dir_ramdisk evaluate_retval sleep 1 echo -n "Remount RAM disk to \$dir_needwrite ... " umount \$dir_ramdisk sleep 1 mount \$dev_ram \$dir_needwrite sleep 1 ;; *) echo "Usage: $0 {start}" exit 1 ;; esac EOF Make it executable: chmod u+x $LFS/etc/init.d/create_ramdisk create_ramdisk should be the first script excecuted by init, so we set this link: /etc/rcS.d/S000create_ramdisk -> ../init.d/create_ramdisk cd $LFS/etc/rcS.d ln -s ../init.d/create_ramdisk S000create_ramdisk 6. Create boot disk & test your system ----------------------------------- Now we'll create a boot disk. !!! But first we have to change /etc/fstab of LFS !!! Delete all entries you don't need. (e.g. all /dev/hd*) We don't want to mount anything automaticly on boot. (do you?) Don't worry about mounting root filesystem "/". This will be mounted read-only by kernel. The best is to remove also the following links in /etc/rcS.d: S100localnet, S200checkfs, S300mountfs Create ext2 system on floppy and mount it to $LFS/mnt /sbin/mke2fs -m 0 /dev/fd0 /bin/mount /dev/fd0 $LFS/mnt Copy kernel, bootmenu and devices to floppy (this process may take some time ...) mkdir $LFS/mnt/{boot,dev} cp $LFS/boot/{lfskernel,boot.b} $LFS/mnt/boot cp -dpR /dev/fd[01]* $LFS/mnt/dev cp -dpR /dev/hd[a-h]* $LFS/mnt/dev Create lilo.conf at $LFS/mnt cat > $LFS/mnt/lilo.conf << EOF boot =/dev/fd0 install =boot/boot.b map =boot/map timeout =100 prompt read-only backup =/dev/null compact ### remove this when boot floppy works image = boot/lfskernel label = cur_lfs root =/dev/fd0 append ="root=/dev/hdXn" # your LFS partion e.g. hda1 read-only ### image = boot/lfskernel label = PRI_MASTER root =/dev/fd0 append ="root=/dev/hda" image = boot/lfskernel label = PRI_SLAVE root =/dev/fd0 append ="root=/dev/hdb" image = boot/lfskernel label = SEC_MASTER root =/dev/fd0 append ="root=/dev/hdc" image = boot/lfskernel label = SEC_SLAVE root =/dev/fd0 append ="root=/dev/hdd" EOF You can remove "compact" in lilo.conf to make lilo boot faster, but with "compact" is more failsave when using a floppy. The Boot CD should work on other systems too! This is why we set root to /dev/fd0 to let lilo boot the kernel from floppy and set append="root=/dev/hdx" to let the kernel mount /dev/hdx as root fs "/" (/dev/hdx is the cdrom drive) When you create a bootable CD, the floppy image is copied to the CD and the BIOS will detect the boot image of the CD as floppy /dev/fd0. Run lilo from $LFS/mnt cd $LFS/mnt $LFS/sbin/lilo -C lilo.conf -v Umount floppy cd $LFS/ /bin/umount $LFS/mnt Thats it! You can try to boot your system from floppy. The kernel will mount your LFS partition read-only. This is the same as if you would boot from CD. Now you will see if your LFS system boots. It should mount the RAM disk and go into runlevel 3. Try to login ! Did the boot disk work? You may want to delete cur_lfs from $LFS/mnt/lilo.conf and run lilo again, so that you have a clean boot image. Now create an image of this disk to /boot/ of the LFS system dd if=/dev/fd0 of=$LFS/boot/image bs=1024 7. Burn the Boot CD ---------------- If you have a CD-RW you should take this for testing. When your system boots quite good from CD you can burn it on a CR-R. (I give you this advice, because I got the clue after burning about 10 CD-Rs that didn't work ;-) Before you start burning, check the size of your LFS tree: du -h $LFS/ Delete all stuff you don't need on a Boot CD. (/usr/src/linux/) Note! dev=0,0,0 is the device number of your CD-Writer Check your SCSI devices with "cdrecord -scanbus" speed=4 should be changed to (max) speed of your CD-Writer. cd $LFS/ mkisofs -bboot/image -cboot/catalog -r -l -D -J -L -VLFS $LFS | \ cdrecord -v -eject dev=0,0,0 speed=4 -data - If this doesn't work you may want to use xcdroast instead of command line to burn your CD. (Set Boot image to "boot/image" and Catalog to "boot/catalog") 8. Reboot and enjoy ---------------- Reboot and let your Bios boot from CD. Enjoy the kernel messages and login prompt ;-) ------------------------------------------------------------------ If you have any ideas, suggestions or found a bug you can send a mail to me: Thomas Foecking ------------------------------------------------------------------