initrd(4) | Device Drivers Manual | initrd(4) |
initrd - boot loader initialized RAM disk
/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:
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.
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.
In the first boot-up phase, the kernel starts up and mounts an initial root filesystem 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 filesystem (i.e., the normal root filesystem) is mounted from a different device.
When booting up with initrd, the system boots as follows:
The following boot loader options, when used with initrd, affect the kernel's boot-up operation:
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 filesystems. For an NFS-mounted normal root filesystem, 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/nfs/nfsroot.txt (or Documentation/filesystems/nfsroot.txt before Linux 2.6.33). For more information on setting the root filesystem see also the LILO and LOADLIN documentation.
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 filesystem device number into /proc/sys/kernel/real-root-dev. For an NFS root filesystem, 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:
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":
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 filesystem is obsolete. See the Linux kernel source file Documentation/admin-guide/initrd.rst (or Documentation/initrd.txt before Linux 4.10) as well as pivot_root(2) and pivot_root(8) for information on the modern method of changing the root filesystem.
The main motivation for implementing initrd was to allow for modular kernel configuration at system installation.
A possible system installation scenario is as follows:
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.
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.
A third scenario is more convenient recovery disks. Because information like the location of the root filesystem 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.
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.
/dev/initrd
/dev/ram0
/linuxrc
/initrd
chown(1), mknod(1), ram(4), freeramdisk(8), rdev(8)
Documentation/admin-guide/initrd.rst (or Documentation/initrd.txt before Linux 4.10) in the Linux kernel source tree, the LILO documentation, the LOADLIN documentation, the SYSLINUX documentation
2023-10-31 | Linux man-pages 6.7 |