| 1 |
AUTHOR: Alexander E. Patrakov <patrakov at ums dot usu dot ru> |
|---|
| 2 |
|
|---|
| 3 |
DATE: 2005-12-15 |
|---|
| 4 |
|
|---|
| 5 |
LICENSE: GNU General Public License, version 2 or later |
|---|
| 6 |
|
|---|
| 7 |
SYNOPSIS: Design and history of the official LFS LiveCD |
|---|
| 8 |
|
|---|
| 9 |
DESCRIPTION: |
|---|
| 10 |
This hint documents design choices made while developing |
|---|
| 11 |
the official LFS LiveCD. This is not a step-by-step guide. |
|---|
| 12 |
|
|---|
| 13 |
PREREQUISITES: |
|---|
| 14 |
Ability to build LFS and BLFS and script the build process |
|---|
| 15 |
Working knowledge of C, ability to read and understand documentation |
|---|
| 16 |
|
|---|
| 17 |
HINT: |
|---|
| 18 |
|
|---|
| 19 |
I. DIFFERENCES BETWEEN A LIVE CD AND A REGULAR SYSTEM |
|---|
| 20 |
|
|---|
| 21 |
Any Linux live CD contains a Linux system and a special boot loader designed |
|---|
| 22 |
for running it from a CD-ROM. The fact that the root file system is stored |
|---|
| 23 |
on a CD leads to the following consequences: |
|---|
| 24 |
|
|---|
| 25 |
1. The device which holds the system is not known in advance. |
|---|
| 26 |
|
|---|
| 27 |
Some people have their CD-ROM as /dev/hdc, others use /dev/hdd or even /dev/sr0. |
|---|
| 28 |
This means that one cannot pass a fixed "root=..." argument to the kernel |
|---|
| 29 |
in the boot loader configuration. |
|---|
| 30 |
|
|---|
| 31 |
2. The hardware on the target system is not known in advance. |
|---|
| 32 |
|
|---|
| 33 |
In order to be useful for building the LFS system, the official LiveCD must |
|---|
| 34 |
be able to boot from a CD drive connected to any IDE or SCSI controller and |
|---|
| 35 |
also recognize all hard disks in the target system. |
|---|
| 36 |
|
|---|
| 37 |
3. The CD is read-only. |
|---|
| 38 |
|
|---|
| 39 |
The iso9660 filesystem used on CD-ROMs is read-only. However, some programs |
|---|
| 40 |
require a writeable location to store their settings. Some mechanism must |
|---|
| 41 |
exist that provides such scratch space. |
|---|
| 42 |
|
|---|
| 43 |
4. The CD size is limited to 700 MB. |
|---|
| 44 |
|
|---|
| 45 |
A bare-bones LFS system takes approximately 300 megabytes, even after stripping. |
|---|
| 46 |
The official LFS LiveCD must also contain LFS sources, this takes 150 MB more. |
|---|
| 47 |
Thus, without compression, at most 250 megabytes are left for additional BLFS |
|---|
| 48 |
software that makes the CD more comfortable. |
|---|
| 49 |
|
|---|
| 50 |
5. The CD must be configurable in order to fit different user needs. |
|---|
| 51 |
|
|---|
| 52 |
When a user builds his [B]LFS system, he/she edits the configuration files |
|---|
| 53 |
according to personal requirements. Other user may be uncomfortable with |
|---|
| 54 |
the first user's settings. Thus, a live CD should contain some default |
|---|
| 55 |
settings that work for most people. Sometimes (e.g. when keyboard layouts |
|---|
| 56 |
are concerned) it is not possible. In such cases, an easy configuration |
|---|
| 57 |
mechanism should exist. |
|---|
| 58 |
|
|---|
| 59 |
The points outlined above are discussed in more detail in the next parts |
|---|
| 60 |
of the hint. |
|---|
| 61 |
|
|---|
| 62 |
II. The boot loader |
|---|
| 63 |
|
|---|
| 64 |
One of the boot loaders capable of booting a Linux kernel from a CD-ROM is |
|---|
| 65 |
isolinux, part of the Syslinux package. Syslinux is available at: |
|---|
| 66 |
|
|---|
| 67 |
http://syslinux.zytor.com/ |
|---|
| 68 |
|
|---|
| 69 |
The official LFS LiveCD uses a precompiled isolinux.bin file because some |
|---|
| 70 |
time ago the syslinux maintainer advised against recompiling syslinux from |
|---|
| 71 |
source. In order to build isolinux from source, nasm is needed. Issue the |
|---|
| 72 |
following commands to rebuild the isolinux.bin file: |
|---|
| 73 |
|
|---|
| 74 |
make spotless # removes all precompiled files |
|---|
| 75 |
make isolinux.bin # or just "make" if you want other programs in the package |
|---|
| 76 |
|
|---|
| 77 |
This "isolinux.bin" file should end up in the /boot/isolinux directory on the |
|---|
| 78 |
LiveCD, together with the isolinux.cfg configuration file, the kernel image |
|---|
| 79 |
("linux") and the initramfs image ("initramfs_data.cpio.gz", discussed in the |
|---|
| 80 |
next section). The isolinux.cfg file on the official LFS LiveCD contains the |
|---|
| 81 |
following: |
|---|
| 82 |
|
|---|
| 83 |
serial 0 |
|---|
| 84 |
default linux |
|---|
| 85 |
prompt 1 |
|---|
| 86 |
timeout 600 |
|---|
| 87 |
display boot.msg |
|---|
| 88 |
F1 options.msg |
|---|
| 89 |
|
|---|
| 90 |
label linux |
|---|
| 91 |
kernel linux |
|---|
| 92 |
append initrd=initramfs_data_cpio.gz |
|---|
| 93 |
|
|---|
| 94 |
The meaning of each configuration option is described in the syslinux.doc file |
|---|
| 95 |
in the syslinux source tarball. |
|---|
| 96 |
|
|---|
| 97 |
The initramfs performs detection of the CD-ROM device and mounts filesystems |
|---|
| 98 |
in such a way that a read-write filesystem is presented to the user. From |
|---|
| 99 |
the viewpoint of the boot loader, the initramfs image is just an initrd. |
|---|
| 100 |
The file name is passed as initramfs_data_cpio.gz, not initramfs_data.cpio.gz, |
|---|
| 101 |
because Syslinux understands only the bare ISO9660 filenames, not RockRidge |
|---|
| 102 |
extensions. To see bare ISO9660 filenames, issue the following command: |
|---|
| 103 |
|
|---|
| 104 |
mount -o norock,nojoliet /dev/cdrom /media/cdrom |
|---|
| 105 |
|
|---|
| 106 |
The timeout exists for unattended boot scenarios where the user is supposed to |
|---|
| 107 |
connect to his LiveCD system via ssh. This currently requires customizing the |
|---|
| 108 |
LiveCD, as described in the README file. Earlier, an attempt was made to start |
|---|
| 109 |
the ssh daemon automatically when the boot prompt times out, and change the |
|---|
| 110 |
root password to a well-known string. Such practice was insecure, and the |
|---|
| 111 |
old method of starting sshd has been dropped. |
|---|
| 112 |
|
|---|
| 113 |
III. Finding the root device. |
|---|
| 114 |
|
|---|
| 115 |
When the kernel boots, it realizes that the boot loader has passed something |
|---|
| 116 |
to it using the initrd protocol. The kernel looks at the contents of this image |
|---|
| 117 |
and checks whether it looks like a compressed cpio archive. For the official |
|---|
| 118 |
LFS LiveCD, this is the case, and the kernel unpacks this archive into the |
|---|
| 119 |
"ramfs" filesystem and uses it as a root filesystem. Then, the kernel checks |
|---|
| 120 |
whether the /init file exists and is executable. If it is not, the usual |
|---|
| 121 |
"root=..." argument parsing takes place. But the initramfs on the official |
|---|
| 122 |
LFS LiveCD contains /init, thus, the kernel executes it instead of parsing |
|---|
| 123 |
the non-existing "root=..." parameter. This /init file has to mount the |
|---|
| 124 |
real root file system and tell the kernel to use it. |
|---|
| 125 |
|
|---|
| 126 |
Currently, a statically-linked binary is used as the /init script, which makes |
|---|
| 127 |
it hard to explain what exactly is going on to people who don't know the C |
|---|
| 128 |
programming language. The source for this binary is kept in the |
|---|
| 129 |
lfs-livecd/initramfs directory. Earlier pre-releases of the LiveCD contained |
|---|
| 130 |
a number of small utilities statically linked against the "klibc" library |
|---|
| 131 |
(available from http://www.kernel.org/pub/linux/libs/klibc) instead of the |
|---|
| 132 |
usual glibc, and the /init file was a shell script. This practice has been |
|---|
| 133 |
dropped in favour of a statically linked glibc-based binary because klibc |
|---|
| 134 |
could not be built on some non-x86 architectures, like Sparc. |
|---|
| 135 |
|
|---|
| 136 |
Searching for the root device is the first thing done by /init. This is done |
|---|
| 137 |
by querying the ISO9660 volume label on each known device that could |
|---|
| 138 |
contain the LFS LiveCD. The static device nodes created when building the CD |
|---|
| 139 |
are used in initramfs. The shell-based /init used the following commands for |
|---|
| 140 |
searching the CD: |
|---|
| 141 |
|
|---|
| 142 |
LABEL="LFS_CD" |
|---|
| 143 |
DEVS=`echo /dev/hd* /dev/sr*` |
|---|
| 144 |
|
|---|
| 145 |
while [ -z "$CDROM" ] && [ "$TIMEOUT" != "..............." ] ; do |
|---|
| 146 |
for DEV in $DEVS ; do |
|---|
| 147 |
if [ "`isoinfo -V $DEV 2>/dev/null`" = "$LABEL" ] ; then |
|---|
| 148 |
CDROM=$DEV |
|---|
| 149 |
fi |
|---|
| 150 |
done |
|---|
| 151 |
if [ -z "$CDROM" ] ; then |
|---|
| 152 |
echo -n "." |
|---|
| 153 |
TIMEOUT=".$TIMEOUT" |
|---|
| 154 |
sleep 1 |
|---|
| 155 |
fi |
|---|
| 156 |
done |
|---|
| 157 |
|
|---|
| 158 |
The "isoinfo" program is available from |
|---|
| 159 |
ftp://metalab.unc.edu/pub/Linux/utils/disk-management/ |
|---|
| 160 |
|
|---|
| 161 |
In order to compile cleanly against klibc, it needs a patch: |
|---|
| 162 |
isoinfo-0.03.02-fixes-1.patch |
|---|
| 163 |
|
|---|
| 164 |
It is also possible to search for the CD by attempting to mount all devices |
|---|
| 165 |
and looking if one of them contains some file known to be present on the CD. |
|---|
| 166 |
|
|---|
| 167 |
The logic for retrying the CD-ROM detection is needed in the case of SCSI |
|---|
| 168 |
and USB CD-ROM drives, because the kernel performs their detection in the |
|---|
| 169 |
background, and it takes some time, and therefore the first round of CD-ROM |
|---|
| 170 |
detection may miss such devices. |
|---|
| 171 |
|
|---|
| 172 |
In the current C-based init, the corresponding logic is contained in the |
|---|
| 173 |
mountlfscd() function. |
|---|
| 174 |
|
|---|
| 175 |
When the device containing the LFS CD is found, the tmpfs filesystem is mouned |
|---|
| 176 |
onto the /.tmpfs directory, and the CD-ROM device it is mounted onto |
|---|
| 177 |
/.tmpfs/.cdrom. Note: this does not become the root filesystem. |
|---|
| 178 |
|
|---|
| 179 |
Such setup is needed in order to be able to access the sources present on |
|---|
| 180 |
the LiveCD, and will be explained later. |
|---|
| 181 |
|
|---|
| 182 |
CHANGELOG: |
|---|
| 183 |
{place the SVN changelog here just before the official release} |
|---|