The Linux Bootdisk HOWTO 之 3. Bootdisks and the boot process 启动盘与启动过程

来源:互联网 发布:小学语文出题软件 编辑:程序博客网 时间:2024/05/06 16:25
3. Bootdisks and the boot process

A bootdisk is basically a miniature, self−contained Linux system on a diskette. It must perform many of the same functions that a complete full−size Linux system performs. Before trying to build one you should understand the basic Linux boot process. Here we present the basics, which are sufficient for understanding the rest of this document. Many details and alternative options have been omitted.

启动盘与启动过程

基本上,启动盘指的是软盘上的一个最小化的,自包含的Linux系统。它必须执行很多与完全大小的Linux系统所执行功能相同的功能。在试图构建这样一个启动盘之前,你应该对基本的Linux启动过程有所理解。这里我们只表述了基本的部分,它们对于理解本文档的其他部分已经足够了。很多的细节和可选项被略过了。


3.1. The boot process
All PC systems start the boot process by executing code in ROM (specifically, the BIOS) to load the sector from sector 0, cylinder 0 of the boot drive. The boot drive is usually the first floppy drive (designated A: in DOS and /dev/fd0 in Linux). The BIOS then tries to execute this sector. On most bootable disks, sector 0, cylinder 0 contains either:

·   code from a boot loader such as LILO, which locates the kernel, loads it and executes it to start the boot proper; or
·   the start of an operating system kernel, such as Linux.

启动过程

所有的PC系统都是从执行ROM中的代码开始启动过程的,即,加载位于启动驱动器柱面0,扇区0的扇区。启动驱动器通常是第一个软盘驱动器(DOS中是 A: , Linux中是 /dev/fd0)。BIOS尝试执行该扇区。在大部分的可启动的磁盘上,扇区0,柱面0包含以下2者之一:

- 诸如LILO的boot loader的代码,它定位kernel,加载它,并执行它以开始启动; 或者

- 诸如Linux的操作系统kernel的开始部分



If a Linux kernel has been raw-copied to a diskette, the first sector of the disk will be the first sector of the Linux kernel itself. This first sector will continue the boot process by loading the rest of the kernel from the boot device.

如果Linux kernel是裸拷贝到软盘上的话,磁盘的第一个扇区也就是Linux kernel本身的第一个扇区。通过从启动设备加载kernel的其余部分,第一个扇区将继续启动过程。


When the kernel is completely loaded, it initializes device drivers and its internal data structures. Once it is completely initialized, it consults a special location in its image called the ramdisk word. This word tells it how and where to find its root filesystem. A root filesystem is simply a filesystem that will be mounted as ``/''. The kernel has to be told where to look for the root filesystem; if it cannot find a loadable image there, it halts.

当kernel完全加载好的时候,kernel初始化设备驱动,还有它内部的数据结构。一旦完全的初始化好了,kernel会查询在image中的一个叫做ramdisk word的特殊位置。这个word会告诉kernel怎么样,在哪里可以找到kernel的root file system。root file system是一个简单的file system,它被挂接为"/"。kernel必须被告知可以在哪里找到root file system;如果它在那里找不到可加载的image,kernel就挂住了。

In some boot situations often when booting from a diskette the root filesystem is loaded into a ramdisk, which is RAM accessed by the system as if it were a disk. RAM is several orders of magnitude faster than a floppy disk, so system operation is fast from a ramdisk. Also, the kernel can load a compressed filesystem from the floppy and uncompress it onto the ramdisk, allowing many more files to be squeezed onto the diskette.

在从软盘启动的时候,经常有一些启动场景,root file system是被加载到ramdisk中,它是块RAM,不过系统把它作为磁盘进行访问。RAM比floppy disk快几个量级,因此,对于ramdisk进行的系统操作就会很快。另外,kernel可以从floppy加载一个压缩的file system,并将其解压到ramdisk中,


Once the root filesystem is loaded and mounted, you see a message like:
                                                           VFS: Mounted root (ext2 filesystem) readonly.

一旦,root file system加载并挂接好了,你会看见如下面一样的一条信息:

                                                            VFS: Mounted root (ext2 filesystem) readonly 


Once the system has loaded a root filesystem successfully, it tries to execute the init program (in /bin or  /sbin). init reads its configuration file /etc/inittab, looks for a line designated sysinit, and executes the named script. The sysinit script is usually something like /etc/rc or /etc/init.d/boot. This script is a set of shell commands that set up basic system services, such as running fsck on hard disks, loading necessary kernel modules, initializing swapping, initializing the network, and mounting disks mentioned in /etc/fstab.

一旦系统成功加载了root file system,它会尝试执行init 程序(在/bin中,或者/sbin中)。init会读取配置文件 /etc/inittab,找寻指定为sysinit的一行,然后执行命名的脚本。sysinit脚本通常是像 /etc/rc或者 /etc/init.d/boot一样的东西。该脚本是一系列脚本命令的集合,用以建立基本的系统服务,像在硬盘上运行fsck,加载必要的kernel模块,初始化swapping,初始化网络,挂接/etc/fstab中提到的磁盘。


