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

335 lines
13 KiB
HTML

<title>Disks</title>
<h1>2 <a name="s2"> Disks </h1>
<p> <a href="Bootdisk-HOWTO.html#toc2"> Contents of this section</a></p>
<p></p>
<h2>2.1 <A Name="ss2.1"> Summary of Disk Types </h2>
<p>I classify boot-related disks into 4 types. The discussion here
and throughout this document uses the term "disk" to refer to
diskettes unless otherwise specified. Most of the discussion could
be equally well applied to hard disks. </p>
<p>A summary of disk types and uses is:
<dl>
<dt><b>boot</b><dd><p>A disk containing a kernel which can be booted. The disk
can contain a filesystem and use a boot loader to boot, or it can
simply contain the kernel only at the start of the disk.
The disk can be used to boot the kernel using a root
file system on another disk. This could be useful if you lost your
boot loader due to, for example, an incorrect installation attempt.</p>
<p></p>
<dt><b>root</b><dd><p>A disk with a file system containing everything
required to run a Linux system. It does not necessarily contain
either a kernel or a boot loader.</p>
<p>This disk can be used to run the system independently of any other
disks, once the kernel has been booted. A special kernel feature
allows a separate root disk to be mounted after booting, with the
root disk being automatically copied to a ramdisk.</p>
<p>You could use this type of disk to check another disk for corruption
without mounting it, or to restore another disk following disk failure or
loss of files.</p>
<p></p>
<dt><b>boot/root</b><dd><p>A disk which is the same as a root disk, but
contains a kernel and a boot loader. It can be used to boot from,
and to run the system. The advantage of this type of disk is
that is it compact - everything required is on a single disk.
However the gradually increasing size of everything means that
it won't necessarily always be possbile to fit everything on a single
diskette.</p>
<p></p>
<dt><b>utility</b><dd><p>A disk which contains a file system, but is not
intended to be mounted as a root file system. It is an additional
data disk. You would use this type of disk to carry additional
utilities where you have too much to fit on your root disk.</p>
<p>The term "utility" only really applies to diskettes, where you would
use a utility disk to store additional recovery utility software.</p>
</dl>
</p>
<p></p>
<h2>2.2 <A Name="ss2.2"> Boot </h2>
<p></p>
<h3> Overview </h3>
<p>All PC systems start the boot process by executing code in ROM to load
the sector from sector 0, cylinder 0 of the boot drive and try and
execute it. On most bootable disks, sector 0, cylinder 0 contains either:
<ul>
<li>code from a boot loader such as LILO, which locates the kernel,
loads it and executes it to start the boot proper.</li>
<li>the start of an operating system kernel, such as Linux.</li>
</ul>
</p>
<p>If a Linux kernel has been written to a diskette as a raw device,
then the first sector will be the first sector of the Linux kernel
itself, and this sector will continue the boot process by loading
the rest of the kernel and running Linux. For a more detailed
description of the boot sector contents, see the documentation
in lilo-01.5 or higher.</p>
<p>An alternative method of storing a kernel on a boot disk is to create
a filesystem, not as a root filesystem, but simply as a means of
installing LILO and thus allowing boot-time command line options
to be specified. For example, the same kernel could then be used
to boot using a hard disk root filesystem, or a diskette root
filesystem. This could be useful if you were trying to rebuild
the hard disk filesystem, and wanted to repeatedly test results.</p>
<p></p>
<h3> Setting Pointer to Root </h3>
<p>The kernel must somehow obtain a pointer to the drive and partititon to
be mounted as the root drive. This can be provided
in several ways:
<ul>
<li>By setting <code>ROOT_DEV = &lt;device&gt;</code> in the Linux kernel makefile
and rebuilding the kernel (for advice on how to rebuild the kernel,
read the Linux FAQ and look in <code>/usr/src/linux</code>). Comments in the
Linux makefile describe the valid values for <code>&lt;device&gt;</code>.</li>
<li>By running the rdev utility:
<blockquote><code>
<pre>
rdev &lt;filename&gt; &lt;device&gt;
</pre>
</code></blockquote>
This will set the root device of the kernel contained in <code>&lt;filename&gt;</code>
to be <code>&lt;device&gt;</code>. For example:
<blockquote><code>
<pre>
rdev Image /dev/sda1
</pre>
</code></blockquote>
This sets the root device in the kernel in Image to the first partition on
the first SCSI drive.</li>
</ul>
</p>
<p>There are some alternative ways of issuing the rdev command. Try:
<blockquote><code>
<pre>
rdev -?
</pre>
</code></blockquote>
</p>
<p>and it will display command usage.</p>
<p>There is usually no need to configure the root device for
boot diskette use, because the kernel currently used to boot from
probably already points to the root drive device. The need can
arise, howoever, if you obtain a kernel from another machine,
for example, from a distribution, or if you want to use the kernel
to boot a root diskette. It never hurts to check, though. To use
rdev to check the current root device in a kernel file, enter
the command:
<blockquote><code>
<pre>
rdev -r &lt;filename&gt;
</pre>
</code></blockquote>
</p>
<p>It is possible to change the root device set in a kernel by means other
than using rdev. For details, see the FAQ at the end of this document.</p>
<p></p>
<h3> Copying Kernel to Boot Diskette </h3>
<p>Once the kernel has been configured then it must be copied to the
boot diskette. </p>
<p>If the disk is not intended to contain a file system, then the kernel
must be copied using the dd command, as follows:
<blockquote><code>
<pre>
dd if=&lt;filename&gt; of=&lt;device&gt;
where &lt;filename&gt; is the name of the kernel
and &lt;device&gt; is the diskette raw device,
usually /dev/fd0
</pre>
</code></blockquote>
</p>
<p>The seek parameter to the dd command should NOT be used. The file
must be copied to start at the boot sector (sector 0, cylinder 0),
and omitting the seek parameter will do this.</p>
<p>The output device name varies. Many systems have <code>/dev/fd0</code> as an
alias of one sort or another for the "real" device name for the
default diskette drive. For example, where the default drive
(i.e. "drive A:" in DOS) is a high density 3 1/2 inch diskette
drive, the device name will be <code>/dev/fd0H1440</code>, but usually
<code>/dev/fd0</code> points to the same device.</p>
<p>Where the kernel is to be copied to a boot disk containing a filesystem,
then the disk is mounted at a suitable point in a currently-mounted
filesystem, then the cp command is used. For example:
<blockquote><code>
<pre>
mount -t ext2 /dev/fd0 /mnt
cp Image /mnt
umount /mnt
</pre>
</code></blockquote>
</p>
<p></p>
<h2>2.3 <A Name="ss2.3"> Root </h2>
<p></p>
<h3> Overview </h3>
<p>A root disk contains a complete working Linux system, but without
necessarily including a kernel. In other words, the disk may not
be bootable, but once the kernel is running, the root disk contains
everything needed to support a full Linux system. To be able to
do this, the disk must include the minimum requirements for a
Linux system:
<ul>
<li>File system.</li>
<li>Minimum set of directories - dev, proc, bin, etc, lib, usr, tmp.</li>
<li>Basic set of utilities - bash (to run a shell), ls, cp etc.</li>
<li>Minimum set of config files - rc, inittab, fstab etc.</li>
<li>Runtime library to provide basic functions used by utilities.</li>
</ul>
</p>
<p>Of course, any system only becomes useful when you can run something
on it, and a root diskette usually only becomes useful when you
can do something like:
<ul>
<li>Check a file system on another drive, for example to check
your root file system on your hard drive, you need to be
able to boot Linux from another drive, as you can with a
root diskette system. Then you can run fsck on your
original root drive while it is not mounted.</li>
<li>Restore all or part of your original root drive from backup
using archive/compression utilities including cpio, tar,
gzip and ftape.</li>
</ul>
</p>
<p></p>
<h2>2.4 <A Name="ss2.4"> Boot/Root </h2>
<p>This is essentially the same as the root disk, with the
addition of a kernel and a boot loader such as LILO.</p>
<p>With this configuration, a kernel file is copied to the root file
system, and LILO is then run to install a configuration which
points to the kernel file on the target disk. At boot time, LILO
will boot the kernel from the target disk.</p>
<p>Several files must be copied to the diskette for this method to
work. Details of these files and the required LILO configuration,
including a working sample, are given below in the section
titled "LILO".</p>
<p></p>
<h3> RAM Drives and Root Filesystems on Diskette </h3>
<p>For a diskette root filesystem to be efficient, you need to be able to run
it from a ramdrive, i.e. an emulated disk drive in main memory.
This avoids having the system run at a snail's pace, which a
diskette would impose.</p>
<p>There is an added benefit from using a ramdrive - the Linux kernel
includes an automatic ramdisk root feature, whereby it will, under
certain circumstances, automatically copy the contents of a
root diskette to a RAM disk, and then switch the root drive
to be the RAM disk instead of the diskette. This has two major
benefits:
<ul>
<li>The system runs a lot faster.</li>
<li>The diskette drive is freed up to allow other diskettes
to be used on a single-diskette drive system.</li>
</ul>
</p>
<p>The requirements for this feature to be invoked are:
<ul>
<li>The file system on the diskette drive must be either a minix
or an ext2 file system. The ext2 file system is generally the preferred
file system to use. Note that if you have a Linux kernel earlier
than 1.1.73, then you should see the comments in the section
below titled "File Systems" to see whether your kernel will
support ext2. If your kernel is old then you may have to use
minix. This will not cause any significant problems.</li>
<li>A RAM disk must be configured into the kernel, and it must
be at least as big as the diskette drive.</li>
</ul>
</p>
<p>A RAM disk can be configured into the kernel in several ways:
<ul>
<li>By uncommenting the RAMDISK macro in the Linux kernel
makefile, so that it reads:
<blockquote><code>
<pre>
RAMDISK = -DRAMDISK=1440
</pre>
</code></blockquote>
to define a ramdisk of 1440 1K blocks, the size of a
high-density diskette.</li>
<li>By running the rdev utility, available on most Linux
systems. This utility displays or sets values for several
things in the kernel, including the desired size for a
ramdisk. To configure a ramdisk of 1440 blocks into a
kernel in a file named Image, enter:
<blockquote><code>
<pre>
rdev -r Image 1440
</pre>
</code></blockquote>
this might change in the future, of course. To see what
your version of rdev does, enter the command:
<blockquote><code>
<pre>
rdev -?
</pre>
</code></blockquote>
and it should display its options.</li>
<li>By using the boot loader package LILO to configure it into
your kernel at boot time. This can be done using the
LILO configuration parameter:
<blockquote><code>
<pre>
ramdisk = 1440
</pre>
</code></blockquote>
to request a RAM drive of 1440 1K blocks at boot time.</li>
<li>By interrupting a LILO automatic boot and adding ramdisk=1440
to the command line. For example, such a command line might be:
<blockquote><code>
<pre>
vmlinux ramdisk=1440
</pre>
</code></blockquote>
See the section on LILO for more details.</li>
<li>By editing the kernel file and altering the values near the
start of the file which record the ramdisk size. This is definitely a
last resort, but can be done. See the FAQ near the end of this
document for more details.</li>
</ul>
</p>
<p>The easiest of these methods is LILO configuration, because you
need to set up a LILO configuration file anyway, so why not add the
ramdisk size here?</p>
<p>LILO configuration is briefly described in a section titled "LILO"
below, but it is advisable to obtain the latest stable version of
LILO from your nearest Linux mirror site, and read the documentation
that comes with it.</p>
<p></p>
<h2>2.5 <A Name="ss2.5"> Utility </h2>
<p>Often one disk is not sufficient to hold all the software you need
to be able to perform rescue functions of analysing, repairing and
restoring corrupted disk drives. By the time you include tar, gzip
e2fsck, fdisk, Ftape and so on, there is enough for a whole new
diskette, maybe even more if you want lots of tools.</p>
<p>This means that a rescue set often requires a utility diskette,
with a file system containing any extra files required. This file
system can then be mounted at a convenient point, such as /usr, on
the boot/root system.</p>
<p>Creating a file system is fairly easy, and is described above in
the section titled "File Systems" above. </p>
<p></p>
<p><a href="Bootdisk-HOWTO-3.html"> Next </a> Chapter, <a href="Bootdisk-HOWTO-1.html"> Previous </a> Chapter</p><p>Table of contents of <a href="Bootdisk-HOWTO.html#toc2">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>