initrd(4) - Linux man page initrd(4) - Linux 手册页

initrd man

Name

initrd - boot loader initialized RAM disk
initrd - 引导加载程序初始化的 RAM 磁盘

Configuration

The /dev/initrd is a read-only block device assigned major number 1 and minor number 250. Typically /dev/initrd is owned by root.disk with mode 0400 (read access by root only). If the Linux system does not have /dev/initrd already created, it can be created with the following commands:
/dev/initrd 是一个只读块设备,分配了主编号 1 和次要编号 250。通常,/dev/initrd 归 root.disk 所有,模式为 0400(仅由 root 用户进行读取访问)。如果 Linux 系统尚未创建 /dev/initrd,可以使用以下命令创建它:

mknod -m 400 /dev/initrd b 1 250
chown root:disk /dev/initrd

Also, support for both “RAM disk” and “Initial RAM disk” (e.g., CONFIG_BLK_DEV_RAM=y and CONFIG_BLK_DEV_INITRD=y) must be compiled directly into the Linux kernel to use /dev/initrd. When using /dev/initrd, the RAM disk driver cannot be loaded as a module.
此外,对“RAM磁盘”和“初始RAM磁盘”(例如,CONFIG_BLK_DEV_RAM=y和CONFIG_BLK_DEV_INITRD=y)的支持必须直接编译到Linux内核中才能使用/dev/initrd。使用 /dev/initrd 时,无法将 RAM 磁盘驱动程序作为模块加载。

Description

The special file /dev/initrd is a read-only block device. This device is a RAM disk that is initialized (e.g., loaded) by the boot loader before the kernel is started. The kernel then can use /dev/initrd’s contents for a two-phase system boot-up.
特殊文件 /dev/initrd 是一个只读块设备。此设备是一个 RAM 磁盘,在内核启动之前由引导加载程序初始化(例如,加载)。然后,内核可以使用 /dev/initrd 的内容进行两阶段系统启动。
In the first boot-up phase, the kernel starts up and mounts an initial root file-system from the contents of /dev/initrd (e.g., RAM disk initialized by the boot loader). In the second phase, additional drivers or other modules are loaded from the initial root device’s contents. After loading the additional modules, a new root file system (i.e., the normal root file system) is mounted from a different device.
在第一个启动阶段,内核启动并从 /dev/initrd 的内容(例如,由引导加载程序初始化的 RAM 磁盘)挂载初始根文件系统。在第二阶段,从初始根设备的内容加载其他驱动程序或其他模块。加载其他模块后,将从其他设备挂载新的根文件系统(即普通根文件系统)。

Boot-up operation

