How to use the command 'dracut' (with examples)
- Linux
- December 25, 2023
Dracut is a command-line tool used to generate initramfs images for booting the Linux kernel. It provides options to configure the generation process and uses configuration files in /etc/dracut.conf
, /etc/dracut.conf.d/*.conf
, and /usr/lib/dracut/dracut.conf.d/*.conf
by default. This article will explore various use cases of the dracut
command.
Use case 1: Generate an initramfs image for the current kernel without overriding any options
Code:
dracut
Motivation:
Sometimes, it becomes necessary to generate an initramfs image, especially during kernel updates, to ensure proper boot-up. By using the dracut
command without any options, it generates an initramfs image for the current kernel, taking into account the existing configuration options.
Explanation:
dracut
: The command itself calls thedracut
tool to generate the initramfs image.
Example output:
dracut: dracut module 'usrmount' will not be installed, because command 'mount' could not be found!
dracut: dracut module 'busybox' will not be installed, because command 'busybox' could not be found!
dracut: dracut module 'dash' will not be installed, because command 'dash' could not be found!
dracut: dracut module 'dash-static' will not be installed, because command 'dash' could not be found!
dracut: dracut module 'mdraid' will not be installed, because command 'mdadm' could not be found!
*** Creating image file ***
*** Creating image file done ***
*** Creating initramfs image file '/boot/initramfs-5.4.0-84-generic.img' done ***
Use case 2: Generate an initramfs image for the current kernel and overwrite the existing one
Code:
dracut --force
Motivation:
Occasionally, it may be necessary to overwrite the existing initramfs image to ensure the latest changes or updates are incorporated into the boot process. By using the --force
option, the dracut
command will overwrite the existing initramfs image for the current kernel.
Explanation:
--force
: This option forcesdracut
to overwrite any existing initramfs image without prompting for confirmation.
Example output:
*** Creating image file ***
*** Creating image file done ***
*** Creating initramfs image file '/boot/initramfs-5.4.0-84-generic.img' done ***
Use case 3: Generate an initramfs image for a specific kernel
Code:
dracut --kver kernel_version
Motivation:
In some scenarios, there may be multiple installed kernels on the system, and it becomes necessary to generate an initramfs image for a specific kernel. The --kver
option allows us to specify the kernel version for which we want to generate the initramfs image.
Explanation:
--kver kernel_version
: This option specifies the kernel version for which the initramfs image should be generated.
Example output:
*** Creating image file ***
*** Creating image file done ***
*** Creating initramfs image file '/boot/initramfs-5.10.0-1051-oem.img' done ***
Use case 4: Show a list of available modules
Code:
dracut --list-modules
Motivation:
The dracut
command also provides an option to list all available modules that can be used during the initramfs generation process. This can be helpful when customizing the generation process or troubleshooting boot-related issues.
Explanation:
--list-modules
: This option displays a list of available modules that can be used with thedracut
command.
Example output:
10menu
90crypt
95lvm
96fcoe
97dasd
...
Conclusion:
The dracut
command is a versatile tool for generating initramfs images for booting the Linux kernel. By understanding the various use cases and options described in this article, users can effectively generate and customize their initramfs images based on their specific requirements.