07-A.3: Configuring initrd
- Page ID
initrd (initial ramdisk) is a scheme for loading a temporary root file system into memory, which may be used as part of the Linux startup process. initrd and initramfs refer to two different methods of achieving this. Both are commonly used to make preparations before the real root file system can be mounted.
Many Linux distributions ship a single, generic Linux kernel image – one that the distribution's developers create specifically to boot on a wide variety of hardware. The device drivers for this generic kernel image are included as loadable kernel modules because statically compiling many drivers into one kernel causes the kernel image to be much larger, perhaps too large to boot on computers with limited memory. This then raises the problem of detecting and loading the modules necessary to mount the root file system at boot time, or for that matter, deducing where or what the root file system is.
An image of this initial root file system (along with the kernel image) must be stored somewhere accessible by the Linux bootloader or the boot firmware of the computer. This can be the root file system itself, a boot image on an optical disc, a small partition on a local disk (a boot partition, usually using ext2 or FAT file systems), or a TFTP server (on systems that can boot from Ethernet).
The bootloader will load the kernel and initial root file system image into memory and then start the kernel, passing in the memory address of the image. At the end of its boot sequence, the kernel tries to determine the format of the image from its first few blocks of data, which can lead either to the initrd or initramfs scheme.
The mkinitrd Command
The mkinitrd command creates an initial image used by the kernel for preloading the block device modules (such as IDE, SCSI or RAID) which are needed to access the root filesystem.
mkinitrd [ OPTIONS ] [<nitrd-image] <kernel-version>
|--with=<module>||Add the kernel module <module> to the initramfs.|
|--preload=<module>||Preload the kernel module <module> in the initramfs before any other kernel modules are loaded.|
|--nocompress||Do not compress the resulting image.|
|-f, --force||Overwrite existing initramfs file.|
We have seen the idea of using the uname command to help us issue commands before. We use it in the following example because we want the resulting image to have a definitive name associating it with the current kernel.
pbmac@pbmac-server $ mkinitrd -f /boot/initrd-`uname -r`-new.img `uname -r`
The /boot Directory
This directory contains everything required for the boot process except for configuration files not needed at boot time (the most notable of those being those that belong to the GRUB boot-loader) and the map installer. Thus, the /boot directory stores data that is used before the kernel begins executing user-mode programs. This may include redundant (back-up) master boot records, sector/system map files, the kernel and other important boot files and data that is not directly edited by hand. Programs necessary to arrange for the boot loader to be able to boot a file are placed in /sbin. Configuration files for boot loaders are placed in /etc. The system kernel is located in either / or /boot
|/boot Files and Directories||Description|
|/boot/initrd.img-<kernel version>||In the initrd scheme, the image may be a file system image (optionally compressed), which is made available in a special block device (/dev/ram) that is then mounted as the initial root file system. The driver for that file system must be compiled statically into the kernel.|
|Some Linux distributions use initramfs as an alternative to initrd. In the initramfs scheme, the image may be a cpio archive (optionally compressed). The archive is unpacked by the kernel into a special instance of a tmpfs that becomes the initial root file system. This scheme has the advantage of not requiring an intermediate file system or block drivers to be compiled into the kernel.|
|/boot/efi||The EFI (Extensible Firmware Interface) system partition or ESP is a partition on a data storage device (usually a hard disk drive or solid-state drive) that is used by computers adhering to the Unified Extensible Firmware Interface (UEFI). When a computer is booted, UEFI firmware loads files stored on the ESP to start installed operating systems and various utilities.|
|/boot/grub||Contains the configuration files for the GRUB bootloader. These files are mostly modules (.mod), with configuration stored in grub.cfg.|
|vmlinux-<kernel version>||On Linux systems, vmlinux is a statically linked executable file that contains the Linux kernel in one of the object file formats supported by Linux, which includes ELF, COFF and a.|
What is dracut?
As you begin to work with creating and modifying kernels you will find references to the dracut command in some of the man pages. dracut is an event driven initramfs infrastructure. dracut (the tool) is used to create an initramfs image by copying tools and files from an installed system and combining it with the dracut framework, usually found in /usr/lib/dracut/modules.d.
Unlike existing initramfs's, dracut's framework attempts at having as little as possible hard-coded into the initramfs. The initramfs has (basically) one purpose in life -- getting the rootfs mounted so that we can transition to the real rootfs. This is all driven off of device availability. Therefore, instead of scripts hard-coded to do various things, dracut's initramfs depends on udev to create symbolic links to device nodes and then when the rootfs's device node appears, it is mounted and root is switched to it. This helps to keep the time required in the initramfs as minimal as possible so that things like a five-second boot aren't made impossible as a result of the very existence of an initramfs.
"Initial ramdisk" by Multiple Contributors, Wikipedia is licensed under CC BY-SA 3.0
"/boot/" by Multiple Contributors, Wikipedia is licensed under CC BY-SA 3.0
"EFI system partition" by Multiple Contributors, Wikipedia is licensed under CC BY-SA 3.0
"dracut" by Various contributors, The Linux Kernel Archives is licensed under CC BY-SA 3.0