The mkinitrd
command is used in Linux systems to create an image file that is loaded into the RAM disk (initramfs) during the boot process. This image file contains the necessary drivers, modules, and configuration files required to initialize the system and mount the root file system. The mkinitrd
command is usually used when there are changes made to the system that require a new kernel to be installed.
Overview
The mkinitrd
command is used to create an image file that is loaded into the RAM disk during the boot process. This image file contains the necessary drivers, modules, and configuration files required to initialize the system and mount the root file system.
The basic syntax for the mkinitrd
command is:
mkinitrd [options] <initrd-image> <kernel-version>
Where:
[options]
are the available options for the command (see below).<initrd-image>
is the name of the image file to be created.<kernel-version>
is the version of the kernel for which the image file is being created.
For example, to create an image file named initrd.img
for kernel version 4.18.0-193.el8.x86_64
, the command would be:
mkinitrd -f /boot/initrd.img-4.18.0-193.el8.x86_64 4.18.0-193.el8.x86_64
This command will create the initrd.img-4.18.0-193.el8.x86_64
image file in the /boot
directory.
Use cases
The mkinitrd
command is commonly used in the following scenarios:
- When adding new hardware to the system that requires additional drivers or modules.
- When modifying the system’s boot process, such as changing the root file system or boot loader.
- When upgrading the kernel to a new version.
Examples
Here are some examples of how to use the mkinitrd
command:
Example 1: Creating a new image file
To create a new image file named initrd.img
for kernel version 4.18.0-193.el8.x86_64
, use the following command:
mkinitrd -f /boot/initrd.img-4.18.0-193.el8.x86_64 4.18.0-193.el8.x86_64
Example 2: Verbose output
To display verbose output during the creation of the image file, use the -v
option:
mkinitrd -v -f /boot/initrd.img-4.18.0-193.el8.x86_64 4.18.0-193.el8.x86_64
Example 3: Custom kernel arguments
To include custom kernel arguments in the image file, use the -a
option:
mkinitrd -a "root=/dev/sda1 quiet" -f /boot/initrd.img-4.18.0-193.el8.x86_64 4.18.0-193.el8.x86_64
Options
Here are the available options for the mkinitrd
command:
Option | Description |
---|---|
-f <initrd-image> |
Specify the name and location of the image file to be created. |
-k <kernel-version> |
Specify the version of the kernel for which the image file is being created. |
-v |
Display verbose output during the creation of the image file. |
-r <root-device> |
Specify the root device to be used during the boot process. |
-m <module> |
Specify additional modules to be included in the image file. |
-a <kernel-args> |
Specify additional kernel arguments to be included in the image file. |
-t <temp-directory> |
Specify a temporary directory to be used during the creation of the image file. |
-h |
Display help information for the command. |
Troubleshooting tips
Here are some common issues that may occur when using the mkinitrd
command and how to troubleshoot them:
Error: “No module mptbase found for kernel <kernel-version>”
This error occurs when a required module is missing from the system. To resolve this issue, install the missing module using the appropriate package manager.
Error: “Failed to create initrd image”
This error occurs when there is insufficient disk space or permissions to create the image file. To resolve this issue, ensure that there is enough disk space and that the user has the necessary permissions to create the file.
Error: “Invalid kernel version”
This error occurs when the specified kernel version is invalid or does not exist on the system. To resolve this issue, ensure that the correct kernel version is specified and installed on the system.
Notes
- The
mkinitrd
command is typically used on Red Hat-based systems, while themkinitramfs
command is used on Debian-based systems. - The
mkinitrd
command is typically run as the root user or with sudo privileges.