This script often invokes various other scripts to do modular initialization. For example, in the common SysVinit structure, the directory /etc/rc.d/ contains a complex structure of subdirectories whose files specify how to enable and shut down most system services. However, on a bootdisk the sysinit script is often very simple.

该脚本经常调用各种其他的脚本,以进行模块初始化。例如,在通常的 SysVinit结构中,目录/etc/rc.d会包含一个复杂的结构,包含很多子目录。该子目录的文件定义了怎么样开启以及关闭大部分的系统服务。然而,在启动盘上的sysinit脚本,通常是比较简单的。


When the sysinit script finishes control returns to init, which then enters the default runlevel, specified in inittab with the initdefault keyword. The runlevel line usually specifies a program like getty, which is responsible for handling commununications through the console and ttys. It is the getty program which prints the familiar ``login:'' prompt. The getty program in turn invokes the login program to handle login validation and to set up user sessions.

当sysinit脚本结束,控制返回到init之后,init会进入默认的runlevel,runlevel以initdefault关键字定义在inittab中。runlevel通常定义了像getty一样的程序,getty负责通过console和ttys进行通信。打印“login:”提示符,就是像getty样的程序干的事。反过来,getty调用login程序以处理login的有效性并建立用户会话。


3.2. Disk types
Having reviewed the basic boot process, we can now define various kinds of disks involved. We classify disks into four types. The discussion here and throughout this document uses the term ``disk'' to refer to floppy diskettes unless otherwise specified, though most of the discussion could apply equally well to hard disks.

3.2 磁盘类型

看过了基本的启动过程之后,我们现在可以定义几种会接触到的磁盘了。我们将磁盘分为4类。这里的讨论以及贯穿整个文档,使用术语“磁盘”来提及floppy软盘,除非特别说明,虽然讨论的大部分内容也同样应用于硬盘。


boot
A disk containing a kernel which can be booted. The disk can be used to boot the kernel, which then may load a root file system on another disk. The kernel on a bootdisk usually must be told where to find its root filesystem.

Often a bootdisk loads a root filesystem from another diskette, but it is possible for a bootdisk to be set up to load a hard disk's root filesystem instead. This is commonly done when testing a new kernel (in fact, ``make zdisk'' will create such a bootdisk automatically from the kernel source code).

boot磁盘包含可以启动的kernel。磁盘可以用来启动kernel,之后,kernel会加载其他磁盘上的root file system。启动盘上的kernel通常都必须被告知,可以在哪里找到kernel的root file system。

经常地,启动盘会从其他的软盘加载root file system,但是对于启动盘而言,也可能替代地加载硬盘的root file system。在测试新的kernel的时候,通常会这么做(事实上,“make zdisk”就会从kernel源码自动地创建这样一个启动盘)。


root
A disk with a filesystem containing files required to run a Linux system. Such a disk does not necessarily contain either a kernel or a boot loader.

A root disk can be used to run the system independently of any other disks, once the kernel has been booted. Usually the root disk is automatically copied to a ramdisk. This makes root disk accesses much faster, and frees up the disk drive for a utility disk.

root磁盘其上有file system,并包含运行Linux系统所需的文件。这样的磁盘不必包含kernel或者boot loader。

一旦kernel已经启动起来,root磁盘可以独立于其他的磁盘运行整个系统。通常,root磁盘会被自动拷贝到ramdisk。这使得root 磁盘可以更快地访问,并且,为utility磁盘释放出了一个磁盘驱动。

boot/root
A disk which contains both the kernel and a root filesystem. In other words, it contains everything necessary to boot and run a Linux system without a hard disk. 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 is increasingly difficult to fit everything on a single diskette, even with compression.

boot/root磁盘,它既包含kernel又包含root file system。换句话说,不需要硬盘,它包含启动并运行Linux系统的一切。这种类型磁盘的优势是,所必需的紧凑的所有都处在一个磁盘上。然而,即便有压缩可用,每件所需都在不断增加大小,这意味着,越来越难将所有的放在一个磁盘上。

utility
A disk which contains a filesystem, 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.

utility磁盘包含一个 file system,但并不是用于挂接作root file system。它是一个额外的数据磁盘。你会使用这种类型的磁盘搬运附加的工具,如果是在你的root磁盘上,你需要做的就太多了。

In general, when we talk about ``building a bootdisk'' we mean creating both the boot (kernel) and root (files) portions. They may be either together (a single boot/root disk) or separate (boot + root disks). The most flexible approach for rescue diskettes is probably to use separate boot and root diskettes, and one or more utility diskettes to handle the overflow.

一般而言,当我们谈论“构建启动盘”的时候,通常意味着,创建启动(kernel)和根(files)两部分。它们可能是在一起的(一个单一的boot/root磁盘),或者独立开的(boot + root 2个磁盘)。对于应急软盘,最灵活的方法可能是,使用独立开的boot 和 root 软盘,还有,一个或者多个utility磁盘以处理溢出的情况。





原创粉丝点击