Files
oldlinux-files/study/boot/Bootdisk-HOWTO/bootdisk-howto-v101/bootdisk-HOWTO-3.html
2024-02-19 00:25:23 -05:00

472 lines
18 KiB
HTML

<title>Components</title>
<h1>3 <a name="s3"> Components </h1>
<p> <a href="Bootdisk-HOWTO.html#toc3"> Contents of this section</a></p>
<p></p>
<h2>3.1 <A Name="ss3.1"> File Systems </h2>
<p>The Linux kernel now supports two file system types for root
disks to be automatically copied to ramdisk. These are minix
and ext2, of which ext2 is the preferred file system.
The ext2 support was added sometime between 1.1.17 and 1.1.57,
I'm not sure exactly which. If you have a kernel within this range
then edit /usr/src/linux/drivers/block/ramdisk.c and look for the
word "ext2". If it is not found, then you will have to use a minix
file system, and therefore the "mkfs" command to create it.</p>
<p>To create an ext2 file system on a diskette on my system, I issue the
following command:
<blockquote><code>
<pre>
mke2fs /dev/fd0
</pre>
</code></blockquote>
</p>
<p>The mke2fs command will automatically detect the space available and
configure itself accordingly. It does not therefore require any
parameters.</p>
<p>An easy way to test the result is to create a system using the above
command or similar, and then attempt to mount the diskette. If it is
an ext2 system, then the command:
<blockquote><code>
<pre>
mount -t ext2 /dev/fd0 /&lt;mount point&gt;
</pre>
</code></blockquote>
should work.</p>
<p></p>
<h2>3.2 <A Name="ss3.2"> Kernel </h2>
<p></p>
<h3> Building a Custom Kernel </h3>
<p>In most cases it would be possible to copy your current kernel and
boot the diskette from that. However there may be cases where you
wish to build a separate one.</p>
<p>One reason is size. The kernel is one of the
largest files in a minimum system, so if you want to build a
boot/root diskette, then you will have to reduce the size of the kernel
as much as possible. The kernel now supports changing
the diskette after booting and before mounting root, so it is not
necessary any more to squeeze the kernel into the same disk as
everything else, therefore these comments apply only if you choose
to build a boot/root diskette.</p>
<p>There are two ways of reducing kernel size:
<ul>
<li>Building it with the minumum set of facilities necessary
to support the desired system. This means leaving out
everything you don't need. Networking is a good thing to
leave out, as well as support for any disk drives and
other devices which you don't need when running your
boot/root system.</li>
<li>Compressing it, using the standard compressed-kernel
option included in the makefile:
<blockquote><code>
<pre>
make zImage
</pre>
</code></blockquote>
Refer to the documentation included with the kernel source
for up-to-date information on building compressed kernels.
Note that the kernel source is usually in /usr/src/linux.</li>
</ul>
</p>
<p>Having worked out a minimum set of facilities to include in a kernel,
you then need to work out what to add back in. Probably the most
common uses for a boot/root diskette system would be to examine
and restore a corrupted root file system, and to do this you may
need kernel support.</p>
<p>For example, if your backups are all held on tape using Ftape to
access your tape drive, then, if you lose your current root drive
and drives containing Ftape, then you will not be able to restore
from your backup tapes. You will have to reinstall Linux, download
and reinstall Ftape, and then try and read your backups.</p>
<p>It is probably desirable to maintain a copy of the same version
of backup utilities used to write the backups, so that you don't
waste time trying to install versions that cannot read your
backup tapes.</p>
<p>The point here is that, whatever I/O support you have added to
your kernel to support backups should also be added into your
boot/root kernel. Note, though, that the Ftape module (or at least
the one I have) is quite large and will not fit on your boot/root
diskette. You will need to put it on a utility diskette - this
is described below in the section titled "ADDING UTILITY DISKETTES".</p>
<p>The procedure for actually building the kernel is described in
the documentation that comes with the kernel. It is quite easy to
follow, so start by looking in /usr/src/linux. Note that if you
have trouble building a kernel, then you should probably not
attempt to build boot/root systems anyway.</p>
<p></p>
<h2>3.3 <A Name="ss3.3"> Devices </h2>
<p>A /dev directory containing a special file for all devices to be
used by the system is mandatory for any Linux system. The
directory itself is a normal directory, and can be created with
the mkdir command in the normal way. The device special files,
however, must be created in a special way, using the mknod command.</p>
<p>There is a shortcut, though - copy your existing /dev directory
contents, and delete the ones you don't want. The only requirement
is that you copy the device special files using the -R option. This
will copy the directory without attempting to copy the contents of the
files. Note that if you use lower caser, as in "-r", there will be
a vast difference, because you will probably end up copying the
entire contents of all of your hard disks - or at least as much
of them as will fit on a diskette! Therefore, take care, and use
the command:
<blockquote><code>
<pre>
cp -dpR /dev /mnt
</pre>
</code></blockquote>
assuming that the diskette is mounted at /mnt. The dp switches
ensure that symbolic links are copied as links (rather than
the target file being copied) and that the original file attributes
are preserved, thus preserving ownership information.</p>
<p>If you want to do it the hard way, use ls -l to display the major
and minor device numbers for the devices you want, and create
them on the diskette using mknod.</p>
<p>Many distributions include a shell script called MAKEDEV in the
/dev directory. This shell script could be used to create the devices,
but it is probably easier to just copy your existing ones, especially
for rescue disk purposes.</p>
<p></p>
<h2>3.4 <A Name="ss3.4"> Directories </h2>
<p>It might be possible to get away with just /dev, /proc and /etc to run
a Linux system. I don't know - I've never tested it. However a
reasonable minimum set of directories consists of the following:
<dl>
<dt><b>/dev</b><dd><p>Required to perform I/O with devices</p>
<dt><b>/proc</b><dd><p>Required by the ps command</p>
<dt><b>/etc</b><dd><p>System configuration files</p>
<dt><b>/bin</b><dd><p>Utility executables considered part of the system</p>
<dt><b>/lib</b><dd><p>Shared libraries to provide run-time support</p>
<dt><b>/mnt</b><dd><p>A mount point for maintenance on other disks</p>
<dt><b>/usr</b><dd><p>Additional utilities and applications</p>
</dl>
</p>
<p>Note that the directory tree presented here is for root diskette use only.
Refer to the Linux File System Standard for much better information
on how file systems should be structured in "standard" Linux
systems.</p>
<p>Four of these directories can be created very easily:
<ul>
<li>/dev is described above in the section titled DEVICES.</li>
<li>/proc only needs to exist. Once the directory is created using
mkdir, nothing more is required.</li>
<li>Of the others, /mnt and /usr are included in this list only as
mount points for use after the boot/root system is running.
Hence again, these directories only need to be created.</li>
</ul>
</p>
<p>The remaining 3 directories are described in the following sections.</p>
<p></p>
<h3> /etc </h3>
<p>This directory must contain a number of configuration files. On most
systems, these can be divided into 3 groups:
<ul>
<li>Required at all times, e.g. rc, fstab, passwd.</li>
<li>May be required, but no-one is too sure.</li>
<li>Junk that crept in. </li>
</ul>
</p>
<p>Files which are not essential can be identified with the command:
<blockquote><code>
<pre>
ls -ltru
</pre>
</code></blockquote>
This lists files in reverse order of date last accessed, so if any
files are not being accessed, then they can be omitted from a root
diskette.</p>
<p>On my root diskettes, I have the number of config files down to
15. This reduces my work to dealing with three sets of files:
<ul>
<li>The ones I must configure for a boot/root system:
<blockquote><code>
<pre>
rc system startup script
fstab list of file systems to be mounted
inittab parameters for the init process - the
first process started at boot time.
</pre>
</code></blockquote>
</li>
<li>the ones I should tidy up for a boot/root system:
<blockquote><code>
<pre>
passwd list of logins
shadow contains passwords
</pre>
</code></blockquote>
These should be pruned on secure systems to avoid copying
user's passwords off the system, and so that when you boot
from diskette, unwanted logins are rejected.</li>
<li>The rest. They work at the moment, so I leave them alone.</li>
</ul>
</p>
<p>Out of this, I only really have to configure two files, and what they
should contain is suprisingly small.
<ul>
<li>rc should contain:
<blockquote><code>
<pre>
#!/bin/sh
/etc/mount -av
/bin/hostname boot_root
</pre>
</code></blockquote>
and I don't really need to run hostname - it just looks nicer
if I do. Even mount is actually only needed to mount /proc to
support the ps command - Linux will run without it.</li>
<li>fstab should contain:
<blockquote><code>
<pre>
/dev/fd0 / ext2 defaults
/proc /proc proc defaults
</pre>
</code></blockquote>
I don't think that the first entry is really needed, but I
find that if I leave it out, mount won't mount /proc.</li>
</ul>
</p>
<p>Inittab should be ok as is, unless you want to ensure that users on
serial ports cannot login. To prevent this, comment out all the entries
for /etc/getty which include a ttys or ttyS device at the end of the line.
Leave in the tty ports so that you can login at the console.</p>
<p>For the rest, just copy all the text files in your /etc directory, plus
all the executables in your /etc directory that you cannot be sure you
do not need. As a guide, consult the sample ls listing in
"Sample Boot/Root ls-lR Directory Listing" -
this is what I have, so probably it will be sufficient for you if
you copy only those files.</p>
<p></p>
<h3> /bin </h3>
<p>Here is a convenient point to place the extra utilities you need to
perform basic operations, utilities such as ls, mv, cat, dd etc.</p>
<p>See the section titled "Sample Boot/Root ls-lR Directory Listing"
for the list of files that I place in my boot/root /bin
directory. You may notice that it does not include any of the utilities
required to restore from backup, such as
cpio, tar, gzip etc. That is because I place these on a separate
utility diskette, to save space on the boot/root diskette. Once I
have booted my boot/root diskette, it then copies itself to the ramdisk
leaving the diskette drive free to mount another diskette, the utility
diskette. I usually mount this as /usr.</p>
<p>Creation of a utility diskette is described below in the section
titled "Adding Utility Diskettes".</p>
<p></p>
<h3> /lib </h3>
<p>Two libraries are required to run many facilities under Linux:
<ul>
<li>ld.so</li>
<li>libc.so.4</li>
</ul>
</p>
<p>If they are not found in your /lib directory then the system will
be unable to boot. If you're lucky you may see an error message
telling you why.</p>
<p>These should be present in you existing /lib directory. Note that
libc.so.4 may be a symlink to a libc library with version number
in the filename. If you issue the command:
<blockquote><code>
<pre>
ls -l /lib
</pre>
</code></blockquote>
you will see something like:
<blockquote><code>
<pre>
libc.so.4 -&gt; libc.so.4.5.21
</pre>
</code></blockquote>
</p>
<p>In this case, the libc library you want is libc.so.4.5.21.</p>
<p></p>
<h2>3.5 <A Name="ss3.5"> LILO </h2>
<p></p>
<h3> Overview </h3>
<p>For the boot/root to be any use, it must be bootable. To achieve this,
the easiest way (possibly the only way?) is to install a boot loader,
which is a piece of executable code stored at sector 0, cylinder 0 of
the diskette. See the section above titled "BOOT DISKETTE" for an
overview of the boot process.</p>
<p>LILO is a tried and trusted boot loader available from any Linux
mirror site. It allows you to configure the boot loader, including:
<ul>
<li>Which device is to be mounted as the root drive.</li>
<li>Whether to use a ramdisk.</li>
</ul>
</p>
<p></p>
<h3> Sample LILO Configuration </h3>
<p>This provides a very convenient place to specify to the kernel how
it should boot. My root/boot LILO configuration file, used with
LILO 0.15, is:
<blockquote><code>
<hr>
<pre>
boot = /dev/fd0
install = ./mnt/boot.b
map = ./mnt/lilo.map
delay = 50
message = ./mnt/lilo.msg
timeout = 150
compact
image = ./mnt/vmlinux
ramdisk = 1440
root = /dev/fd0
</pre>
<hr>
</code></blockquote>
</p>
<p>Note that boot.b, lilo.msg and the kernel must first have been copied to
the diskette using a command similar to:
<blockquote><code>
<hr>
<pre>
cp /boot/boot.b ./mnt
</pre>
<hr>
</code></blockquote>
</p>
<p>If this is not done, then LILO will not run correctly at boot time if
the hard disk is not available, and there is little point setting up
a rescue disk which requires a hard disk in order to boot.</p>
<p>I run lilo using the command:
<blockquote><code>
<pre>
/sbin/lilo -C &lt;configfile&gt;
</pre>
</code></blockquote>
</p>
<p>I run it from the directory containing the mnt directory where I have
mounted the diskette. This means that I am telling LILO to install a
boot loader on the boot device (/dev/fd0 in this case), to boot a
kernel in the root directory of the diskette.</p>
<p>I have also specified that I want the root device to be the diskette,
and I want a RAM disk created of 1440 1K blocks, the same size as the
diskette. Since I have created an ext2 file system on the diskette,
this completes all the conditions required for Linux to automatically
switch the root device to the ramdisk, and copy the diskette contents
there as well.</p>
<p>The ramdisk features of Linux are described further in the section
above titled "RAM DRIVES AND BOOT/ROOT SYSTEMS".</p>
<p>It is also worth considering using the "single" parameter to cause
Linux to boot in single-user mode. This could be useful to prevent
users logging in on serial ports.</p>
<p>I also use the "DELAY" "MESSAGE" and "TIMEOUT" statements so
that when I boot the disk, LILO will give me the opportunity to
enter command line options if I wish. I don't need them at present,
but I never know when I might want to set a different root device
or mount a filesystem read-only.</p>
<p>The message file I use contains the message:</p>
<p>
<blockquote><code>
<pre>
Linux Boot/Root Diskette
========================
Enter a command line of the form:
vmlinux [ command-line options]
If nothing is entered, linux will be loaded with
defaults after 15 seconds.
</pre>
</code></blockquote>
</p>
<p>This is simply a reminder to myself what my choices are.</p>
<p>Readers are urged to read the LILO documentation carefully before
atttempting to install anything. It is relatively easy to destroy
partitions if you use the wrong "boot = " parameter. If you are
inexperienced, do NOT run LILO until you are sure you understand it
and you have triple-checked your parameters.</p>
<p></p>
<h3> Removing LILO </h3>
<p>One other thing I might as well add here while I'm on the LILO topic:
if you mess up lilo on a drive containing DOS, you can always replace
the boot sector with the DOS boot loader by issuing the DOS command:
<blockquote><code>
<pre>
FDISK /MBR
</pre>
</code></blockquote>
</p>
<p>where MBR stands for "Master Boot Record". Note that some purists
disagree with this, and they may have grounds, but it works.</p>
<p></p>
<h3> Useful LILO Options </h3>
<p></p>
<p>LILO has several useful options which are worth keeping in mind when
building boot disks:
<ul>
<li>Command line options - you can enter command line options
to set the root device, ramdrive size, special device parameters, or
other things. If you include the DELAY = nn statement in your LILO
configuration file, then LILO will pause to allow you to select
a kernel image to boot, and to enter, on the same line, any options.
For example:
<blockquote><code>
<pre>
vmlinux aha152x=0x340,11,3,1 ro
</pre>
</code></blockquote>
will pass the aha152x parameters through to the aha152x scsi disk
driver (provided that driver has been included when the kernel was
built) and will ask for the root filesystem to be mounted read-only.</li>
<li>Command line "lock" option - this option asks LILO to store
the command line entered as the default command line to be used for
all future boots. This is particularly useful where you have a device
which cannot be autoselected. By using "lock" you can avoid having
to type in the device parameter string every time you boot.
For example:
<blockquote><code>
<pre>
vmlinux aha152x=0x340,11,3,1 root=/dev/sda8 ro lock
</pre>
</code></blockquote>
</li>
<li>APPEND configuration statement - this allows device parameter
strings to be stored in the configuration, as an alternative to
using the "lock" command line option. Note that any keywords of
the form word=value MUST be enclosed in quotes. For example:
<blockquote><code>
<pre>
APPEND = "aha152x=0x340,11,3,1"
</pre>
</code></blockquote>
</li>
<li>DELAY configuration statement - this pauses for DELAY tenths
of seconds and allows the user to interrupt the automatic boot of
the default command line, so that the user can enter an alternate
command line.</li>
</ul>
</p>
<p></p>
<p><a href="Bootdisk-HOWTO-4.html"> Next </a> Chapter, <a href="Bootdisk-HOWTO-2.html"> Previous </a> Chapter</p><p>Table of contents of <a href="Bootdisk-HOWTO.html#toc3">this chapter</a>,
General <a href="Bootdisk-HOWTO.html#toc">table of contents</a></p>
<p><a href="Bootdisk-HOWTO.html"> Top </a> of the document,
<a href="#0"> Beginning of this Chapter</a></p>