When booting up with initrd, the system boots as follows:
使用 initrd 启动时,系统按如下方式启动:
1.
The boot loader loads the kernel program and /dev/initrd’s contents into memory.
引导加载程序将内核程序和 /dev/initrd 的内容加载到内存中。
2.
On kernel startup, the kernel uncompresses and copies the contents of the device /dev/initrd onto device /dev/ram0 and then frees the memory used by /dev/initrd.
在内核启动时,内核会解压缩设备 /dev/initrd 的内容并将其复制到设备 /dev/ram0 上,然后释放 /dev/initrd 使用的内存。
3.
The kernel then read-write mounts the device /dev/ram0 as the initial root file system.
然后,内核读写挂载设备 /dev/ram0 作为初始根文件系统。
4.
If the indicated normal root file system is also the initial root file-system (e.g., /dev/ram0) then the kernel skips to the last step for the usual boot sequence.
如果指示的普通根文件系统也是初始根文件系统(例如,/dev/ram0),则内核将跳到通常引导序列的最后一步。
5.
If the executable file /linuxrc is present in the initial root file-system, /linuxrc is executed with UID 0. (The file /linuxrc must have executable permission. The file /linuxrc can be any valid executable, including a shell script.)
如果可执行文件 /linuxrc 存在于初始根文件系统中,则使用 UID 0 执行 /linuxrc。(文件 /linuxrc 必须具有可执行权限。文件 /linuxrc 可以是任何有效的可执行文件,包括 shell 脚本。
6.
If /linuxrc is not executed or when /linuxrc terminates, the normal root file system is mounted. (If /linuxrc exits with any file-systems mounted on the initial root file-system, then the behavior of the kernel is UNSPECIFIED. See the NOTES section for the current kernel behavior.)
如果未执行 /linuxrc 或 /linuxrc 终止,则挂载普通根文件系统。(如果 /linuxrc 退出,并带有挂载在初始根文件系统上的任何文件系统,则内核的行为为 UNSPECIFIED。有关当前内核行为,请参阅“注释”部分。
7.
If the normal root file system has a directory /initrd, the device /dev/ram0 is moved from / to /initrd. Otherwise if the directory /initrd does not exist, the device /dev/ram0 is unmounted. (When moved from / to /initrd, /dev/ram0 is not unmounted and therefore processes can remain running from /dev/ram0. If directory /initrd does not exist on the normal root file system and any processes remain running from /dev/ram0 when /linuxrc exits, the behavior of the kernel is UNSPECIFIED. See the NOTES section for the current kernel behavior.)
如果普通根文件系统有目录 /initrd,则设备 /dev/ram0 将从 / 移动到 /initrd。否则,如果目录 /initrd 不存在,则卸载设备 /dev/ram0。(当从 / 移动到 /initrd 时,/dev/ram0 不会卸载,因此进程可以从 /dev/ram0 保持运行。如果目录 /initrd 在普通根文件系统上不存在,并且在 /linuxrc 退出时任何进程仍从 /dev/ram0 运行,则内核的行为为 UNSPECIFIED。有关当前内核行为,请参阅“注释”部分。
8.
The usual boot sequence (e.g., invocation of /sbin/init) is performed on the normal root file system.
通常的引导顺序(例如,调用 /sbin/init)是在普通的根文件系统上执行的。

Options

The following boot loader options, when used with initrd, affect the kernel’s boot-up operation:
以下引导加载程序选项与 initrd 一起使用时,会影响内核的引导操作:
initrd=filename
Specifies the file to load as the contents of /dev/initrd. For LOADLIN this is a command-line option. For LILO you have to use this command in the LILO configuration file /etc/lilo.config. The filename specified with this option will typically be a gzipped file-system image.
指定要加载的文件作为 /dev/initrd 的内容。对于 LOADLIN,这是一个命令行选项。对于 LILO,您必须在 LILO 配置文件 /etc/lilo.config 中使用此命令。使用此选项指定的文件名通常是 gzip 压缩的文件系统映像。
noinitrd
This boot option disables the two-phase boot-up operation. The kernel performs the usual boot sequence as if /dev/initrd was not initialized. With this option, any contents of /dev/initrd loaded into memory by the boot loader contents are preserved. This option permits the contents of /dev/initrd to be any data and need not be limited to a file system image. However, device /dev/initrd is read-only and can be read only one time after system startup.
此引导选项禁用两阶段引导操作。内核执行通常的引导顺序,就好像 /dev/initrd 没有初始化一样。使用此选项,引导加载程序内容加载到内存中的 /dev/initrd 的任何内容都将保留。此选项允许 /dev/initrd 的内容是任何数据,而不必局限于文件系统映像。但是,设备 /dev/initrd 是只读的,在系统启动后只能读取一次。
root=device-name
Specifies the device to be used as the normal root file system. For LOADLIN this is a command-line option. For LILO this is a boot time option or can be used as an option line in the LILO configuration file /etc/lilo.config. The device specified by the this option must be a mountable device having a suitable root file-system.
指定要用作普通根文件系统的设备。对于 LOADLIN,这是一个命令行选项。对于 LILO,这是一个引导时间选项,也可以用作 LILO 配置文件 /etc/lilo.config 中的选项行。此选项指定的设备必须是具有合适根文件系统的可挂载设备。

Changing the normal root file system
更改普通根文件系统

By default, the kernel’s settings (e.g., set in the kernel file with rdev(8) or compiled into the kernel file), or the boot loader option setting is used for the normal root file systems. For an NFS-mounted normal root file system, one has to use the nfs_root_name and nfs_root_addrs boot options to give the NFS settings. For more information on NFS-mounted root see the kernel documentation file Documentation/filesystems/nfsroot.txt. For more information on setting the root file system see also the LILO and LOADLIN documentation.
默认情况下,内核的设置(例如,在内核文件中使用 rdev(8) 设置或编译到内核文件中)或引导加载程序选项设置用于普通的根文件系统。对于挂载了 NFS 的普通根文件系统,必须使用 nfs_root_name 和 nfs_root_addrs 引导选项来提供 NFS 设置。有关 NFS 挂载根的详细信息,请参阅内核文档文件 Documentation/filesystems/nfsroot.txt。有关设置根文件系统的更多信息,另请参阅 LILO 和 LOADLIN 文档。

It is also possible for the /linuxrc executable to change the normal root device. For /linuxrc to change the normal root device, /proc must be mounted. After mounting /proc, /linuxrc changes the normal root device by writing into the proc files /proc/sys/kernel/real-root-dev, /proc/sys/kernel/nfs-root-name, and /proc/sys/kernel/nfs-root-addrs. For a physical root device, the root device is changed by having /linuxrc write the new root file system device number into /proc/sys/kernel/real-root-dev. For an NFS root file system, the root device is changed by having /linuxrc write the NFS setting into files /proc/sys/kernel/nfs-root-name and /proc/sys/kernel/nfs-root-addrs and then writing 0xff (e.g., the pseudo-NFS-device number) into file /proc/sys/kernel/real-root-dev. For example, the following shell command line would change the normal root device to /dev/hdb1:
/linuxrc 可执行文件也可以更改正常的根设备。要使 /linuxrc 更改普通的根设备,必须挂载 /proc。挂载 /proc 后,/linuxrc 通过写入 proc 文件 /proc/sys/kernel/real-root-dev、/proc/sys/kernel/nfs-root-name 和 /proc/sys/kernel/nfs-root-addrs 来更改普通的 root 设备。对于物理根设备,通过让 /linuxrc 将新的根文件系统设备编号写入 /proc/sys/kernel/real-root-dev 来更改根设备。对于 NFS 根文件系统,通过让 /linuxrc 将 NFS 设置写入文件 /proc/sys/kernel/nfs-root-name 和 /proc/sys/kernel/nfs-root-addrs,然后将0xff(例如,伪 NFS 设备编号)写入文件 /proc/sys/kernel/real-root-dev 来更改根设备。例如,以下 shell 命令行会将普通根设备更改为 /dev/hdb1:

echo 0x365 >/proc/sys/kernel/real-root-dev
For an NFS example, the following shell command lines would change the normal root device to the NFS directory /var/nfsroot on a local networked NFS server with IP number 193.8.232.7 for a system with IP number 193.8.232.2 and named “idefix”:
对于 NFS 示例,对于 IP 号为 193.8.232.2 且名为“idefix”的系统,以下 shell 命令行会将 IP 号为 193.8.232.2 且名为“idefix”的本地联网 NFS 服务器上的普通根设备更改为 NFS 目录 /var/nfsroot:
echo /var/nfsroot >/proc/sys/kernel/nfs-root-name
echo 193.8.232.2:193.8.232.7::255.255.255.0:idefix
>/proc/sys/kernel/nfs-root-addrs
echo 255 >/proc/sys/kernel/real-root-dev

Note: The use of /proc/sys/kernel/real-root-dev to change the root file system is obsolete. See the Linux kernel source file Documentation/initrd.txt as well as pivot_root(2) and pivot_root(8) for information on the modern method of changing the root file system.
注意:使用 /proc/sys/kernel/real-root-dev 更改根文件系统已过时。参见 Linux 内核源文件 Documentation/initrd.txt以及 pivot_root(2) 和 pivot_root(8) 来了解更改根文件系统的现代方法。

Usage

The main motivation for implementing initrd was to allow for modular kernel configuration at system installation.
实现 initrd 的主要动机是允许在系统安装时进行模块化内核配置。
A possible system installation scenario is as follows:
可能的系统安装方案如下:

The loader program boots from floppy or other media with a minimal kernel (e.g., support for /dev/ram, /dev/initrd, and the ext2 file-system) and loads /dev/initrd with a gzipped version of the initial file-system.
loader 程序从软盘或其他具有最小内核的介质(例如,支持 /dev/ram、/dev/initrd 和 ext2 文件系统)启动,并使用初始文件系统的 gzip 版本加载 /dev/initrd。
2.
The executable /linuxrc determines what is needed to (1) mount the normal root file-system (i.e., device type, device drivers, file system) and (2) the distribution media (e.g., CD-ROM, network, tape, …). This can be done by asking the user, by auto-probing, or by using a hybrid approach.
可执行文件 /linuxrc 确定 (1) 挂载普通根文件系统(即设备类型、设备驱动程序、文件系统)和 (2) 分发介质(例如 CD-ROM、网络、磁带等)所需的内容。这可以通过询问用户、自动探测或使用混合方法来完成。
3.
The executable /linuxrc loads the necessary modules from the initial root file-system.
可执行文件 /linuxrc 从初始根文件系统加载必要的模块。
4.
The executable /linuxrc creates and populates the root file system. (At this stage the normal root file system does not have to be a completed system yet.)
可执行文件 /linuxrc 创建并填充根文件系统。(在此阶段,普通的根文件系统还不一定是完整的系统。
5.
The executable /linuxrc sets /proc/sys/kernel/real-root-dev, unmount /proc, the normal root file system and any other file systems it has mounted, and then terminates.
可执行文件 /linuxrc 设置 /proc/sys/kernel/real-root-dev,卸载 /proc、普通根文件系统和它已挂载的任何其他文件系统,然后终止。
6.
The kernel then mounts the normal root file system.
然后,内核挂载普通的根文件系统。
7.
Now that the file system is accessible and intact, the boot loader can be installed.
现在文件系统是可访问的并且完好无损,可以安装引导加载程序了。
8.
The boot loader is configured to load into /dev/initrd a file system with the set of modules that was used to bring up the system. (e.g., Device /dev/ram0 can be modified, then unmounted, and finally, the image is written from /dev/ram0 to a file.)
引导加载程序配置为将文件系统加载到 /dev/initrd 中,其中包含用于启动系统的模块集。(例如,可以修改设备 /dev/ram0,然后卸载,最后将映像从 /dev/ram0 写入文件。
9.
The system is now bootable and additional installation tasks can be performed.
系统现在可以启动,并且可以执行其他安装任务。
The key role of /dev/initrd in the above is to reuse the configuration data during normal system operation without requiring initial kernel selection, a large generic kernel or, recompiling the kernel.
在上面,/dev/initrd 的关键作用是在正常系统运行期间重用配置数据,而无需初始内核选择、大型通用内核或重新编译内核。

A second scenario is for installations where Linux runs on systems with different hardware configurations in a single administrative network. In such cases, it may be desirable to use only a small set of kernels (ideally only one) and to keep the system-specific part of configuration information as small as possible. In this case, create a common file with all needed modules. Then, only the /linuxrc file or a file executed by /linuxrc would be different.
第二种情况是 Linux 在单个管理网络中具有不同硬件配置的系统上运行的安装。在这种情况下,可能希望只使用一小部分内核(理想情况下只有一个内核),并使配置信息中特定于系统的部分尽可能小。在这种情况下,创建一个包含所有需要模块的通用文件。然后,只有 /linuxrc 文件或 /linuxrc 执行的文件会有所不同。

A third scenario is more convenient recovery disks. Because information like the location of the root file-system partition is not needed at boot time, the system loaded from /dev/initrd can use a dialog and/or auto-detection followed by a possible sanity check.
第三种情况是更方便的恢复磁盘。因为在引导时不需要根文件系统分区的位置等信息,所以从 /dev/initrd 加载的系统可以使用对话框和/或自动检测,然后进行可能的健全性检查。

Last but not least, Linux distributions on CD-ROM may use initrd for easy installation from the CD-ROM. The distribution can use LOADLIN to directly load /dev/initrd from CD-ROM without the need of any floppies. The distribution could also use a LILO boot floppy and then bootstrap a bigger RAM disk via /dev/initrd from the CD-ROM.
最后但并非最不重要的一点是,CD-ROM 上的 Linux 发行版可以使用 initrd 以便从 CD-ROM 轻松安装。发行版可以使用 LOADLIN 直接从 CD-ROM 加载 /dev/initrd,而无需任何软盘。该发行版还可以使用 LILO 启动软盘,然后通过 CD-ROM 中的 /dev/initrd 引导更大的 RAM 磁盘。

Files
/dev/initrd
/dev/ram0
/linuxrc
/initrd

Notes
1.
With the current kernel, any file systems that remain mounted when /dev/ram0 is moved from / to /initrd continue to be accessible. However, the /proc/mounts entries are not updated.
使用当前内核,当 /dev/ram0 从 / 移动到 /initrd 时,任何保持挂载的文件系统都可以继续访问。但是,/proc/mounts 条目不会更新。
2.
With the current kernel, if directory /initrd does not exist, then /dev/ram0 will not be fully unmounted if /dev/ram0 is used by any process or has any file-system mounted on it. If /dev/ram0 is not fully unmounted, then /dev/ram0 will remain in memory.
在当前内核中,如果目录 /initrd 不存在,那么如果 /dev/ram0 被任何进程使用或挂载了任何文件系统,则 /dev/ram0 将不会被完全卸载。如果 /dev/ram0 未完全卸载,则 /dev/ram0 将保留在内存中。
3.
Users of /dev/initrd should not depend on the behavior give in the above notes. The behavior may change in future versions of the Linux kernel.
/dev/initrd 的用户不应依赖上述说明中给出的行为。在将来的 Linux 内核版本中,该行为可能会更改。

See Also
chown(1), mknod(1), ram(4), freeramdisk(8), rdev(8)
chown(1)、mknod(1)、ram(4)、freeramdisk(8)、rdev(8)
Documentation/initrd.txt in the Linux kernel source tree, the LILO documentation, the LOADLIN documentation, the SYSLINUX documentation
Linux内核源代码树中的文档/initrd.txt,LILO文档,LOADLIN文档,SYSLINUX文档

Referenced By

gfs2_mount(8), gfs_mount(8), hotplug(8), mount.gfs2(8)
gfs2_mount(8)、gfs_mount(8)、热插拔(8)、mount.gfs2(8)

  • 24
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

魔尊moon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值