Bootable CD of LFS using grub

Durgesh Sharma durgeshs at compucomtech.co.in
Mon Feb 7 21:23:24 PST 2005


LFS Linux booting from a CD



Hello,
    I am using Fedora-Core-1 (Kernel-2.4.22) and using grub as Bootloader.
    I have succesfully created my LFS using LFS-5.1.1. and made LFS on 
CD using the lfs-hints for Bootable CD and also tried algorithm (How to 
make LFS linux bootable CD) written by Gerard Beekmens attached herewith.
but all of my five CD writting attempts were failed.
I have followed every single instruction mentioned in the above stated 
algos successfully without any error .According to the algo we have 
successfully burnt the ISO image of the LFS , but while we used that CD 
for booting , Nothing happened.
CD contents were only the ISO image of the lfs system.
Should there be some other files or directories also needed  along with 
the above mentioned ISO image on the CD to make this CD bootable?
I am a totally newbie as far as linux is concerned. I need to convert my 
LFS system into a LIVE LFS linux CD or LFS Bootable CD.
Please suggest me the Live LFS CD or Bootable LFS CD (Using grub) 
procedure in details.
Thanx in advance.
Both algos used by me are attached.
Regards
Sunil



--------------------------------------------------------------------------------


How to make a LFS Linux 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 


LFS bootable CD
Introduction
This is my method of making a bootable CD. The Linux system used is LFS, details of which can be found at www.linuxfromscratch.org. I started this project when I realised that I had no proper recovery system, and it just grew from there. 

I tried various other systems; the best being cd_template by Martin L. Pursche. Extending this package, to boot a full Linux system, became my goal. 

Here are the standard warnings. You must be confident enough to build systems, with various hacks and modifications. You must be careful enough to avoid wrecking your systems; many of the scripts will mess up your base system if run wrongly. 


How it boots
First a few words on how to make a bootable CD, (using lilo). 

When you burn a CD using mkisofs, you have the -b option to specify the boot image. This boot image must be something that the hardware understands, therefore you need to emulate a floppy. Since we are only pretending that is a floppy, we may choose any type, so we choose the largest -- a 2.88Mb floppy. 

We make a file system using a loop device that is exactly 2.88Mb, copy files to it, then run lilo on it. 

Here is a lilo.conf: 


cat > $TOPDIR/lilo.conf << EOF
disk=/dev/loop1
bios=0x00 # bios ID from drive A, we need that here because lilo
# need to know which boot device to use
sectors=36 # 2.88MB disk geometry
heads=2
cylinders=80
timeout=30

 boot=/dev/loop1
 message=/mnt/loop1/boot/boot.msg
 install=/mnt/loop1/boot/boot.b
 map=/mnt/loop1/boot/map
 prompt
 compact

 image=/mnt/loop1/boot/vmlinuz
   label=linux
   initrd=/mnt/loop1/initrd.img
   append = "root=/dev/ram init=/linuxrc rw"
   ramdisk=$ISIZE

EOF
# run lilo
/sbin/lilo -C $TOPDIR/lilo.conf


At the start of the above, you can see us telling lies to the hardware, that this is a 2.88Mb floppy. 

We have put a kernel and boot message into this file system. 

The initrd.img is a compressed file system. 

linuxrc is an executable script in the root of this compressed file system. 

This must all fit inside 2.88Mb. 

The file system may be 6.5Mb, before compression, and still be small enough. 

linuxrc may be a symbolic link to bash 

The file system may contain anything you like, but this is all you will have after booting the CD 

You can make this system inside a directory; it will look something like: 
/dev  #  The devices that you need
/bin  ->  sbin
/lib  # Needed if you are using dynamic programs
/linuxrc  #  The script
/sbin     #  You selection of programs



Once you have made this; you calculate its size, make a file system on a loop device, copy the files, then compress it into initrd.img. 

During the linuxrc script you would mount the cdrom, giving you access to whatever you put on the CD. See the mount_cdrom script below that auto-detects the cdrom, and modify it to do what you want. 

The base system
The base system's kernel will need loop devices enabled. I use mkisofs and cdrecord from package cdrtools-1.10a17. You will also need directories to use the loop back devices; /mnt/loop1 and /mnt/loop2 are what I use. 


The image system
You must decide if you just want a CD that will work on your machine, (and any identical); or you want a CD that will work on any PC. If you just want a recovery/repair disk then download the package and go to the final chapter to make your CD. 

If you want a generic CD, then you must build a generic system to act as the image. 

To do this you must do the following: 


Change the .bash_profile
Both the building systems .bash-profile and the .bash_profile that is created when building the LFS system must have the following lines added 

CFLAGS=' -m486 -march=i486 -Os '
export CFLAGS

The 486 stuff forces the compiler to build code that will work on 486 and Pentium PCs. The -Os flag optimizes for minimum size, and suppresses the -g flag causing stripped binaries and libraries to be made. 
Apply the uname hack
On your building system apply this hack to uname 
mv uname uname.real
cat > uname << EOF
uname.real $@  |  sed  's/[456]86/486'
EOF
chmod 755 uname


On the static build of sh-utils append these instructions to the book: 

# Modification for false uname to answer i486
mv  $LFS/bin/uname  $LFS/bin/uname.real
cat  > $LFS/bin/uname <<EOF
#!/bin/bash
/bin/uname.real "\$@"  |  sed 's/[456]86/486/'
EOF
chmod 755  $LFS/bin/uname
cp  $LFS/bin/uname  $LFS/bin/uname.false

The \ in the "\$@" hides the $ from the shell. 
On the dynamic build of uname append these instructions to the book: 
# Mofification for false uname to answer i486

mv  $LFS/bin/uname  $LFS/bin/uname.real
mv  $LFS/bin/uname.false $LFS/bin/uname

You can now build a generic, (i486), system. 

The kernel must be built i486 and the following must be set: 
CONFIG_BLK_DEV_RAM_SIZE=32768
The system used for the image can be any working combination you choose. Things that use many shared libraries, such as KDE, should be avoided, because they will be too slow for any effective work on a CD. I use a standard LFS plus a few extras such as gpm, X and lynx. Remember to build everything i486 

So, following on from the above here are some notes on how to make a bootable CD, and what you should put into the boot image. 



Making the package
You will need two LFS systems to generate a bootable CD. One is the base system that will be used for building. The other is the system that provides the image. 
If you do not want to build you own boot package, then you can download mine from www.stockwith.uklinux.net. If you do not have a small optimised system, then your programs and libraries may be too large to make a boot image. Here is how it works. 

Let us first consider what we want. We need a writable root partition, so we will make one out of RAM. We will want /proc and /cdrom mounted on the root. I also wanted /root, /dev and /etc writeable, so these are unpacked from tar files during the boot process. (How the image system as prepared is described later). 

The start up linuxrc will achieve this, then pass control to init. Here is my linuxrc script: 

#!/bin/sh

echo "Welcome to the LFS Linux CD system"

# /proc is needed to find the CD
mount -t proc none /proc

# Make a 25 Mb file system for root
dd if=/dev/zero  of=/dev/ram  bs=1k  count=25000
mkdir  -p  ram
mke2fs -q /dev/ram
# Mount our new root file system
mount  /dev/ram  /ram
cd /ram
mkdir cdrom
# Find the CDROM
# This will auto-detect and mount the CD
/mount_cdrom
# Mount proc and set links to the CD
mkdir proc
mount  -t proc  none /ram/proc
ln -s  cdrom/bin  bin
ln -s  cdrom/sbin  sbin
ln -s  cdrom/lib  lib
ln -s  cdrom/boot  boot
ln -s  /cdrom/usr  usr
# Set up some swap space
dd  if=/dev/zero  of=swapspace bs=1k  count=5000
mkswap  swapspace
echo "Preparing file systems for pivot"
# Finish off setting up
mkdir home
mkdir disk
mkdir tmp
mkdir mnt
mkdir mnt/lfs
mkdir var
cd var
mkdir lib lock log mail run spool tmp opt cache lib/misc local
cd /ram
echo "Unpacking tar files for /root /dev and /etc"
# These are the only writeable directories
tar xf /ram/cdrom/root.tar
tar xf /ram/cdrom/dev.tar
tar xf /ram/cdrom/etc.tar
mkdir initrd
# Swap root file systems /dev/ram <-->  /dev/root
pivot_root  .  initrd
# Change to new root and swap to new root's devices
exec /usr/sbin/chroot . /sbin/init <dev/console >dev/console 2>&1
# It should never reach here
exit


