LinuxCommandLibrary

dracut

Create initramfs images for booting Linux

TLDR

Generate an initramfs image for the current kernel without overriding any options

$ dracut
copy

Generate an initramfs image for the current kernel and overwrite the existing one
$ dracut [[-f|--force]]
copy

Generate an initramfs image for a specific kernel
$ dracut --kver [kernel_version]
copy

List available modules
$ dracut --list-modules
copy

SYNOPSIS

dracut [OPTIONS] [<image_file> [<kernel_version>]]

PARAMETERS

-H, --host-only
    Generates an initramfs image specifically for the current host's hardware, including only modules and files needed for the running system. This typically results in a smaller image.

-f, --force
    Forces dracut to overwrite an existing initramfs image with the same name.

-v, --verbose
    Increases the verbosity of the output during the image generation process, showing more details about what dracut is doing.

-q, --quiet
    Suppresses most output from dracut, only showing critical errors or warnings.

-k, --kver <kernel_version>
    Specifies the kernel version for which the initramfs image should be built. If omitted, it defaults to the currently running kernel version.

-o, --omit <modules>
    A comma-separated list of dracut modules to explicitly omit from the generated initramfs, even if they would normally be included.

-a, --add <modules>
    A comma-separated list of dracut modules to explicitly add to the generated initramfs, even if not automatically detected.

-N, --no-compress
    Prevents the compression of the resulting initramfs image. This results in a larger file but can sometimes speed up boot times by avoiding decompression overhead.

--list-modules
    Prints a list of all available dracut modules along with a brief description for each.

--regenerate-all
    Attempts to regenerate all initramfs images found in /boot for all installed kernel versions.

DESCRIPTION

The dracut command is a utility used to create an initramfs (initial RAM filesystem) image. This image is a compressed archive containing a minimal root filesystem and essential kernel modules, tools, and scripts. It is loaded by the Linux kernel very early in the boot process, allowing the system to access and mount the actual root filesystem, especially when it's located on complex storage setups like LVM, encrypted volumes, software RAID, or network-based storage (e.g., iSCSI, NFS).

dracut is designed to be highly modular and uses shell scripts for its functionality, making it flexible and extensible. It automatically detects the necessary kernel modules and components required for the specific host system, thereby creating an initramfs image tailored to that machine. This modular approach replaced older tools like mkinitrd in many modern Linux distributions, including Fedora, RHEL, and CentOS, providing a more robust and maintainable solution for boot-time setup.

CAVEATS

Improper use of dracut, such as omitting critical drivers or misconfiguring paths, can render a system unbootable. While --host-only is recommended for smaller images, it means the initramfs is tied to specific hardware; changes in hardware (e.g., migrating a virtual machine to a different hypervisor) might require regenerating the image. Large initramfs images can increase boot time and memory consumption during the early boot phase.

DRACUT MODULES

The core of dracut's flexibility comes from its module system. These modules are self-contained directories or scripts that provide specific functionalities, drivers, or tools to be included in the initramfs. Examples include modules for managing LVM, decrypting encrypted volumes (cryptsetup), setting up network booting (NFS, iSCSI), or integrating with systemd. Users can also develop custom modules to add highly specific boot-time requirements.

DEFAULT IMAGE LOCATION

By default, dracut places the generated initramfs image in the /boot directory, typically named initramfs-<kernel_version>.img. The bootloader (like GRUB) is then configured to load this specific image along with the kernel during startup.

HISTORY

dracut was developed by Harald Hoyer of Red Hat and first introduced around 2009. It emerged as a modern, modular, and more flexible successor to the traditional mkinitrd utility. Its design emphasizes simplicity, auto-detection of necessary components, and a highly modular, script-based approach to building the initramfs. This made it easier to manage and extend across various Linux distributions and hardware configurations, leading to its widespread adoption in distributions like Fedora, RHEL, and CentOS.

SEE ALSO

mkinitrd(8), initramfs(7), lsinitrd(8), kernel(7), modprobe(8)

Copied to clipboard