boot-cd_easy LFS hint

Thomas Foecking thomas at
Mon Jan 14 14:06:53 PST 2002


"How to create an easy boot cd of a working lfs"

My first hint. If something is not ok (e.g. format)
you can tell me.

Greets from Germany
-------------- next part --------------
TITLE:          Easy Boot CD of your LFS
AUTHOR:	        Thomas Foecking <thomas at>

	How to create an easy boot cd of your working LFS system.

Version 0.1


    1. What do I need and what is the idea?
    2. Configure & compile Kernel
    3. Create archive of /dev /var /tmp /root /home
    4. Move /dev /var /tmp /root /home to /fake/ramdisk
    5. Create symlinks /dev -> /fake/ramdisk/dev ...
    6. Create boot script which mounts the RAM disk
    7. Create boot disk & test your system
    8. 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)
	- Create archive of /dev /var /tmp /root /home to /fake/all.tgz
	- Move /dev /var /tmp /root /home to /fake/ramdisk
	- Set symlinks
		/dev  -> /fake/ramdisk/dev
		/var  -> /fake/ramdisk/var
		/tmp  -> /fake/ramdisk/tmp
		/root -> /fake/ramdisk/root
		/home -> /fake/ramdisk/home
	- Mount /dev/ram0 to /fake/ramdisk
	- Extract /fake/all.tgz to /fake/ramdisk
	Now we have read-write access on /dev /var /tmp /root /home

	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:


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:


	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)

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. Create archive of /dev /var /tmp /root /home

	Now you can boot your other linux system to create an archive
	of /dev /var /tmp /root /home to /fake/all.tgz.
	You should set LFS to your lfs root directory:

	Create /fake direcotry:

mkdir $LFS/fake

	Create compressed archive from /dev /var /tmp /root /home
	to /fake/all.tgz with saving owner and permissions (-p):

cd $LFS || /
tar cfzp fake/all.tgz dev/ var/ tmp/ root/ home/

4. Move /dev /var /tmp /root /home to /fake/ramdisk

	Now we move /dev /var /tmp /root /home to /fake/ramdisk.
	This direcotiries will be burned read-only later on.
	This is important for booting kernel, when the RAM disk isn't
	present /dev /var /tmp /root /home will point to read-only
	/fake/ramdisk (which is no RAM disk, before mounting to RAM)

	Move /dev /var /tmp /root /home to /fake/ramdisk

mkdir $LFS/fake/ramdisk
mv $LFS/dev $LFS/var $LFS/tmp $LFS/root $LFS/home $LFS/fake/ramdisk

5. Create symlinks /dev -> /fake/ramdisk/dev ...

	We have saved our /dev /var /tmp /root /home in archive
	/fake/all.tgz and moved them to /fake/bootdisk
	Now we must set this links, so that everything seems to be
	as before.

cd $LFS || cd /
ln -s fake/ramdisk/dev dev
ln -s fake/ramdisk/var var
ln -s fake/ramdisk/tmp tmp
ln -s fake/ramdisk/root root
ln -s fake/ramdisk/home home

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

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

6. 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


source /etc/init.d/functions

case "\$1" in
                echo -n "Creating ext2fs on \$dev_ram ..."
                /sbin/mke2fs -m 0 -q \$dev_ram
                sleep 1
                echo -n "Mounting ramdisk on \$dir_ramdisk ..."
                mount \$dev_ram \$dir_ramdisk
                sleep 1
                echo -n "Copying files to ramdisk ..."
                tar xfzp \$dir_fake/\$file_all -C \$dir_ramdisk
                echo "Usage: $0 {start}"
                exit 1

	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

7. Create boot disk & test your system

	Now we'll create a boot disk.
	!!! But first we have to change /etc/fstab !!!
	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.

	 Copy ($LFS)/etc/lilo.conf to
	($LFS)/tmp/ and edit it. Or use my lilo.conf:

cat > $LFS/tmp/lilo.conf << EOF
boot    = /dev/fd0
vga     = 791
timeout = 80

#!!! change this to your lfs kernel and partition !!!

#this is later for our boot cd

	Run lilo (if you use devfs change it to -b /dev/floppy/0)

/sbin/lilo -b /dev/fd0 -C $LFS/tmp/lilo.conf

	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 lfs_hd_ro from
	/tmp/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

8. Burn cd

	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.

9. 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>

More information about the hints mailing list