The only non standard thing used here is mount_cdrom, this is it. 

#!/bin/sh
for ide in ide0 ide1; do
for disk in hda hdb hdc hdd hde hdf hdg hdh; do
   if [ -r /proc/ide/$ide/$disk/media ] ; then
     if grep -s -q "cdrom" /proc/ide/$ide/$disk/media; then
         if  mount -t iso9660 -o ro -n /dev/$disk /ram/cdrom 2> /dev/null  ; then
            echo "Found the CD-ROM on $disk"
            exit
         fi
     fi
   fi
done
done

if [ -f /proc/scsi/scsi ] ; then

    if ! grep -q "Attached devices: none" /proc/scsi/scsi
      then
      for drive in `echo /dev/scd?`
      do
        if ! mount -r -t iso9660 $drive /ram/cdrom 2> /dev/null
        then
          continue
        else
          echo "Found the CD-ROM on $drive"
          exit
        fi
      done
    fi
fi
echo "No CD-ROM found"



>From this is can be seen that the following programs are needed during the boot process: 

bash cp echo gzip mkdir mkswap mv rm tar chroot grep ln mke2fs mount pivot_root sh 

Because shared libraries plus programs are smaller than static programs, the following libraries are needed: 

ld-2.2.4.so
ld-linux.so.2 -> ld-2.2.4.so
libc-2.2.4.so
libc.so.6 -> libc-2.2.4.so
libcom_err.so.2 -> libcom_err.so.2.0
libcom_err.so.2.0
libdl-2.2.4.so
libdl.so.2 -> libdl-2.2.4.so
libe2p.so.2 -> libe2p.so.2.3
libe2p.so.2.3
libext2fs.so.2 -> libext2fs.so.2.4
libext2fs.so.2.4
libm-2.2.4.so
libm.so.6 -> libm-2.2.4.so
libncurses.so.5 -> libncurses.so.5.2
libncurses.so.5.2
libpthread-0.9.so
libpthread.so.0 -> libpthread-0.9.so
librt-2.2.4.so
librt.so.1 -> librt-2.2.4.so
libuuid.so.1 -> libuuid.so.1.2
libuuid.so.1.2

We can therefore make a system like this in a directory called initrdtree 

ls  initrdtree/
bin   dev  etc  initrd  lib linuxrc
mount_cdrom proc root sbin tmp usr var

Where bin a link to sbin, sbin contains the programs and lib the libraries. linuxrc and mount_cdrom are the scripts, and dev has the devices. 

This file system must be small enough, ( 6-7Mb ), so that its compressed size, ( 2Mb ), plus a kernel is less than 2.88Mb. 

A file system can be made on a loop device, and the directory initrdtree copied to it. The file system is then compressed, and this compressed file is put into a futher file system containing a kernel. This file system must be exactly 2.88Mb, (it is a floppy to the hardware). This is also mounted on a loop device and lilo is run on it. This is then the boot image that mkisofs sees with the -b flag 

Here is the script build.sh that builds the iso; note that the system providing the CD image is mounted on cdtree/ The build directory looks like: 
bootimagetree # Contains the kernel and the compressed file system
build.sh  # The script
initrdtree    # Contains the boot image system before compression
cdtree    #  The system providing the CD image is mounted here



#! /bin/sh 

if [ -z $TOPDIR ] ; then
  echo "you must define TOPDIR"
  exit
fi

oldpwd=`pwd`

cd $TOPDIR

# we need to set aside a few loop devices. I chose (in reverse order of their appearance)
# -- loop1 for the boot image
# -- loop2 for the ram disk image
# since the loop1 choice is reflected in the lilo.loopfix file, 
# you should not change that (or you need to change the file).
# I had used loop0 first, but I found that this is used by the Samba daemon.
# Also, I assume that the mount points are /mnt/loop{1,2}.
# In principle we could do with one, but it comes in handy to be able to
# leave one mounted, so I took two different ones. 

# we first assume that a proper directory tree of the later ramdisk 
# is in the initrdtree directory. Put everything in there what you think
# will be needed. We assume that this is the case.

echo -n "Creating the Initial Ramdisk image.... "

# first find out how much space we need. 
ISIZE=`du -s -k  $TOPDIR/initrdtree/ | awk '{print $1}'`

# is that true? Anyway, we are smaller than that.
if [ $ISIZE -gt 8192 ]; then
   echo "Initial Ramdisk max size exceeded ($ISIZE, max is 8192KB)"
   exit 1
fi

ISIZE=`expr $ISIZE + 1024`
echo "Initial Ramdisk contents will be $ISIZE KB"

# delete the existing ramdisk image, if there is one
rm -f $TOPDIR/ramdisk

# create a file of 4MB (4096 KB)
# Modified to calculated $ISIZE
dd if=/dev/zero of=$TOPDIR/ramdisk bs=1k count=$ISIZE

# associate it with /dev/loop2
losetup /dev/loop2 $TOPDIR/ramdisk

# make an ext2 filesystem on it. We set the amount of unused space to 0%
# and turn down the number of inodes to save space
#mkfs  -t ext2 -i 16384 -m 0 /dev/loop2
#  A plain mke2fs works better
mke2fs  /dev/loop2

# we mount it...
mount /dev/loop2 /mnt/loop2 

# ... and delete the lost+found directory 
rm -rf /mnt/loop2/lost+found 

