The purpose of this rootf is to prepare the ramdisk to receive the
rootfs, to detect where the CD-ROM drive is and to launch the copy of the files
necessary to the construction of the rootfs. These are the files required for
the initrd creation:
.
|-- bin
| |-- bash
| |-- cat
| |-- cp
| |-- echo
| |-- findcd
| |-- mke2fs
| |-- mount
| |-- rm
| `-- umount
|-- cdrom
|-- dev
| |-- console
| |-- hda
| |-- hdb
| |-- hdc
| |-- hdd
| |-- null
| `-- ram1
|-- etc
| `-- mtab
|-- lib
| |-- ld-linux.so.2
| |-- libc.so.6
| |-- libcom_err.so.2
| |-- libcrypt.so.1
| |-- libdl.so.2
| |-- libe2p.so.2
| |-- libext2fs.so.2
| |-- libncurses.so.5
| `-- libuuid.so.1
|-- linuxrc
|-- proc
`-- ramdisk
Voici le détail
de ces fichiers :
.:
total 32
drwxr-xr-x 2 root root 4096 Aug 24 16:09 bin
drwxr-xr-x 2 root root 4096 Aug 21 12:31 cdrom
drwxr-xr-x 2 root root 4096 Aug 21 16:00 dev
drwxr-xr-x 2 root root 4096 Aug 21 15:48 etc
drwxr-xr-x 2 root root 4096 Aug 21 14:54 lib
-rwxr-xr-x 1 root root 1765 Aug 24 16:09 linuxrc
drwxr-xr-x 2 root root 4096 Aug 19 15:46 proc
drwxr-xr-x 2 root root 4096 Aug 21 12:29 ramdisk
./bin:
total 656
-rwxr-xr-x 1 root root 461400 Aug 19 16:39 bash
-rwxr-xr-x 1 root root 9668 Aug 19 15:56 cat
-rwxr-xr-x 1 root root 32272 Aug 23 14:47 cp
-rwxr-xr-x 1 root root 7148 Aug 19 15:56 echo
-rwxr-xr-x 1 root root 576 Aug 21 17:55 findcd
-rwxr-xr-x 1 root root 19536 Aug 21 12:36 mke2fs
-rwxr-xr-x 1 root root 65404 Aug 19 15:56 mount
-rwxr-xr-x 1 root root 20304 Aug 21 13:52 rm
-rwsr-xr-x 1 root root 36572 Aug 19 15:56 umount
./cdrom:
total 0
./dev:
total 0
crw-r--r-- 1 root root 4, 0 Aug 19 16:02 console
brw-r--r-- 1 root root 3, 0 Aug 19 16:02 hda
brw-r--r-- 1 root root 3, 64 Aug 19 16:02 hdb
brw-r--r-- 1 root root 22, 0 Aug 19 16:02 hdc
brw-r--r-- 1 root root 22, 64 Aug 19 16:02 hdd
crw-r--r-- 1 root root 1, 3 Aug 19 16:02 null
brw-r----- 1 root root 1, 1 Aug 21 16:00 ram1
./etc:
total 0
-rw-r--r-- 1 root root 0 Aug 21 15:48 mtab
./lib:
total 1332
-rwxr-xr-x 1 root root 83976 Aug 19 15:59
ld-linux.so.2
-rwxr-xr-x 1 root root 887712 Aug 19 15:59 libc.so.6
-rw-r--r-- 1 root root 5244 Aug 21 14:54
libcom_err.so.2
-rw-r--r-- 1 root root 20436 Aug 19 15:59
libcrypt.so.1
-rw-r--r-- 1 root root 9452 Aug 19 16:44 libdl.so.2
-rw-r--r-- 1 root root 12300 Aug 21 14:54 libe2p.so.2
-rw-r--r-- 1 root root 66000 Aug 21 14:54
libext2fs.so.2
-rw-r--r-- 1 root root 233816 Aug 19 16:41
libncurses.so.5
-rw-r--r-- 1 root root 7752 Aug 21 14:54 libuuid.so.1
./proc:
total 0
./ramdisk:
total 0
The files in the bin directory are binaries necessary to the linuxrc
execution. The files in the lib directory are the libraries used by the
programs in bin. To determine which libraries are necessary, we use ldd. The
files in dev are imput/output files necessary to linuxrc.
Here is the linuxrc script, it uses the bash located in bin:
#! /bin/bash
echo "Installation of the ramdisk"
/bin/mount -n
proc /proc -t proc
#mounting procfs for collection system information
echo "Proc FS mounted"
/bin/mke2fs /dev/ram1 65535
#ramdisk formating
echo "ramdisk formated"
/bin/mount -n -t ext2 /dev/ram1 /ramdisk
#we mount the ramdisk in the fs initrd
echo "Ramdisk mounted"
/bin/rm -Rf /ramdisk/lost+found
#deleting lost+found directory
echo "Ramdisk ready"
/bin/mount -n -t iso9660 /dev/$(/bin/findcd) /cdrom
#we mount the cd-rom detected by findcd
echo "CD-ROM mounted"
echo "Copying files in progress ..."
echo "Copying directory /bin ..."
/bin/cp -Rpd /cdrom/bin /ramdisk/
echo "Copying directory /boot ..."
/bin/cp -Rpd /cdrom/boot /ramdisk/
echo "Copying directory /cdrom ..."
/bin/cp -Rpd /cdrom/cdrom /ramdisk/
echo "Copying directory /dev ..."
/bin/cp -Rpd /cdrom/dev /ramdisk/
echo "Copying directory /etc ..."
/bin/cp -Rpd /cdrom/etc /ramdisk/
echo "Copying directory /floppy ..."
/bin/cp -Rpd /cdrom/floppy /ramdisk/
echo "Copying directory /home ..."
/bin/cp -Rpd /cdrom/home /ramdisk/
echo "Copying directory /initrd ..."
/bin/cp -Rpd /cdrom/initrd /ramdisk/
echo "Copying directory /lib ..."
/bin/cp -Rpd /cdrom/lib /ramdisk/
echo "Copying directory /mnt ..."
/bin/cp -Rpd /cdrom/mnt /ramdisk/
echo "Copying directory /proc ..."
/bin/cp -Rpd /cdrom/proc /ramdisk/
echo "Copying directory /root ..."
/bin/cp -Rpd /cdrom/root /ramdisk/
echo "Copying directory /sbin ..."
/bin/cp -Rpd /cdrom/sbin /ramdisk/
echo "Copying directory /tmp ..."
/bin/cp -Rpd /cdrom/tmp /ramdisk/
echo "Copying directory /usr ..."
/bin/cp -Rpd /cdrom/usr /ramdisk/
echo "Copying directory /var ..."
/bin/cp -Rpd /cdrom/var /ramdisk/
echo "... Files copied"
#Copy of the files on the rootfs
/bin/umount /cdrom
#Unmounting CD-ROM
echo "CD-ROM démonté"
/bin/umount /ramdisk
#Unmounting ramdisk
echo "Ramdisk unmounted"
echo "257" > /proc/sys/kernel/real-root-dev
#We specify the new rootfs
#the number 257 is calculated from the minor and the major of the
peripheral
#under the 0xminmaj form and converted to decimal
/bin/umount /proc
#We unmount the proc fs
This script works thanks to another bash script that allows CD-ROM
detection. This script uses the data in /proc to determine where the CD-ROM is.
Here is the script:
#! /bin/bash
function returnhda
{
if [ $(cat /proc/ide/ide0/hda/media) = "cdrom" ]
then echo "hda"
fi
}
function returnhdb
{
if [ $(cat /proc/ide/ide0/hdb/media) = "cdrom" ]
then echo "hdb"
fi
}
function returnhdc
{
if [ $(cat /proc/ide/ide1/hdc/media) = "cdrom" ]
then echo "hdc"
fi
}
function returnhdd
{
if [ $(cat /proc/ide/ide1/hdd/media) = "cdrom" ]
then echo "hdd"
fi
}
test -e /proc/ide/ide0/hda/media && returnhda
test -e /proc/ide/ide0/hdb/media && returnhdb
test -e /proc/ide/ide1/hdc/media && returnhdc
test -e /proc/ide/ide1/hdd/media && returnhdd
This script performs tests in the /proc directory in order to
determine where the CD-ROM drive is. Once these tests have been performed, is
sends the CD-ROM drive’s ID so that the linuxrc script can mount it and copy
the necessary files.
We now need to create and image of this initrd. Let us start by
creating a 2MB ram file system and mount it:
#mke2fs /dev/ram 2048
#mount /dev/ram /mnt
We can now copy the files needed with the –Rvpd option in order to
keep the permissions of the copied files. We suppose that the previous files
are in /backup_initrd .
#cp –Rvpd
./backup_initrd/* /mnt
We now need to create an image of this file system. We use the dd
tool with the following syntax:
#dd if=/dev/ram bs=1k count=2048 | gzip –v9 > initrd.gz
On remarque que
l’image a été compressé afin d’occuper le moins de place possible.
The image has been compressed to reduce its size. Nous allons
maintenant pouvoir passer à la réalisation de l’étape suivante de la
distribution, la création du bootfs.
We can now copy the initial ramdisk image (intitrd.gz) in the boot directory
of our LFS system. We will use LILO to copy the boot sector of the floppy disk.
This is our lilo.conf file that we named mdlilo.conf:
boot =/dev/fd0
install =/boot/boot.b
map =/boot/map
read-write
backup =/dev/null
compact
image = kernel
label = ramd
initrd = /boot/initrd.gz
We have specified the initrd. Although the distribution is on a
bootable CD-ROM, we specify that the boot peripheral is /dev/fd0 to respect the
emulation system.
In order to create the boot disk that we will use to produce our
CD-ROM image, we have to use a true floppy disk and create its image. We start
by formatting a floppy disk in the /dev/fd0 drive:
#mke2fs /dev/fd0 1440
We mount the floppy disk :
#mount /dev/fd0 /floppy
We copy the necessary files that we have previously created in
/backup_bootfs :
#cp –Rvpd . /backup_bootfs/* /floppy
Once the floppy disk created, we make it bootable using a specific
LILO command :
#lilo –v –C mdlilo.conf –r /floppy
This command uses the mdlilo.conf file to write the floppy disk boot
sector of the floppy mounted on /floppy.
We now need to create an image of this floppy disk using the dd
tool, we will call it bootfs.img:
#dd if=/dev/fd0 of=bootfs.img bs=10k count=144