hint boot-cd_easy UPDATE

Thomas Foecking thomas at foecking.de
Tue Jan 15 14:43:11 PST 2002


Hi!

I updated some important stuff:
- create bootdisk which runs on every system (not hardware dependent)
(so the boot cd works on other systems too)
- instead of .tgz archive we move /dev /var ... to /fake/needwrite
so that we can easily change the content of these directories.

Greets
Thomas
-------------- next part --------------
TITLE:          Easy Boot CD of your LFS
LFS VERSION:    3.1
AUTHOR:	        Thomas Foecking <thomas at foecking.de>

SYNOPSIS:
	How to create an easy Boot CD of your working LFS system.

HINT:
Version 0.1a
16/01/2002

Contents
--------

    1. What do I 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
    9. Reboot and enjoy


1. What do I need and what is the idea?
   ------------------------------------

	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? (simple overview)
	- Create kernel with RAM disk support (/dev/ram0 = 16MB)
	- 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

	Now we have read-write access on /dev /var /tmp /root /home
	because they point to /fake/needwrite which is now a RAM disk

	You'll need another linux/unix system to create your lfs Boot CD.
	You are also able to do the most things from the other linux/unix
	system by setting LFS to your lfs partition. LFS=/path/to/lfs
	e.g.:

LFS=/mnt/lfs


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 enough for our files
	You need ISO 9660 CDROM file system support!
		"File systems" -> "ISO 9660 CDROM file system support"

	You should also think about to create some other drivers as
	modules. e.g. if you plan to have network support on the lfs
	Boot CD. If you want to be able to boot the CD on a lot of pcs
	(e.g. 468, PII, PIII, Athlon) you have to complile the kernel
	for 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!

3. Move /dev /var /tmp /root /home to /fake/needwrite
   --------------------------------------------------

	We move all stuf which need write access later on to
	/fake/needwrite.

	First we have to create this directory
	and the later mountpoint for 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 links so that everything seems to be
	as before.

cd $LFS || cd /
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

	After this, we have got:
	 dev -> fake/needwrite/dev
	 home -> fake/needwrite/hom
	 root -> fake/needwrite/roo
	 tmp -> fake/needwrite/tmp
	 var -> fake/needwrite/var

	When the kernel is booting and init is running it tries to
	open/read some devices of /dev. Its good to have /dev linked to
	/fake/needwrite/dev which already contains the /dev files of
	the lfs system (read-only, but this is enough for this time)


5. Create boot script which mounts the RAM disk
   --------------------------------------------

	Ok, we have already /dev /var /tmp /root /home to boot the
	kernel, but they point to /fake/ramdisk which is read-only.
	To be able to login (and maybe run services on start
	which need write access to /dev /var /tmp /root or /home)
	we must call a script from our runlevel directory.

	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.

	We must mount our RAM disk on /fake/ramdisk. This is done
	by a boot script: /etc/init.d/create_ramdisk

	The script creates a RAM disk to /fake/ramdisk and extracts
	/fake/all.tgz to /fake/ramdisk.

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 ramdisk on \$dir_ramdisk ..."
                mount \$dev_ram \$dir_ramdisk
                evaluate_retval
                sleep 1
                echo -n "Copying files to ramdisk ..."
                cp -dpR \$dir_needwrite/* \$dir_ramdisk
                evaluate_retval
                sleep 1
                echo -n "Remount ramdisk 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 a link in your /etc/rcS.d .
	/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 mount points to your local drives, because
	we don't want to mount anything automaticly on boot.
	The best is to remove also the following links in /etc/rcS.d:
	S100localnet, S200checkfs, S300mountfs
	The Boot CD will be mounted read-only to / by kernel.

	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 append to root=/dev/hdx
	to let the kernel mount /dev/hdx as /
	(/dev/hdx is our cdrom drive)

	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 (wait a minute)

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 (floppy)

cat > $LFS/mnt/lilo.conf << EOF

        boot      =/dev/fd0
        install   =boot/boot.b
        map       =boot/map
        timeout   =100
        prompt
        read-write
        backup    =/dev/null
        compact

### remove this when floppy works
        image     = boot/lfskernel
        label     = cur_lfs
        root      =/dev/hdX1 #(e.g. hda1 -> your lfs parition)
        append    ="root=/dev/hdc"
###

        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

	Run lilo from $LFS/mnt

cd $LFS/mnt
/sbin/lilo -C lilo.conf

	Umount floppy

cd $LFS || cd /
/bin/umount $LFS/mnt

	Thats is! You can try to boot you 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 go into runlevel 3 and
	mount the RAM disk to /fake/ramdisk. 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 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.

	Note! /dev/cdrecorder should point to your CD-Writer.
	Speed=4 should be changed to (max) speed of your CD-Writer.
	Set LFS=/path/to/lfs

cd /some/where/not/lfs
mkisofs -rlDJLV "LFS" $LFS -b boot/image -c boot/catalog \
| cdrecord -v -eject dev=/dev/cdrecorder speed=4 -data -

	You may want to use xcdroast instead of command line to
	burn your CD.


8. Reboot and enjoy
   ----------------

	Reboot and tell your Bios to boot from CD.
	Enjoy the kernel messages ;-)


If you have any ideas, suggestions or found a bug you can send a
mail to me: Thomas Foecking <thomas at foecking.de>


More information about the hints mailing list