LFS Linux on a bootable CD



Acknowledgments

Thanks to:

Gerard Beekmans for the LFS system

Martin L. Purschke for the original idea about this CD

Ideas, reports, and fixes from users, and the LFS lists that have been used in this package

Copyright Chris Lingard - GNU GENERAL PUBLIC LICENSE

Introduction.



This package will help you make a bootable CD that runs a complete Linux system. You will need a machine with at least 128Mb of memory for it to run jobs, because the root file system is 25Mb of RAM, with 5Mb of swap. It will compile small packages, such as bash, just using memory. To build glibc you need to mount a spare disk partition to give you some space. As to its use; this is limited just by your imagination

You will need two systems. One is the building system, this will make the image and write the CD. The other is the LFS system that will provide the data, (but will become temporarily unbootable during the build).

The system that is being written to CD must be fairly standard, to work. /usr/sbin/chroot must exist.

The building system must have loop devices built into the kernel. You will need the following two mount points:

/mnt/loop1 and /mnt/loop2.

Make these directories now, if something goes wrong during the build you will need to remove any data left on these mount points, otherwise this will spoil subsequent builds.

The initrdtree directory is used to make a file system. This file system is compressed and written to the bootimagetree.

The directory bootimagetree is used to make the bootable image and contains a kernel version 2.4.14, this cured memory problems. Together with the compressed file system it must not exceed 2.88Mb; as a double size floppy is emulated. The build parameters for this kernel are included in the file kernel_parameters. Once you make the bootable CD you may want to make your own kernel to replace the supplied one. Note that the initrd size has been increased to 32768.

The script updatebinaries will replace the programs and libraries in initboottree from the LFS system. It may be best is you do not run this immediately as the programs and libraries supplied are known to work under the contraints of the system requirements.

Download



The package

Preparation of the LFS system



The package cd_builder.tar.bz2 contains all the required scripts and programs. You will need to be root to unpack and use it.


First you must prepare the system pointed to by $LFS so that it will boot from CD.
Set TOPDIR to point to the directory containing the cd_builder package. cd where_ever_it_is/cd_builder export TOPDIR=`pwd`

/etc/mtab must be a pointer to /proc/mounts (already is for LFS 3) cd $LFS/etc ls -l mtab and if it is a file mv mtab mtab.bak ln -s /proc/mounts mtab You need to replace the $LFS/etc/fstab with the one supplied cd $LFS/etc mv fstab fstab.bak cp $TOPDIR/fstab . You need the script checkcd to replace checkfs and mountfs cp $TOPDIR/checkcd $LFS/etc/rc.d/init.d cd $LFS/etc/rc.d/rcsysinit.d ln -s ../init.d/checkcd S25checkcd mv S10swap ZZZS10swap mv S20mountproc ZZZS20mountproc mv S30checkfs ZZZS30checkfs mv S40mountfs ZZZS40mountfs mv S50cleanfs ZZZS50cleanfs Check that your $LFS/etc/inittab will start up at level 3 Inspect your level 3 start up scripts and disable any that you think are inappropriate cd $LFS/etc/rc.d/rc3.d ls I just have S100sysklog; the ethernet would work; except that no ethernet modules are built into the supplied kernel. Finally you need to tar $LFS/root $LFS/dev and $LFS/etc cd $LFS tar cf root.tar root tar cf dev.tar dev tar cf etc.tar etc After this the LFS partition can be restored by reversing the changes; the tar files will be used during the boot.

Building the image



Return to the build directory and set TOPDIR

cd where_ever_it_is/cd_builder
export TOPDIR=`pwd`


The directory cdtree must have the LFS root directory mounted.  On my system it is /dev/hdb6 so:

mount  /dev/hdb6  cdtree

If you have a separate partition for usr then mount this too

mount  /dev/hdxx  cdtree/usr

If you have a partition containing source you may also mount this.  Mine is /dev/hdb5 so:

mount  /dev/hdb5  cdtree/usr/src

You can now build the image:

bash  build.sh >& Build &

Check the output for any warning or any "file system full". 
A warning from lilo about lilo.conf not having the correct permissions is normal; the latest lilo will also warn about lba32 and compact.

If you have both the LFS and the LFS/usr/src mounted the image will be in bootcd.iso and will be about 500Mb.


Write this to a CD and try the system.

Restoration of the LFS system

There are three major changes to be made before the LFS system will reboot:


$LFS/etc/mtab
$LFS/etc/fstab
$LFS/etc/rcS.d
First the mtab
cd $LFS/etc
rm mtab
cp mtab.bak mtab



Then the fstab
cd $LFS/etc
cp fstab  fstab.cd
cp fstab.bak  fstab

And finaly the links
cd $LFS/etc/rcS.d
mv S25checkcd ZZZS25checkcd
mv ZZZS10swap    S10swap
mv ZZZS20mountproc S20mountproc  
mv ZZZS30checkfs   S30checkfs
mv ZZZS40mountfs   S40mountfs  
mv ZZZS50cleanfs   S50cleanfs



Your LFS system should now boot; enabling you to change and tune it. Then add more software before building a better CD.

Some uses for the boot CD

Broken files


Any partition can be mounted; files edited or replaced by those on the CD.

Mending a broken lilo


Suppose that the machine just does LILILILI on boot up.
Boot from the CD and mount your root partition to /disk; if your not sure which partition; then test the partitions listed in /proc/partition until you get the right one.
Once you have the broken root partition mounted do:
chroot /disk
cd /etc
vi lilo.conf and fix what is wrong
then
lilo -C lilo.conf

Exit (from the chroot), unmount the disk and reboot.

Installation from the CD

First you need to use fdisk to prepare your hard disk partitions, and then mount them to your root partition. The root partition has a mount point called disk, so you could mount your future root and usr partitions onto disk. You then then just copy the CD to the new partitions

cp -a /cdrom/* /disk

Then restore the newly created disk partions the same as restoring the LFS partion, (they are identical). If you have many machines to set up, it would be useful if you pre-installed fstab and lilo.conf files onto the LFS root; so that they are available on the CD.

Conclusion



I would appreciate any feedback. This is a prototype, I have upgraded the kernel to 2.4.18, (on 29 April). Thanks for the reports. See you on the LFS lists or write direct Chris Lingard.