# then we copy the contents of our initrdtree to this filesystem
cp -dpR $TOPDIR/initrdtree/* /mnt/loop2/

# and unmount and divorce /dev/loop2
umount /mnt/loop2
losetup -d /dev/loop2 

echo "done"

# Now we have the image of the ramdisk in $TOPDIR/ramdisk. We
# compress this one and write the compressed image to the boot tree:

echo -n "Compressing the Ramdisk image.... "

# delete any existing one
rm -f $TOPDIR/bootimagetree/initrd.img

# and gzip our ramdisk image and put it in the right place.
gzip -9 -c $TOPDIR/ramdisk > $TOPDIR/bootimagetree/initrd.img

# we are done with the uncompresses ramdisk image, delete it
rm  $TOPDIR/ramdisk

# how much is the contents of the bootimagetree?
ISIZE=`du -s -k  $TOPDIR/bootimagetree/ | awk '{print $1}'`
echo "Boot image size is $ISIZE KB"

echo "done"

# Part II. We work the boot tree (with the image of the ramdisk) now.
# we put that into yet another image which we put on the CD. 
# This image has to be 2.88 MB exactly, because we emulate a 2.88MB floppy.

echo -n "Creating the boot image.... "

# delete any leftover version
rm -f $TOPDIR/cdtree/boot/boot.img

# and make a file of the proper size (this time it's fixed at 2880 KB)
# note that the file gets created already in the right place to be the boot image.
dd if=/dev/zero of=$TOPDIR/cdtree/boot/boot.img bs=1k count=2880

# this one gets associated with loop1 and gets a ext2 file system
losetup /dev/loop1 $TOPDIR/cdtree/boot/boot.img
mkfs -t ext2 /dev/loop1

# mount it...
mount /dev/loop1 /mnt/loop1

# ... and copy the contents of our bootimagetree over
cp -dpR $TOPDIR/bootimagetree/* /mnt/loop1/ 

#and we copy our system's boot loader...
cp /boot/boot.* /mnt/loop1/boot/

# now we calculate the ramdisk size for the lilo.conf
# Hard code the size we want; also see linuxrc for dd's count=
ISIZE=30000
echo "Ram disk size will be $ISIZE KB"
cat > $TOPDIR/lilo.conf <<EOF
disk=/dev/loop1
bios=0x00 # bios ID from drive A, we need that here because lilo
# need to know which boot device to use
sectors=36 # 2.88MB disk geometry
heads=2
cylinders=80
timeout=30
 
 boot=/dev/loop1
 message=/mnt/loop1/boot/boot.msg
 install=/mnt/loop1/boot/boot.b
 map=/mnt/loop1/boot/map
 prompt
 compact
  
 image=/mnt/loop1/boot/vmlinuz
   label=linux
   initrd=/mnt/loop1/initrd.img
   append = "root=/dev/ram init=/linuxrc rw"
   ramdisk=$ISIZE

EOF


# run lilo
/sbin/lilo -C $TOPDIR/lilo.conf

rm -f $TOPDIR/lilo.conf

# unmount and divorce from the loop device
umount /mnt/loop1
losetup -d /dev/loop1 

echo "done"

# note that after running lilo, we cannot mount the image back. That's why 
# we make it a throwaway.

# go to the top directory of the future CD
cd $TOPDIR/cdtree

# and create the CD image
# you can fill in the info below as follows if you like
# -p "preparer id" - that's your email, for example
# -P "publisher_id" - again you
# -A "Application_id"

echo -n "Creating the CD iso image, $TOPDIR/bootcd.iso... "
mkisofs -b boot/boot.img -c boot.catalog \
               -o $TOPDIR/bootcd.iso \
               -J -r -T \
               -p "Your email" \
               -P "Your name" \
               -A "LFS Disk" \
	       .

echo "done"

# go back where we came from
cd $oldpwd

# now we can burn this image to a cd. 
Making the bootable CD
/etc/mtab must be a pointer to /proc/mounts 
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
cd $LFS/etc
mv fstab fstab.bak
cat > fstab << EOF
/dev/ram                /                       ext2    defaults        0 0
proc                    /proc                   proc    defaults        0 0
swapspace               swap                    swap    defaults        0 0
EOF
You need the script checkcd to replace checkfs and mountfs 
cat > $LFS/etc/init.d << EOF
#!/bin/sh
# Begin /etc/init.d/checkcd
#
# Include the functions declared in the /etc/init.d/functions file
#
source /etc/init.d/functions
#
# Activate all the swap partitions declared in the /etc/fstab file
#
echo -n "Activating swap..."
/sbin/swapon -a
evaluate_retval
echo -n "Remounting root file system in read-write mode..."
/bin/mount -n -o remount,rw /
evaluate_retval

echo "Making /tmp writeable"
chmod 1777 /tmp

umount  /initrd/proc
echo "Goodbye to the RAMDISK"
umount /initrd
EOF

cd $LFS/etc/rcS.d
ln -s ../init.d/checkcd  S250checkcd
mv S200checkfs ZZZS200checkfs
mv S300mountfs ZZZS300mountfs
Note that the umount of /initrd/proc, then /initrd releases the boot image, it is no longer needed. 

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 
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 in bootcd.iso 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

Note: If you have lost your mtab, then just delete the symbolic link.
You will get some warnings the first time you reboot, but an mtab will be created.

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

And finaly the links
cd $LFS/etc/rcS.d
mv S250checkcd ZZZS250checkcd
mv ZZZS200checkfs S200checkfs
mv ZZZS300mountfs S300mountfs


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. 


--------------------------------------------------------------------------------


r882 - trunk
tushar at linuxfromscratch.org tushar at linuxfromscratch.org 
Tue Aug 10 19:38:15 MDT 2004 

  a.. Previous message: r881 - trunk 
  b.. Next message: r883 - trunk 
  c.. Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

--------------------------------------------------------------------------------

Author: tushar
Date: 2004-08-10 18:38:13 -0600 (Tue, 10 Aug 2004)
New Revision: 882

Added:
   trunk/2.6-udev-nptl-bootcd.txt
Removed:
   trunk/lfs-live-cd.txt
Log:
Added Hint: 2.6-udev-nptl-bootcd

Added: trunk/2.6-udev-nptl-bootcd.txt
===================================================================
--- trunk/2.6-udev-nptl-bootcd.txt	2004-08-11 00:16:53 UTC (rev 881)
+++ trunk/2.6-udev-nptl-bootcd.txt	2004-08-11 00:38:13 UTC (rev 882)
@@ -0,0 +1,652 @@
+AUTHOR: Mike Hernandez <mike at culmination dot org>
+
+DATE: 2004-07-24
+
+LICENSE: GNU Free Documentation License Version 1.2
+
+SYNOPSIS: How to create a live cd with udev, NPTL, and the 2.6 kernel
+          
+
+DESCRIPTION:
+This hint describes, in detail, the process by which I created a live cd
+from a system built with the BE-LFS book (As of 2004-04-27). The reader
+should be able to follow the hint to create a live cd of their own.
+It was adapted from the "Easy" hint to work with what is currently
+the "unstable" book.
+
+PREREQUISITES:
+1. A working LFS System (and cdrtools)
+2. An LFS system built for the purpose of creating a live cd (see below)
+3. CD Writer + Media (but you knew that, I bet)
+4. Syslinux
+
+HINT:
+
+First of all you might be wondering why you need two systems to create a live 
+cd. The reason is actually quite simple. If you are like me, you optimized your
+lfs system to suit your pc (or in my case, laptop). I have a pentium 4 system,
+so all of the programs which can handle optimization have been built with:
+
+        CFLAGS='-march=pentium4' 
+
+So what's the issue? It's that I want my live cd to run on just about anything
+that can boot a cd! The programs on my current system won't run on any machine 
+that isn't a pentium 4. I actually use many more optimizations when I build,
+but here I mention the architecture because it illustrates my first point:
+
+**Remember that the system running your live cd may not be the same as your 
+working system.**
+
+It really all depends on what you want your live cd to do. You may want to
+consider optimizing everything in your live cd system for size? That's up to
+you. 
+
+Another reason you want to have a separate system is because in order to
+create the cd we make some directories and move very important files
+around. In the event that something goes wrong, having at least your
+initial working system (if not a backup of the livecd system) is essential.
+
+Ok with that out of the way, let's get to creating the cd!
+
+If you want to copy and paste commands, you should set the LIVECD
+variable set to point to the mount point of the system you are
+building:
+
+        export LIVECD=/mnt/livecd 
+
+For the purpose of the next command you might want to set LIVECDDEV as well:
+
+        export LIVECDDEV=/dev/your-drive+partition
+
+Set the ISODIR to the location where you would like to keep the image:
+
+        export ISODIR=/where/you/have/space
+
+STEP ONE: chrooting into the livecd system 
+1.  Mount your live cd system:
+
+        mkdir -p $LIVECD
+        mount $LIVECDDEV $LIVECD
+
+2.  As per the directions of the BE-LFS book which is current at
+	the time this is written, mount the virtual file systems prior 
+	to entering the chroot environment:
+		
+        mount -t proc proc $LIVECD/proc
+        mount -t sysfs sysfs $LIVECD/sys
+
+    and perform the fake mounts:
+
+        mount -f -t ramfs ramfs $LIVECD/dev
+        mount -f -t tmpfs tmpfs $LIVECD/dev/shm
+        mount -f -t devpts -o gid=4,mode=620 devpts $LIVECD/dev/pts
+
+3.  chroot into the live cd system with the command given at the end of
+    chapter 6. (NOT THE CHROOT COMMAND AT THE BEGINNING!!!):
+
+        chroot $LIVECD /usr/bin/env -i \
+        HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
+        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
+        /bin/bash --login
+
+4.  mount ramfs and populate /dev
+
+        mount -n -t ramfs none /dev
+        /sbin/udevstart
+
+5.  Create essential symlinks and directories not created by udev:
+
+        ln -s /proc/self/fd /dev/fd
+        ln -s /proc/self/fd/0 /dev/stdin
+        ln -s /proc/self/fd/1 /dev/stdout
+        ln -s /proc/self/fd/2 /dev/stderr
+        ln -s /proc/kcore /dev/core
+        mkdir /dev/pts
+        mkdir /dev/shm
+
+6.  Perform the mounting of the proper virtual (kernel) file systems:
+
+        mount -t devpts -o gid=4,mode=620 none /dev/pts
+        mount -t tmpfs none /dev/shm
+
+STEP TWO: Building the kernel for your live cd
+
+Building the kernel for your live cd is not something to be taken lightly
+by even a veteran! There are options which need to be built in and others
+which can be built as modules. I assume that if you're using what is, at
+the moment, either the testing or unstable branch of the book,
+that you know how to build and configure the 2.6 kernel, just be careful! =) 
+ 
+STEP THREE: Installing cdrtools (for using isoinfo)
+  Note: The original "easy" hint allowed for the use of isoinfo.
+        The options for isoinfo have changed, however.
+        I do not use isoinfo but have left the section in tact
+        so that the directions for using it could be added later.
+        (point: you really dont need to install cdrtools)
+
+(Follow blfs instructions)
+If you are using cdrtools-2.00.3 then you may have to
+insert:
+ 
+        typedef unsigned char u8; 
+
+"ifdef linux" section of scsihack.c in order for it to compile properly.
+(see http://linuxfromscratch.org/pipermail/blfs-support/2003-July/043100.html)                                                                                
+STEP FOUR: Moving /dev /etc /home /root /tmp /var  to /fake/needwrite
+
+# What is /fake/needwrite?
+# The /fake/needwrite directory is used to hold files that must be
+# writable while the livecd is running.
+# Obviously, these files can not remain on the cd-rom, and so are moved
+# To a location from which they will be copied into a ramdisk
+
+	First we have to create this directory and the mountpoint for the ramdisk:
+
+        mkdir -p $LIVECD/fake/{needwrite,ramdisk}
+
+	Then we can move it there:
+
+        cd $LIVECD/
+        mv dev/ etc/ home/ root/ tmp/ var/ fake/needwrite/
+
+ Create symlinks /... -> /fake/needwrite/...
+
+	We have moved dev/ etc/ home/ root/ tmp/ and var/ to /fake/needwrite.
+	Now we have to create symlinks so that everything seems to be
+	as before.
+
+        cd $LIVECD/
+        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
+        ln -s fake/needwrite/etc etc
+
+    now "ls -l" says:
+    dev  -> fake/needwrite/dev
+    etc  -> fake/needwrite/etc
+    home -> fake/needwrite/home
+    root -> fake/needwrite/root
+    tmp  -> fake/needwrite/tmp
+    var  -> fake/needwrite/var
+
+
+STEP FIVE: Create boot script which mounts the ramdisk
+   --------------------------------------------
+
+	Ok, we have /etc /dev /var /tmp /root /home linked to
+	/fake/needwrite which is read-only (because it's on the cd).
+	To be able to login (and to run services on runlevel x
+	which need write access to /dev /var /tmp /root /home or /etc)
+	we must call a script from our /etc/rc.d/init.d/ directory which
+	mounts a ramdisk on /fake/needwrite with write access.
+
+  The following script creates 2 ram disks, a temporary one and one
+  that will house the directories which need write permission.
+  It copies the files from the cd to the temporary ram disk,
+  and then from there to the final ram disk.
+
+  The original hint used 1 ram disk, but this caused a serious
+  problem for me. First of all, the initrd which is loaded at
+  boot time uses the first ramdisk (/dev/ram0). Therefore it
+  trying to mount /dev/ram0 somewhere else leads to "device
+  already mounted" errors. Secondly, umounting a ram disk causes
+  all of the files to be lost. The original hint unmounted the
+  ram disk and remounted it, assuming the files would still be
+  there. That did not work for me, which is why I made sure
+  that /dev/ram{0,1,2} are all present, and suggest you do the
+  same. 
+
+cat > $LIVECD/etc/rc.d/init.d/create_ramdisk << "EOF"
+#!/bin/sh
+
+# SET UP SOME VARIABLES FOR DEVICES AND DIRECTORIES
+
+dev_ram=/dev/ram1
+dev_ram2=/dev/ram2
+dir_ramdisk=/fake/ramdisk
+dir_needwrite=/fake/needwrite
+
+# SOURCE THE FUNCTIONS FILE
+
+source /etc/rc.d/init.d/functions
+
+case "$1" in
+        start)
+          
+					# CREATE THE RAM DISK
+          
+					echo "Creating ext2fs on $dev_ram ...              "
+          /sbin/mke2fs -m 0 -i 1024 -q $dev_ram > /dev/null 2>&1
+          evaluate_retval
+          sleep 1
+
+          # MOUNT THE RAM DISK
+
+          echo "Mounting ramdisk on $dir_ramdisk ...         "
+          mount -n $dev_ram $dir_ramdisk -t ext2
+          evaluate_retval
+          sleep 1
+
+          # COPY FILES TO THE RAM DISK
+
+          echo "Copying files to ramdisk ...                 "
+          cp -a $dir_needwrite/* $dir_ramdisk > /dev/null 2>&1
+          evaluate_retval
+          sleep 1
+
+          # CREATE SECOND RAMDISK
+          echo "Creating second ramdisk"
+          /sbin/mke2fs -m 0 -i 1024 -q $dev_ram2 > /dev/null 2>&1
+          evaluate_retval
+          sleep 1
+          
+          # MOUNT SECOND RAMDISK
+
+          echo "mounting second ram disk"
+          mount -n $dev_ram2 $dir_needwrite -t ext2
+          evaluate_retval
+          sleep 1
+          
+          # COPY FILES TO THE SECOND RAMDISK
+          
+          echo "copying files to the second ram disk"
+          cp -a $dir_ramdisk/* $dir_needwrite
+          evaluate_retval
+          sleep 1
+          
+          # UNMOUNT THE FIRST RAMDISK
+
+          echo "unmounting and clearing ram disks"
+          umount -n $dir_ramdisk > /dev/null 2>&1
+          blockdev --flushbufs /dev/ram1
+          evaluate_retval
+          sleep 1
+          ;;
+        *)
+          echo "Usage: $0 {start}"
+          exit 1
+          ;;
+esac
+
+EOF
+
+	Make it executable:
+
+        chmod 0755 $LIVECD/etc/rc.d/init.d/create_ramdisk
+
+  Gabe Munoz pointed out that this symlink can be S11, where it used
+  to be at S00. Of course feel free to number the symlink as you see
+	fit. (This is LFS after all!):
+	/etc/rc.d/rcsysinit.d/S11create_ramdisk -> ../init.d/create_ramdisk
+
+        cd $LIVECD/etc/rc.d/rcsysinit.d
+        ln -s ../init.d/create_ramdisk S00create_ramdisk
+
+**Note: If you have another script set to run first (at S00) you should
+  move that script to start after. (Maybe to S05?)
+
+
+
+STEP SIX: Install the bootloader isolinux
+   -------------------------------
+
+	We also need a bootloader on the CD to boot the kernel and ramdisk.
+	lilo and grub are all nice but isolinux is made to boot iso images!
+	(it comes with syslinux). I assume the tarball syslinux-2.09.tar.bz2 is
+	already placed in $LIVECD/usr/src.
+
+cd $LIVECD/usr/src
+
+tar xzf syslinux-2.09.tar.gz
+mkdir $LIVECD/isolinux
+cp syslinux-2.09/isolinux.bin $LIVECD/isolinux
+
+mv $LIVECD/boot/* $LIVECD/isolinux
+cd $LIVECD/
+rmdir boot
+ln -s isolinux boot
+
+cat > $LIVECD/isolinux/isolinux.cfg << "EOF"
+default bootcd
+
+label bootcd
+  kernel lfskernel
+  append initrd=initrd.gz root=/dev/ram0 init=/linuxrc ramdisk_size=16384
+EOF
+
+STEP SEVEN: Create initial ramdisk
+   ----------------------
+
+	!!! But first we have to change /etc/fstab of the live cd system !!!
+	Delete all entries you don't need. (e.g. all /dev/hd*)
+	You only need proc (and maybe devfs, devpts)
+
+vi $LIVECD/etc/fstab
+
+	Don't worry about mounting root filesystem "/".
+	This will be mounted by linuxrc from initrd fs.
+
+	You may find it helpful to remove the following links:
+
+rm $LIVECD/etc/rc.d/rc3.d/S20network
+rm $LIVECD/etc/rc.d/rc0.d/K80network
+rm $LIVECD/etc/rc.d/rc6.d/K80network
+rm $LIVECD/etc/rc.d/rcsysinit.d/S40mountfs
+rm $LIVECD/etc/rc.d/rcsysinit.d/S30checkfs
+
+	Now we create the initrd image file and filesystem.
+
+    dd if=/dev/zero of=$LIVECD/boot/initrd bs=1024 count=6144
+    mke2fs -m 0 -i 1024 -F $LIVECD/boot/initrd
+
+    mount -o loop $LIVECD/boot/initrd $LIVECD/mnt
+    cd $LIVECD/mnt
+    mkdir bin sbin lib dev proc mnt sys etc
+    cp -a $LIVECD/bin/{bash,mount,grep,umount,echo,ln,mkdir} bin/
+    cp -a $LIVECD/sbin/udev* sbin/
+    cp -a $(find $LIVECD -name "test" -type f) bin/
+    cp -a $(find $LIVECD -name "chroot" -type f) bin/
+    cp -a $(find $LIVECD -name "pivot_root" -type f) bin/
+    cp -H $LIVECD/lib/{libncurses.so.5,libdl.so.2,libc.so.6,ld-linux.so.2} lib/
+		cp -H $LIVECD/lib/{libreadline.so.5.0,libhistory.so.5.0} lib/
+
+You need the console, null, ram0, ram1 and ram2 devices!
+console and null should already be present
+but we have to create /dev/ram0, /dev/ram1 and /dev/ram2
+
+    cp -a $LIVECD/dev/{console,null} dev/
+
+You need /etc/udev, /etc/hotplug and /etc/dev.d
+
+    cp -a $LIVECD/etc/{udev,dev.d,hotplug.d} etc/
+
+    ln -s bash bin/sh
+    ln -s test bin/[
+
+If you wish to use isoinfo instead of mount to detect the live cd you
+must also copy isoinfo into the initial ramdisk.
+
+    cp $(find $LIVECD -name "isoinfo" -type f) bin/
+
+The first program executed by the kernel is /linuxrc. As it does not
+exist we create it. Our script will find the CD in the correct
+	CD-ROM drive and then mount it as rootfs / and run /sbin/init 3.
+
+
+----------- copy & paste -------------
+
+cat > $LIVECD/mnt/linuxrc << "EOF"
+#!/bin/sh
+                                                                                
+#ID is the volume id / label of the LFS boot CD if you use /bin/isoinfo
+#or ID is a file in root of the LFS boot CD
+ID="livecd"
+TMP_MOUNT="/mnt"
+                                                                                
+PATH="/bin:/sbin:/usr/bin:/usr/sbin"
+                                                                                
+#isoinfo currently does not work
+#if [ -e "/bin/isoinfo" ]; then
+#  CHECK_TYPE="isoinfo"
+#else
+  CHECK_TYPE="try_mount"
+#fi
+                                                                                
+#***********************************MOUNT KERNEL FILESYSTEMS
+
+# Create the proc directory if it does not exist
+
+if [ ! -d "/proc/" ]; then
+  mkdir /proc
+fi
+
+# Mount the proc filesystem
+
+mount -n proc /proc -t proc
+
+# If sysfs is listed as a valid filesystem type in /proc
+# then mount it (if it doesnt then udev wont work
+# and you wont have the devices you need)
+                                                                              
+if grep -q '[[:space:]]sysfs' /proc/filesystems; then
+    if [ ! -d /sys/block ]; then
+    mount -n sysfs /sys -t sysfs
+    fi
+fi
+                                                                                
+# Create some things that sysfs does not, and should not export for us.  Feel
+# free to add devices to this list.
+
+make_extra_nodes() {
+        ln -s /proc/self/fd /dev/fd
+        ln -s /proc/self/fd/0 /dev/stdin
+        ln -s /proc/self/fd/1 /dev/stdout
+        ln -s /proc/self/fd/2 /dev/stderr
+        ln -s /proc/kcore /dev/core
+        mkdir /dev/pts
+        mkdir /dev/shm
+}
+                                                                                
+                                                                                
+if [ ! -x /sbin/hotplug ]; then
+    echo /sbin/udev > /proc/sys/kernel/hotplug
+fi
+                                                                                
+# Mount a temporary file system over /dev, so that any devices
+# made or removed during this boot don't affect the next one.
+# The reason we don't write to mtab is because we don't ever
+# want /dev to be unavailable (such as by `umount -a').
+                                                                                
+mount -n ramfs /dev -t ramfs
+                                                                                
+/sbin/udevstart
+                                                                                
+make_extra_nodes
+                                                                               
+
+# Detecting the livecd is pretty complicated, 
+# but is a very logical process
+                                                                                
+#1. Search for cdrom devices and add them to CDROM_LIST
+                                                                                
+CDROM_LIST=""
+                                                                                
+# Search in proc tree for ide cdrom devices
+# There used to be a section for devfs, but this was
+# edited for udev. Actually we should probably not
+# use /proc anymore, but use sysfs instead...
+# Perhaps in the future;)
+    
+  # Check for ide channels.
+ 
+  for ide_channel in /proc/ide/ide[0-9]
+  do
+
+    # If there are no ide channels found, then skip this
+
+    if [ ! -d "$ide_channel" ]; then
+     break
+    fi
+
+		# Try each ide device to see if we can find the cd-rom drive
+
+    for ide_device in hda hdb hdc hdd hde hdf hdg hdh hdi hdj hdk hdl hdm hdn
+    do
+      device_media_file="$ide_channel/$ide_device/media"
+      if [ -e "$device_media_file" ]; then
+        grep -i "cdrom" $device_media_file > /dev/null 2>&1
+        if [ $? -eq 0 ]; then
+            CDROM_LIST="$CDROM_LIST /dev/$ide_device"
+        fi
+      fi
+    done
+  done
+
+  # Check for scsi cds
+
+  for scsi_cdrom in /dev/scd[0-99]
+  do
+    if [ -e "$scsi_cdrom" ]; then
+      CDROM_LIST="$CDROM_LIST $scsi_cdrom"
+    fi
+  done
+                                                                                
+#2. now we try to find the LFS boot CD (we use ID as identification)
+                                                                                
+LFS_CDROM_DEVICE=""
+
+for cdrom_device in $CDROM_LIST
+do
+  if [ "$CHECK_TYPE" = "try_mount" ]; then
+    mount -n -t iso9660 ${cdrom_device} $TMP_MOUNT
+    # > /dev/null 2>&1
+    media_found=$?
+  fi
+
+	# Again, the isoinfo check here doesnt work
+	# I plan on figuring this out when I'm not lazy
+	# The livecd will work just fine without isoinfo
+	# I'm leaving this here to create less work later =)
+
+  if [ "$CHECK_TYPE" = "isoinfo" ]; then
+    isoinfo -d -i $cdrom_device > /dev/null 2>&1
+    media_found=$?
+    if [ $media_found -ne 0 ]; then
+      isoinfo -V $cdrom_device > /dev/null 2>&1
+      media_found=$?
+    fi
+  fi
+                                                                                
+  if [ $media_found -eq 0 ]; then
+                                                                                
+    echo -n "media found"
+    if [ "$CHECK_TYPE" = "try_mount" ]; then
+      [ -e "$TMP_MOUNT/$ID" ]
+      media_lfs=$?
+    fi
+    if [ "$CHECK_TYPE" = "isoinfo" ]; then
+     isoinfo -d -i $cdrom_device | grep -i "Volume id:" | grep "$ID" \
+      > /dev/null 2>&1
+      media_lfs=$?
+      if [ $media_lfs -ne 0 ]; then
+        isoinfo -V $cdrom_device | grep "$ID" > /dev/null 2>&1
+        media_lfs=$?
+      fi
+    fi
+                                                                                
+    if [ "$CHECK_TYPE" = "try_mount" ]; then
+      umount -n $cdrom_device > /dev/null 2>&1
+    fi
+                                                                                
+    if [ $media_lfs -eq 0 ]; then
+      echo ", LFS boot CD found. Ready!"
+      LFS_CDROM_DEVICE="$cdrom_device"
+      break;
+    else
+      echo ", not LFS boot CD."
+    fi
+                                                                                
+  else
+    echo "no media "
+  fi
+done
+                                                                                
+                                                                                
+#3. mount LFS CD as / (root fs)
+if [ "$LFS_CDROM_DEVICE" = "" ]; then
+                                                                                
+  echo "No LFS boot CD found!!!"
+  exit 1
+                                                                                
+else
+                                                                                
+  echo "Booting from $LFS_CDROM_DEVICE ...                  "
+                                                    
+
+	# This is the magical part that makes a livecd live!
+	# The cd is mounted and pivot_root+chroot commands
+	# are used to start the system.
+	# If you really want to know what is going on here,
+	# You should read the chroot and pivot_root man pages                            
+  mount -n -o ro -t iso9660 $LFS_CDROM_DEVICE $TMP_MOUNT
+  cd $TMP_MOUNT
+  pivot_root . mnt
+  umount -n /mnt/proc >/dev/null 2>&1
+  exec chroot . sh -c 'umount -n /mnt >/dev/null 2>&1; exec -a init.new /sbin/init 3' <dev/console >dev/console 2>&1
+
+fi                                                                               
+ 
+EOF
+
+--------------------------------------
+
+
+	To make this script executable run
+
+chmod 0755 $LIVECD/mnt/linuxrc
+
+	Ok, that's it. Unmount the image and compress it.
+
+cd $LIVECD/
+umount $LIVECD/mnt
+gzip $LIVECD/boot/initrd
+
+
+8. Burn the Boot CD
+   ----------------
+
+	If you have a CD-RW you should take this for testing. When
+	your system boots quite good from CD-RW you can burn it on a CD-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 -ch $LIVECD/ | grep total
+
+	Delete all the stuff you don't need on a Boot CD. (e.g. /usr/src/*)
+
+	Because linuxrc must be able to identify the CD you have to create a
+	file called "livecd". (unless you use isoinfo)
+
+touch $LIVECD/livecd
+
+	Now burn the LFS system on CD
+
+	Note!
+	dev=/dev/hdc is the device number of your CD-Writer
+	Check your SCSI devices with "cdrecord -scanbus"
+	( as of this writing scsi-emulation is no longer required)
+	speed=4 should be changed to (max) speed of your CD-Writer.
+	If you are not using a CD-RW remove blank=fast from the cdrecord-command!
+
+cd $LIVECD/
+mkisofs -R -l -L -D -b isolinux/isolinux.bin -o $ISODIR/livecd_image.iso -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -V "livecd" $LIVECD && 
+cdrecord -v -eject dev=/dev/hdc blank=fast $ISODIR/livecd_image.iso
+
+
+
+ACKNOWLEDGEMENTS:
+
+Thanks to:
+
+ * Thomas Foecking <thomas at foecking.de> and Christian Hesse <mail at earthworm.de>
+   For writing the "Easy Boot CD of your LFS" hint which confused me so much
+   when I tried it with udev that I decided to write this one =o)
+
+ * Gabriel Aneceto Munoz
+   For bring syntax errors and other updates to my attention
+
+Feel free to email me comments, point out typos, etc. 
+
+CHANGELOG:
+[2004-08-04]
+  * Fixed syntax errors and made other updates
+[2004-07-24]
+  * Finally found the time to proofread and submit the hint;)
+[2004-05-19]
+  * Added environment variables for more flexibility
+[2004-05-17]
+  * Initial hint completed.

Deleted: trunk/lfs-live-cd.txt
===================================================================
--- trunk/lfs-live-cd.txt	2004-08-11 00:16:53 UTC (rev 881)
+++ trunk/lfs-live-cd.txt	2004-08-11 00:38:13 UTC (rev 882)
@@ -1,643 +0,0 @@
-AUTHOR: Mike Hernandez <mike at culmination dot org>
-
-DATE: 2004-07-24
-
-LICENSE: GNU Free Documentation License Version 1.2
-
-SYNOPSIS: How to create a live cd with udev, NPTL, and the 2.6 kernel
-          
-
-DESCRIPTION:
-This hint describes, in detail, the process by which I created a live cd
-from a system built with the BE-LFS book (As of 2004-04-27). The reader
-should be able to follow the hint to create a live cd of their own.
-It was adapted from the "Easy" hint to work with what is currently
-the "unstable" book.
-
-PREREQUISITES:
-1. A working LFS System (and cdrtools)
-2. An LFS system built for the purpose of creating a live cd (see below)
-3. CD Writer + Media (but you knew that, I bet)
-4. Syslinux
-
-HINT:
-
-First of all you might be wondering why you need two systems to create a live 
-cd. The reason is actually quite simple. If you are like me, you optimized your
-lfs system to suit your pc (or in my case, laptop). I have a pentium 4 system,
-so all of the programs which can handle optimization have been built with:
-
-        CFLAGS='-march=pentium4' 
-
-So what's the issue? It's that I want my live cd to run on just about anything
-that can boot a cd! The programs on my current system won't run on any machine 
-that isn't a pentium 4. I actually use many more optimizations when I build,
-but here I mention the architecture because it illustrates my first point:
-
-**Remember that the system running your live cd may not be the same as your 
-working system.**
-
-It really all depends on what you want your live cd to do. You may want to
-consider optimizing everything in your live cd system for size? That's up to
-you. 
-
-Another reason you want to have a separate system is because in order to
-create the cd we make some directories and move very important files
-around. In the event that something goes wrong, having at least your
-initial working system (if not a backup of the livecd system) is essential.
-
-Ok with that out of the way, let's get to creating the cd!
-
-If you want to copy and paste commands, you should set the LIVECD
-variable set to point to the mount point of the system you are
-building:
-
-        export LIVECD=/mnt/livecd 
-
-For the purpose of the next command you might want to set LIVECDDEV as well:
-
-        export LIVECDDEV=/dev/your-drive+partition
-
-Set the ISODIR to the location where you would like to keep the image:
-
-        export ISODIR=/where/you/have/space
-
-STEP ONE: chrooting into the livecd system 
-1.  Mount your live cd system:
-
-        mkdir -p $LIVECD
-        mount $LIVECDDEV $LIVECD
-
-2.  As per the directions of the BE-LFS book which is current at
-	the time this is written, mount the virtual file systems prior 
-	to entering the chroot environment:
-		
-        mount -t proc proc $LIVECD/proc
-        mount -t sysfs sysfs $LIVECD/sys
-
-    and perform the fake mounts:
-
-        mount -f -t ramfs ramfs $LIVECD/dev
-        mount -f -t tmpfs tmpfs $LIVECD/dev/shm
-        mount -f -t devpts -o gid=4,mode=620 devpts $LIVECD/dev/pts
-
-3.  chroot into the live cd system with the command given at the end of
-    chapter 6. (NOT THE CHROOT COMMAND AT THE BEGINNING!!!):
-
-        chroot $LIVECD /usr/bin/env -i \
-        HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
-        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
-        /bin/bash --login
-
-4.  mount ramfs and populate /dev
-
-        mount -n -t ramfs none /dev
-        /sbin/udevstart
-
-5.  Create essential symlinks and directories not created by udev:
-
-        ln -s /proc/self/fd /dev/fd
-        ln -s /proc/self/fd/0 /dev/stdin
-        ln -s /proc/self/fd/1 /dev/stdout
-        ln -s /proc/self/fd/2 /dev/stderr
-        ln -s /proc/kcore /dev/core
-        mkdir /dev/pts
-        mkdir /dev/shm
-
-6.  Perform the mounting of the proper virtual (kernel) file systems:
-
-        mount -t devpts -o gid=4,mode=620 none /dev/pts
-        mount -t tmpfs none /dev/shm
-
-STEP TWO: Building the kernel for your live cd
-
-Building the kernel for your live cd is not something to be taken lightly
-by even a veteran! There are options which need to be built in and others
-which can be built as modules. I assume that if you're using what is, at
-the moment, either the testing or unstable branch of the book,
-that you know how to build and configure the 2.6 kernel, just be careful! =) 
- 
-STEP THREE: Installing cdrtools (for using isoinfo)
-  Note: The original "easy" hint allowed for the use of isoinfo.
-        The options for isoinfo have changed, however.
-        I do not use isoinfo but have left the section in tact
-        so that the directions for using it could be added later.
-        (point: you really dont need to install cdrtools)
-
-(Follow blfs instructions)
-If you are using cdrtools-2.00.3 then you may have to
-insert:
- 
-        typedef unsigned char u8; 
-
-"ifdef linux" section of scsihack.c in order for it to compile properly.
-(see http://linuxfromscratch.org/pipermail/blfs-support/2003-July/043100.html)                                                                                
-STEP FOUR: Moving /dev /etc /home /root /tmp /var  to /fake/needwrite
-
-# What is /fake/needwrite?
-# The /fake/needwrite directory is used to hold files that must be
-# writable while the livecd is running.
-# Obviously, these files can not remain on the cd-rom, and so are moved
-# To a location from which they will be copied into a ramdisk
-
-	First we have to create this directory and the mountpoint for the ramdisk:
-
-        mkdir -p $LIVECD/fake/{needwrite,ramdisk}
-
-	Then we can move it there:
-
-        cd $LIVECD/
-        mv dev/ etc/ home/ root/ tmp/ var/ fake/needwrite/
-
- Create symlinks /... -> /fake/needwrite/...
-
-	We have moved dev/ etc/ home/ root/ tmp/ and var/ to /fake/needwrite.
-	Now we have to create symlinks so that everything seems to be
-	as before.
-
-        cd $LIVECD/
-        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
-        ln -s fake/needwrite/etc etc
-
-    now "ls -l" says:
-    dev  -> fake/needwrite/dev
-    etc  -> fake/needwrite/etc
-    home -> fake/needwrite/home
-    root -> fake/needwrite/root
-    tmp  -> fake/needwrite/tmp
-    var  -> fake/needwrite/var
-
-
-STEP FIVE: Create boot script which mounts the ramdisk
-   --------------------------------------------
-
-	Ok, we have /etc /dev /var /tmp /root /home linked to
-	/fake/needwrite which is read-only (because it's on the cd).
-	To be able to login (and to run services on runlevel x
-	which need write access to /dev /var /tmp /root /home or /etc)
-	we must call a script from our /etc/rc.d/init.d/ directory which
-	mounts a ramdisk on /fake/needwrite with write access.
-
-  The following script creates 2 ram disks, a temporary one and one
-  that will house the directories which need write permission.
-  It copies the files from the cd to the temporary ram disk,
-  and then from there to the final ram disk.
-
-  The original hint used 1 ram disk, but this caused a serious
-  problem for me. First of all, the initrd which is loaded at
-  boot time uses the first ramdisk (/dev/ram0). Therefore it
-  trying to mount /dev/ram0 somewhere else leads to "device
-  already mounted" errors. Secondly, umounting a ram disk causes
-  all of the files to be lost. The original hint unmounted the
-  ram disk and remounted it, assuming the files would still be
-  there. That did not work for me, which is why I made sure
-  that /dev/ram{0,1,2} are all present, and suggest you do the
-  same. 
-
-cat > $LIVECD/etc/rc.d/init.d/create_ramdisk << "EOF"
-#!/bin/sh
-
-# SET UP SOME VARIABLES FOR DEVICES AND DIRECTORIES
-
-dev_ram=/dev/ram1
-dev_ram2=/dev/ram2
-dir_ramdisk=/fake/ramdisk
-dir_needwrite=/fake/needwrite
-
-# SOURCE THE FUNCTIONS FILE
-
-source /etc/rc.d/init.d/functions
-
-case "$1" in
-        start)
-          
-					# CREATE THE RAM DISK
-          
-					echo "Creating ext2fs on $dev_ram ...              "
-          /sbin/mke2fs -m 0 -i 1024 -q $dev_ram > /dev/null 2>&1
-          evaluate_retval
-          sleep 1
-
-          # MOUNT THE RAM DISK
-
-          echo "Mounting ramdisk on $dir_ramdisk ...         "
-          mount -n $dev_ram $dir_ramdisk -t ext2
-          evaluate_retval
-          sleep 1
-
-          # COPY FILES TO THE RAM DISK
-
-          echo "Copying files to ramdisk ...                 "
-          cp -a $dir_needwrite/* $dir_ramdisk > /dev/null 2>&1
-          evaluate_retval
-          sleep 1
-
-          # CREATE SECOND RAMDISK
-          echo "Creating second ramdisk"
-          /sbin/mke2fs -m 0 -i 1024 -q $dev_ram2 > /dev/null 2>&1
-          evaluate_retval
-          sleep 1
-          
-          # MOUNT SECOND RAMDISK
-
-          echo "mounting second ram disk"
-          mount -n $dev_ram2 $dir_needwrite -t ext2
-          evaluate_retval
-          sleep 1
-          
-          # COPY FILES TO THE SECOND RAMDISK
-          
-          echo "copying files to the second ram disk"
-          cp -a $dir_ramdisk/* $dir_needwrite
-          evaluate_retval
-          sleep 1
-          
-          # UNMOUNT THE FIRST RAMDISK
-
-          echo "unmounting and clearing ram disks"
-          umount -n $dir_ramdisk > /dev/null 2>&1
-          blockdev --flushbufs /dev/ram1
-          evaluate_retval
-          sleep 1
-          ;;
-        *)
-          echo "Usage: $0 {start}"
-          exit 1
-          ;;
-esac
-
-EOF
-
-	Make it executable:
-
-        chmod 0755 $LIVECD/etc/rc.d/init.d/create_ramdisk
-
-	create_ramdisk should be the first script excecuted by init,
-	so we set this link:
-	/etc/rc.d/rcsysinit.d/S00create_ramdisk -> ../init.d/create_ramdisk
-
-        cd $LIVECD/etc/rc.d/rcsysinit.d
-        ln -s ../init.d/create_ramdisk S00create_ramdisk
-
-**Note: If you have another script set to run first (at S00) you should
-  move that script to start after. (Maybe to S05?)
-
-
-
-STEP SIX: Install the bootloader isolinux
-   -------------------------------
-
-	We also need a bootloader on the CD to boot the kernel and ramdisk.
-	lilo and grub are all nice but isolinux is made to boot iso images!
-	(it comes with syslinux). I assume the tarball syslinux-2.09.tar.bz2 is
-	already placed in $LIVECD/usr/src.
-
-cd $LIVECD/usr/src
-
-tar xzf syslinux-2.09.tar.gz
-mkdir $LIVECD/isolinux
-cp syslinux-2.09/isolinux.bin $LIVECD/isolinux
-
-mv $LIVECD/boot/* $LIVECD/isolinux
-cd $LIVECD/
-rmdir boot
-ln -s isolinux boot
-
-cat > $LIVECD/isolinux/isolinux.cfg << "EOF"
-default bootcd
-
-label bootcd
-  kernel lfskernel
-  append initrd=initrd.gz root=/dev/ram0 init=/linuxrc ramdisk_size=16384
-EOF
-
-STEP SEVEN: Create initial ramdisk
-   ----------------------
-
-	!!! But first we have to change /etc/fstab of the live cd system !!!
-	Delete all entries you don't need. (e.g. all /dev/hd*)
-	You only need proc (and maybe devfs, devpts)
-
-vi $LIVECD/etc/fstab
-
-	Don't worry about mounting root filesystem "/".
-	This will be mounted by linuxrc from initrd fs.
-
-	You may find it helpful to remove the following links:
-
-rm $LIVECD/etc/rc.d/rc3.d/S20network
-rm $LIVECD/etc/rc.d/rc0.d/K80network
-rm $LIVECD/etc/rc.d/rc6.d/K80network
-rm $LIVECD/etc/rc.d/rcsysinit.d/S40mountfs
-rm $LIVECD/etc/rc.d/rcsysinit.d/S30checkfs
-
-	Now we create the initrd image file and filesystem.
-
-    dd if=/dev/zero of=$LIVECD/boot/initrd bs=1024 count=6144
-    mke2fs -m 0 -i 1024 -F $LIVECD/boot/initrd
-
-    mount -o loop $LIVECD/boot/initrd $LIVECD/mnt
-    cd $LIVECD/mnt
-    mkdir bin lib dev proc mnt sys etc
-    cp $LIVECD/bin/{bash,mount,grep,umount,echo,ln,mkdir} bin/
-    cp $LIVECD/sbin/udev* bin/
-    cp $(find $LIVECD -name "test" -type f) bin/
-    cp $(find $LIVECD -name "chroot" -type f) bin/
-    cp $(find $LIVECD -name "pivot_root" -type f) bin/
-    cp $LIVECD/lib/{libncurses.so.5,libdl.so.2,libc.so.6,ld-linux.so.2} lib/
-
-You need the console, null, ram0, ram1 and ram2 devices!
-console and null should already be present
-but we have to create /dev/ram0, /dev/ram1 and /dev/ram2
-
-    cp -dR $LIVECD/dev/{console,null} dev/
-
-You need /etc/udev, /etc/hotplug and /etc/dev.d
-
-    cp -R $LIVECD/etc/{udev,dev.d,hotplug.d} etc/
-
-    ln -s bash bin/sh
-    ln -s test bin/[
-
-If you wish to use isoinfo instead of mount to detect the live cd you
-must also copy isoinfo into the initial ramdisk.
-
-    cp $(find $LIVECD -name "isoinfo" -type f) bin/
-
-The first program executed by the kernel is /linuxrc. As it does not
-exist we create it. Our script will find the CD in the correct
-	CD-ROM drive and then mount it as rootfs / and run /sbin/init 3.
-
-
------------ copy & paste -------------
-
-cat > $LIVECD/mnt/linuxrc << "EOF"
-#!/bin/sh
-                                                                                
-#ID is the volume id / label of the LFS boot CD if you use /bin/isoinfo
-#or ID is a file in root of the LFS boot CD
-ID="livecd"
-TMP_MOUNT="/mnt"
-                                                                                
-PATH="/bin:/sbin:/usr/bin:/usr/sbin"
-                                                                                
-#isoinfo currently does not work
-#if [ -e "/bin/isoinfo" ]; then
-#  CHECK_TYPE="isoinfo"
-#else
-  CHECK_TYPE="try_mount"
-#fi
-                                                                                
-#***********************************MOUNT KERNEL FILESYSTEMS
-
-# Create the proc directory if it does not exist
-
-if [ ! -d "/proc/" ]; then
-  mkdir /proc
-fi
-
-# Mount the proc filesystem
-
-mount -n proc /proc -t proc
-
-# If sysfs is listed as a valid filesystem type in /proc
-# then mount it (if it doesnt then udev wont work
-# and you wont have the devices you need)
-                                                                              
-if grep -q '[[:space:]]sysfs' /proc/filesystems; then
-    if [ ! -d /sys/block ]; then
-    mount -n sysfs /sys -t sysfs
-    fi
-fi
-                                                                                
-# Create some things that sysfs does not, and should not export for us.  Feel
-# free to add devices to this list.
-
-make_extra_nodes() {
-        ln -s /proc/self/fd /dev/fd
-        ln -s /proc/self/fd/0 /dev/stdin
-        ln -s /proc/self/fd/1 /dev/stdout
-        ln -s /proc/self/fd/2 /dev/stderr
-        ln -s /proc/kcore /dev/core
-        mkdir /dev/pts
-        mkdir /dev/shm
-}
-                                                                                
-                                                                                
-if [ ! -x /sbin/hotplug ]; then
-    echo /sbin/udev > /proc/sys/kernel/hotplug
-fi
-                                                                                
-# Mount a temporary file system over /dev, so that any devices
-# made or removed during this boot don't affect the next one.
-# The reason we don't write to mtab is because we don't ever
-# want /dev to be unavailable (such as by `umount -a').
-                                                                                
-mount -n ramfs /dev -t ramfs
-                                                                                
-/sbin/udevstart
-                                                                                
-make_extra_nodes
-                                                                               
-
-# Detecting the livecd is pretty complicated, 
-# but is a very logical process
-                                                                                
-#1. Search for cdrom devices and add them to CDROM_LIST
-                                                                                
-CDROM_LIST=""
-                                                                                
-# Search in proc tree for ide cdrom devices
-# There used to be a section for devfs, but this was
-# edited for udev. Actually we should probably not
-# use /proc anymore, but use sysfs instead...
-# Perhaps in the future;)
-    
-  # Check for ide channels.
- 
-  for ide_channel in /proc/ide/ide[0-9]
-  do
-
-    # If there are no ide channels found, then skip this
-
-    if [ ! -d "$ide_channel" ]; then
-     break
-    fi
-
-		# Try each ide device to see if we can find the cd-rom drive
-
-    for ide_device in hda hdb hdc hdd hde hdf hdg hdh hdi hdj hdk hdl hdm hdn
-    do
-      device_media_file="$ide_channel/$ide_device/media"
-      if [ -e "$device_media_file" ]; then
-        grep -i "cdrom" $device_media_file > /dev/null 2>&1
-        if [ $? -eq 0 ]; then
-            CDROM_LIST="$CDROM_LIST /dev/$ide_device"
-        fi
-      fi
-    done
-  done
-
-  # Check for scsi cds
-
-  for scsi_cdrom in /dev/scd[0-99]
-  do
-    if [ -e "$scsi_cdrom" ]; then
-      CDROM_LIST="$CDROM_LIST $scsi_cdrom"
-    fi
-  done
-fi
-                                                                                
-#2. now we try to find the LFS boot CD (we use ID as identification)
-                                                                                
-LFS_CDROM_DEVICE=""
-
-for cdrom_device in $CDROM_LIST
-do
-  if [ "$CHECK_TYPE" = "try_mount" ]; then
-    mount -n -t iso9660 ${cdrom_device} $TMP_MOUNT
-    # > /dev/null 2>&1
-    media_found=$?
-  fi
-
-	# Again, the isoinfo check here doesnt work
-	# I plan on figuring this out when I'm not lazy
-	# The livecd will work just fine without isoinfo
-	# I'm leaving this here to create less work later =)
-
-  if [ "$CHECK_TYPE" = "isoinfo" ]; then
-    isoinfo -d -i $cdrom_device > /dev/null 2>&1
-    media_found=$?
-    if [ $media_found -ne 0 ]; then
-      isoinfo -V $cdrom_device > /dev/null 2>&1
-      media_found=$?
-    fi
-  fi
-                                                                                
-  if [ $media_found -eq 0 ]; then
-                                                                                
-    echo -n "media found"
-    if [ "$CHECK_TYPE" = "try_mount" ]; then
-      [ -e "$TMP_MOUNT/$ID" ]
-      media_lfs=$?
-    fi
-    if [ "$CHECK_TYPE" = "isoinfo" ]; then
-     isoinfo -d -i $cdrom_device | grep -i "Volume id:" | grep "$ID" \
-      > /dev/null 2>&1
-      media_lfs=$?
-      if [ $media_lfs -ne 0 ]; then
-        isoinfo -V $cdrom_device | grep "$ID" > /dev/null 2>&1
-        media_lfs=$?
-      fi
-    fi
-                                                                                
-    if [ "$CHECK_TYPE" = "try_mount" ]; then
-      umount -n $cdrom_device > /dev/null 2>&1
-    fi
-                                                                                
-    if [ $media_lfs -eq 0 ]; then
-      echo ", LFS boot CD found. Ready!"
-      LFS_CDROM_DEVICE="$cdrom_device"
-      break;
-    else
-      echo ", not LFS boot CD."
-    fi
-                                                                                
-  else
-    echo "no media "
-  fi
-done
-                                                                                
-                                                                                
-#3. mount LFS CD as / (root fs)
-if [ "$LFS_CDROM_DEVICE" = "" ]; then
-                                                                                
-  echo "No LFS boot CD found!!!"
-  exit 1
-                                                                                
-else
-                                                                                
-  echo "Booting from $LFS_CDROM_DEVICE ...                  "
-                                                    
-
-	# This is the magical part that makes a livecd live!
-	# The cd is mounted and pivot_root+chroot commands
-	# are used to start the system.
-	# If you really want to know what is going on here,
-	# You should read the chroot and pivot_root man pages                            
-  mount -n -o ro -t iso9660 $LFS_CDROM_DEVICE $TMP_MOUNT
-  cd $TMP_MOUNT
-  pivot_root . mnt
-  umount -n /mnt/proc >/dev/null 2>&1
-  exec chroot . sh -c 'umount -n /mnt >/dev/null 2>&1; exec -a init.new /sbin/init 3' <dev/console >dev/console 2>&1
-                                                                                
-EOF
-
---------------------------------------
-
-
-	To make this script executable run
-
-chmod 0755 $LIVECD/mnt/linuxrc
-
-	Ok, that's it. Unmount the image and compress it.
-
-cd $LIVECD/
-umount $LIVECD/mnt
-gzip $LIVECD/boot/initrd
-
-
-8. Burn the Boot CD
-   ----------------
-
-	If you have a CD-RW you should take this for testing. When
-	your system boots quite good from CD-RW you can burn it on a CD-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 -ch $LIVECD/ | grep total
-
-	Delete all the stuff you don't need on a Boot CD. (e.g. /usr/src/*)
-
-	Because linuxrc must be able to identify the CD you have to create a
-	file called "livecd". (unless you use isoinfo)
-
-touch $LIVECD/livecd
-
-	Now burn the LFS system on CD
-
-	Note!
-	dev=/dev/hdc is the device number of your CD-Writer
-	Check your SCSI devices with "cdrecord -scanbus"
-	( as of this writing scsi-emulation is no longer required)
-	speed=4 should be changed to (max) speed of your CD-Writer.
-	If you are not using a CD-RW remove blank=fast from the cdrecord-command!
-
-cd $LIVECD/
-mkisofs -R -l -L -D -b isolinux/isolinux.bin -o $ISODIR/livecd_image.iso -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -V "livecd" $LIVECD && 
-cdrecord -v -eject dev=/dev/hdc blank=fast $ISODIR/livecd_image.iso
-
-
-
-ACKNOWLEDGEMENTS:
-
-Thanks to:
-Thomas Foecking <thomas at foecking.de> and Christian Hesse <mail at earthworm.de>
-For writing the "Easy Boot CD of your LFS" hint which confused me so much
-when I tried it with udev that I decided to write this one =o)
-
-Feel free to email me comments, point out typos, etc. 
-
-CHANGELOG:
-[2004-07-24]
-  * Finally found the time to proofread and submit the hint;)
-[2004-05-19]
-  * Added environment variables for more flexibility
-[2004-05-17]
-  * Initial hint completed.


--------------------------------------------------------------------------------


  a.. Previous message: r881 - trunk 
  b.. Next message: r883 - trunk 
  c.. Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

--------------------------------------------------------------------------------
More information about the Hints mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-support/attachments/20050208/a66cd1db/attachment.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-support/attachments/20050208/a66cd1db/attachment.htm>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-support/attachments/20050208/a66cd1db/attachment-0001.htm>


More information about the lfs-support mailing list