Article title: Linux initial RAM disk (initrd) overview. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
What is an initial RAM disk?
Initial RAM disk (initrd)Is an initial root file system attached to the system before the actual root file system is available. Initrd is bound with the kernel and loaded as part of the kernel boot process. The kernel then loads the initrd file as part of its two-phase boot process, so that you can later use the real file system and mount the actual root file system.
Initrd contains the directory required to achieve this goal and the minimal set of executable programs, such asinsmodTool.
Initrd is a temporary file system in a desktop or server Linux system. It has a short life cycle and can only serve as a bridge to the real file system. Initrd is a permanent root file system in an embedded system without storage devices. This article will explore these two situations.
Initrd profiling
The initrd image contains the necessary executable programs and system files required to support the two-phase Linux boot process.
The method for creating an initial RAM disk may vary depending on the Linux version we run. Before Fedora Core 3, initrd usedLoop device.Loop deviceIs a device driver that can be used to mount files to the system as a block device, and then you can view the content in the file system. You may not have a loop device in your kernel, but you can use the kernel configuration tool (make menuconfig) SelectDevice Drivers> Block Devices> Loopback Device Support. You can view the content of the loop device as follows (the name of the initrd file may be slightly different ):
Listing 1. view the content of initrd (applicable to versions earlier than FC3)
# mkdir temp ; cd temp# cp /boot/initrd.img.gz .# gunzip initrd.img.gz# mount -t ext -o loop initrd.img /mnt/initrd# ls -la /mnt/initrd# |
Now we can view the content in the/mnt/initrd subdirectory, which represents the content of the initrd file. Note that even if your initrd image file is not. at the end of gz, it may also be a compressed file. you can add this file. gz suffix, and then use gunzip to decompress it.
Starting from Fedora Core 3, the default initrd image is changed to a compressed cpio archive file. Instead of using the loop device to Mount initrd as a compressed image, we can use it as a cpio archive file. To view the contents of the cpio archive file, run the following command:
Listing 2. view the content of initrd (applicable to FC3 and later versions)
# mkdir temp ; cd temp# cp /boot/initrd-2.6.14.2.img initrd-2.6.14.2.img.gz# gunzip initrd-2.6.14.2.img.gz# cpio -i --make-directories < initrd-2.6.14.2.img# |
A small root file system is generated, as shown in listing 3. There is a small but essential set of applications in the./bin directory, includingnash(Not a shell, is a script interpreter ),insmod(Used to load the kernel module) andlvm(Logical volume management tool ).
Listing 3. default Linux initrd directory structure
# ls -la#drwxr-xr-x 10 root root 4096 May 7 02:48 .drwxr-x--- 15 root root 4096 May 7 00:54 ..drwxr-xr-x 2 root root 4096 May 7 02:48 bindrwxr-xr-x 2 root root 4096 May 7 02:48 devdrwxr-xr-x 4 root root 4096 May 7 02:48 etc-rwxr-xr-x 1 root root 812 May 7 02:48 init-rw-r--r-- 1 root root 1723392 May 7 02:45 initrd-2.6.14.2.imgdrwxr-xr-x 2 root root 4096 May 7 02:48 libdrwxr-xr-x 2 root root 4096 May 7 02:48 loopfsdrwxr-xr-x 2 root root 4096 May 7 02:48 proclrwxrwxrwx 1 root root 3 May 7 02:48 sbin -> bindrwxr-xr-x 2 root root 4096 May 7 02:48 sysdrwxr-xr-x 2 root root 4096 May 7 02:48 sysroot# |
What is interesting in listing 3 is that the init file is in the root directory. Similar to the traditional Linux boot process, this file is also called when extracting the initrd image to a RAM disk. We will explore this issue later in this article.
Tool used to create initrd
|
Cpio command
UsecpioCommand, we can operate on the cpio file. Cpio is a file format. it uses a file header to concatenate a group of files. Cpio file formats can use ASCII and binary files. To ensure portability, we can use ASCII format. To reduce the file size, we can use the binary version. |
|
Let's go back to the very beginning to see how the initrd image was initially built. For traditional Linux systems, the initrd image is created during the Linux build process. There are many tools, suchmkinitrd, Can be used to use the necessary libraries and modules to automatically build initrd, thus serving as a bridge to the real root file system.mkinitrdThe tool is actually a shell script, so we can see how it achieves this result. There is anotherYAIRD(Yet Another Mkinitrd) tool, which can be customized for various aspects of the initrd build process.
[1] [2] [3] Next page