从Lilo软件包的 README 中拷贝出来的,大致描述了通用计算机的引导过程。
Introduction
============
The following sections describe how PCs boot in general and what has to be
known when booting Linux and using LILO in particular.
Disk organization
-----------------
When designing a boot concept, it is important to understand some of the
subtleties of how PCs typically organize disks. The most simple case are
floppy disks. They consist of a boot sector, some administrative data (FAT
or super block, etc.) and the data area. Because that administrative data
is irrelevant as far as booting is concerned, it is regarded as part of the
data area for simplicity.
+---------------------------+
|Boot sector| |
|-----------+ |
| |
| Data area |
| |
| |
+---------------------------+
The entire disk appears as one device (e.g. /dev/fd0) on Linux.
The MS-DOS boot sector has the following structure:
+------------------------+
0x000 |Jump to the program code|
|------------------------|
0x003 | |
| Disk parameters |
| |
|------------------------|
0x02C/0x03E | |
| Program code |
| |
| |
|------------------------|
0x1FE | Magic number (0xAA55) |
+------------------------+
LILO uses a similar boot sector, but it does not contain the disk
parameters part. This is no problem for Minix, Ext2 or similar file
systems, because they don't look at the boot sector, but putting a LILO
boot sector on an MS-DOS file system would make it inaccessible for MS-DOS.
Hard disks are organized in a more complex way than floppy disks. They
contain several data areas called partitions. Up to four so-called primary
partitions can exist on an MS-DOS hard disk. If more partitions are needed,
one primary partition is used as an extended partition that contains
several logical partitions.
The first sector of each hard disk contains a partition table, and an
extended partition and _each_ logical partition contains a partition table
too.
+--------------------------------------------+
| Partition table /dev/hda |
| +------------------------------------------|
| | Partition 1 /dev/hda1 |
| | |
| |------------------------------------------|
| | Partition 2 /dev/hda2 |
| | |
+--------------------------------------------+
The entire disk can be accessed as /dev/hda, /dev/hdb, /dev/sda, etc. The
primary partitions are /dev/hda1 ... /dev/hda4.
+--------------------------------------------+
| Partition table /dev/hda |
| +------------------------------------------|
| | Partition 1 /dev/hda1 |
| | |
| |------------------------------------------|
| | Partition 2 /dev/hda2 |
| | |
| |------------------------------------------|
| | Extended partition /dev/hda3 |
| | +----------------------------------------|
| | | Extended partition table |
| | |----------------------------------------|
| | | Partition 3 /dev/hda5 |
| | | |
| | |----------------------------------------|
| | | Extended partition table |
| | |----------------------------------------|
| | | Partition 4 /dev/hda6 |
| | | |
+--------------------------------------------+
This hard disk has two primary partitions and an extended partition that
contains two logical partitions. They are accessed as /dev/hda5 ...
Note that the partition tables of logical partitions are not accessible as
the first blocks of some devices, while the main partition table, all boot
sectors and the partition tables of extended partitions are.
Partition tables are stored in partition boot sectors. Normally, only the
partition boot sector of the entire disk is used as a boot sector. It is
also frequently called the master boot record (MBR). Its structure is as
follows:
+------------------------+
0x000 | |
| Program code |
| |
| |
|------------------------|
0x1BE | Partition table |
| |
|------------------------|
0x1FE | Magic number (0xAA55) |
+------------------------+
The LILO boot sector is designed to be usable as a partition boot sector.
(I.e. there is room for the partition table.) Therefore, the LILO boot
sector can be stored at the following locations:
- boot sector of a Linux floppy disk. (/dev/fd0, ...)
- MBR of the first hard disk. (/dev/hda, /dev/sda, ...)
- boot sector of a primary Linux file system partition on the first hard
disk. (/dev/hda1, ...)
- partition boot sector of an extended partition on the first hard disk.
(/dev/hda1, ...)*
* Most FDISK-type programs don't believe in booting from an extended
partition and refuse to activate it. LILO is accompanied by a simple
program (activate) that doesn't have this restriction. Linux fdisk also
supports activating extended partitions.
It _can't_ be stored at any of the following locations:
- boot sector of a non-Linux floppy disk or primary partition.
- a Linux swap partition.
- boot sector of a logical partition in an extended partition.*
- on the second hard disk. (Unless for backup installations, if the
current first disk will be removed or disabled, or if some other boot
loader is used, that is capable of loading boot sectors from other
drives.)
* LILO can be forced to put the boot sector on such a partition by using
the -b option or the BOOT variable. However, only few programs that
operate as master boot records support booting from a logical
partition.
Although LILO tries to detect attempts to put its boot sector at an invalid
location, you should not rely on that.
Booting basics
--------------
When booting from a floppy disk, the first sector of the disk, the
so-called boot sector, is loaded. That boot sector contains a small program
that loads the respective operating system. MS-DOS boot sectors also
contain a data area, where disk and file system parameters (cluster size,
number of sectors, number of heads, etc.) are stored.
When booting from a hard disk, the very first sector of that disk, the
so-called master boot record (MBR) is loaded. This sector contains a loader
program and the partition table of the disk. The loader program usually
loads the boot sector, as if the system was booting from a floppy.
Note that there is no functional difference between the MBR and the boot
sector other than that the MBR contains the partition information but
doesn't contain any file system-specific information (e.g. MS-DOS disk
parameters).
The first 446 (0x1BE) bytes of the MBR are used by the loader program. They
are followed by the partition table, with a length of 64 (0x40) bytes. The
last two bytes contain a magic number that is sometimes used to verify that
a given sector really is a boot sector.
There is a large number of possible boot configurations. The most common
ones are described in the following sections.
MS-DOS alone
- - - - - -
+-------------------------------------------------------+
| Master Boot Record Boot sector Operating system |
|-------------------------------------------------------|
| DOS-MBR ------------> MS-DOS ------> COMMAND.COM |
+-------------------------------------------------------+
This is what usually happens when MS-DOS boots from a hard disk: the
DOS-MBR determines the active partition and loads the MS-DOS boot sector.
This boot sector loads MS-DOS and finally passes control to COMMAND.COM.
(This is greatly simplified.)
LOADLIN
- - - -
+------------------------------------------------------------+
| Master Boot Record Boot sector Operating system |
|------------------------------------------------------------|
| DOS-MBR ------------> MS-DOS ------> COMMAND.COM |
| ---> LOADLIN ------> Linux |
+------------------------------------------------------------+
A typical LOADLIN setup: everything happens like when booting MS-DOS, but
in CONFIG.SYS or AUTOEXEC.BAT, LOADLIN is invoked. Typically, a program
like BOOT.SYS is used to choose among configuration sections in CONFIG.SYS
and AUTOEXEC.BAT. This approach has the pleasant property that no boot
sectors have to be altered.
Please refer to the documentation accompanying the LOADLIN package for
installation instructions and further details.
LILO started by DOS-MBR
- - - - - - - - - - - -
+-------------------------------------------------------+
| Master Boot Record Boot sector Operating system |
|-------------------------------------------------------|
| DOS-MBR ------------> LILO --------> Linux |
| ---> other OS |
+-------------------------------------------------------+
This is a "safe" LILO setup: LILO is booted by the DOS-MBR. No other boot
sectors have to be touched. If the other OS (or one of them, if there are
several other operating systems being used) should be booted without using
LILO, the other partition has to be marked "active" with fdisk or activate.
Installation:
- install LILO with its boot sector on the Linux partition.
- use fdisk or activate to make that partition active.
- reboot.
Deinstallation:
- make a different partition active.
- install whatever should replace LILO and/or Linux.
Several alternate branches
- - - - - - - - - - - - -
+------------------------------------------------------------+
| Master Boot Record Boot sector Operating system |
|------------------------------------------------------------|
| DOS-MBR ------------> MS-DOS ------> COMMAND.COM |
| ---> LOADLIN ------> Linux |
| ---> LILO --------> Linux |
| ---> MS-DOS --- ... |
+------------------------------------------------------------+
An extended form of the above setup: the MBR is not changed and both
branches can either boot Linux or MS-DOS. (LILO could also boot other
operating systems.)
LILO started by BOOTACTV*
- - - - - - - - - - - - -
* Other, possibly better known boot switchers, e.g. OS/2 BootManager
operate in a similar way. The installation procedures typically vary.
+-------------------------------------------------------+
| Master Boot Record Boot sector Operating system |
|-------------------------------------------------------|
| BOOTACTV -----------> LILO --------> Linux |
| ---> other OS |
+-------------------------------------------------------+
Here, the MBR is replaced by BOOTACTV (or any other interactive boot
partition selector) and the choice between Linux and the other operating
system(s) can be made at boot time. This approach should be used if LILO
fails to boot the other operating system(s).*
* And the author would like to be notified if booting the other
operating system(s) doesn't work with LILO, but if it works with an
other boot partition selector.
Installation:
- boot Linux.
- make a backup copy of your MBR on a floppy disk, e.g.
dd if=/dev/hda of=/fd/MBR bs=512 count=1
- install LILO with the boot sector on the Linux partition.
- install BOOTACTV as the MBR, e.g.
dd if=bootactv.bin of=/dev/hda bs=446 count=1
- reboot.
Deinstallation:
- boot Linux.
- restore the old MBR, e.g.
dd if=/MBR of=/dev/hda bs=446 count=1
or FDISK /MBR under MS-DOS.
If replacing the MBR appears undesirable and if a second Linux partition
exists (e.g. /usr, _not_ a swap partition), BOOTACTV can be merged with the
partition table and stored as the "boot sector" of that partition. Then,
the partition can be marked active to be booted by the DOS-MBR.
Example:
# dd if=/dev/hda of=/dev/hda3 bs=512 count=1
# dd if=bootactv.bin of=/dev/hda3 bs=446 count=1
_WARNING:_ Whenever the disk is re-partitioned, the merged boot sector on
that "spare" Linux partition has to be updated too.
LILO alone
- - - - -
+----------------------------------------+
| Master Boot Record Operating system |
|----------------------------------------|
| LILO ---------------> Linux |
| ---> other OS |
+----------------------------------------+
LILO can also take over the entire boot procedure. If installed as the MBR,
LILO is responsible for either booting Linux or any other OS. This approach
has the disadvantage, that the old MBR is overwritten and has to be
restored (either from a backup copy, with FDISK /MBR on recent versions of
MS-DOS or by overwriting it with something like BOOTACTV) if Linux should
ever be removed from the system.
You should verify that LILO is able to boot your other operating system(s)
before relying on this method.
Installation:
- boot Linux.
- make a backup copy of your MBR on a floppy disk, e.g.
dd if=/dev/hda of=/fd/MBR bs=512 count=1
- install LILO with its boot sector as the MBR.
- reboot.
Deinstallation:
- boot Linux.
- restore the old MBR, e.g.
dd if=/fd/MBR of=/dev/hda bs=446 count=1
If you've installed LILO as the master boot record, you have to explicitly
specify the boot sector (configuration variable BOOT=...) when updating the
map. Otherwise, it will try to use the boot sector of your current root
partition, which will usually work, but it will probably leave your system
unbootable
阅读(588) | 评论(0) | 转发(0) |