dracut

dracut 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. Upon installing linux, you can choose between mkinitcpio and dracut. dracut is used by Fedora, RHEL, Gentoo, and Debian, among others. Arch uses mkinitcpio by default.

You can read the full project documentation for dracut in the kernel documentation.

Installation

Install the dracut package, or dracut-gitAUR for the latest development version.

Tip: If dracut works on your machine after you test it, you can uninstall mkinitcpio.

Usage

is easy to use and typically does not require user configuration, even when using non-standard setups, like LVM on LUKS.

To generate an initramfs for the running kernel:

# dracut --hostonly --no-hostonly-cmdline /boot/initramfs-linux.img

To generate a fallback initramfs run:

# dracut /boot/initramfs-linux-fallback.img
refers to the output image file. If you are using the non-regular kernel, consider changing the file name. For example, for the  kernel, the output file should be named . However, you can name these files whatever you wish as long as your boot loader configuration uses the same file names.

Additional options

The --force flag overwrites the image file if it is already present.

The option specifies which kernel to use. The argument to this option must match the name of a directory present in .

More flags can be found with .

Advanced configuration

can be configured by directly passing arguments on the command line (see ). If you wish to always execute  with a certain set of flags, you can save a specified configuration in a  file in . For example:
/etc/dracut.conf.d/myflags.conf
hostonly="yes"
compress="lz4"
add_drivers+=" i915 "
omit_dracutmodules+=" network iscsi "

You can see more configuration options with . Fuller descriptions of each option can be found with . We will describe a few common options in what follows.

Dracut modules

dracut uses a modular approach to build the initramfs (see ). All of dracut 's builtin modules are located in and can be listed with dracut --list-modules. Extra modules can be provided by external packages e.g. . dracut 's built-in modules unfortunately lack documentation, although their names can be self-explanatory.

Some of the modules are active/inactive by default, and can be activated/deactivated with / command line argument or with the / persistent config entry lines.

TPM2

To make use of systemd 's unlocking of luks2 encrypted volumes using TPM2 through systemd-cryptenroll, enable the dracut module.

Early kernel module loading

Dracut enables early loading (at the initramfs stage, via ) through it's --force_drivers command or config entry line. For example:

/etc/dracut.conf.d/myflags.conf
# ...
force_drivers+=" nvidia nvidia_modeset nvidia_uvm nvidia_drm "
# ...

Kernel command line options

Kernel command line options can be placed in a .conf file in , and set via the flag. Dracut will automatically source this file and create a file and place it inside the initramfs directory . For example, your kernel command line options file could look like:

Miscellaneous notes

It is not necessary to specify the root block device for . From :

The root device used by the kernel is specified in the boot configuration file on the kernel command line, as always.

However, it may be useful to set some parameters early, and you can enable additional features like prompting for additional command line parameters. See for all options. Here are some example configuration options:

  • Resume from a swap partition:
  • Prompt for additional kernel command line parameters:
  • Print informational output even if "quiet" is set:

Unified kernel image

dracut can produce unified kernel images with the --uefi command line option or with the configuration option.

Tips and tricks

View information about generated image

You can view information about a generated initramfs image, which you may wish to view in a pager:

# lsinitrd /path/to/initramfs_or_uefi_image | less

This command will list the arguments passed to when the image was created, the list of included modules, and the list of all included files.

Change compression program

To reduce the amount of time spent compressing the final image, you may change the compression program used.

Simply add any one of the following lines (not multiple) to your dracut configuration:

compress="cat"
compress="gzip"
compress="bzip2"
compress="lzma"
compress="xz"
compress="lzo"
compress="lz4"
compress="zstd"

gzip is the default compression program used. will make the initramfs with no compression.

You can also use a non-officially-supported compression program:

compress="program"

Generate a new initramfs on kernel upgrade

It is possible to automatically generate new initramfs images upon each kernel upgrade. The instructions here are for the default linux kernel, but it should be easy to add extra hooks for other kernels.

As the command to figure out the kernel version is somewhat complex, it will not work by itself in a pacman hook. So create a script anywhere on your system. For this example it will be created in .

The script will also copy the new kernel file to , since the kernel packages do not place files in anymore.

/usr/local/bin/dracut-remove.sh
#!/usr/bin/env bash

while read -r line; do
	if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
		read -r pkgbase < "/${line}"
		rm -f "/boot/vmlinuz-${pkgbase}" "/boot/initramfs-${pkgbase}.img" "/boot/initramfs-${pkgbase}-fallback.img"
	fi
done

You need to make the scripts executable. If you wish to add or remove flags, you should add them to your dracut configuration.

The next step is creating pacman hooks:

You should stop mkinitcpio from creating and removing initramfs images as well, either by removing or with the following commands:

# ln -sf /dev/null /etc/pacman.d/hooks/90-mkinitcpio-install.hook
# ln -sf /dev/null /etc/pacman.d/hooks/60-mkinitcpio-remove.hook

Troubleshooting

Hibernation

If resuming from hibernation does not work, you may need to configure to include the module. You will need to add a configuration file:

LVM / software RAID / LUKS

If the kernel has issues auto discovering and mounting LVM / software RAID / LUKS blocks. You can retry generating an initramfs with the following kernel command line options:

rd.auto rd.lvm=1 rd.dm=1 rd.md=1 rd.luks=1

A stop job is running for "brltty"

If you have issues booting or very long shutdown processes while the system waits for brllty, add the following to the dracut configuration line:

omit_dracutmodules+=" brltty "

Alternatively, uninstall if it is not needed.

gollark: <@734140198236979302> <@399479031331946496> <@734160436194181170> e
gollark: +>markov
gollark: +>markov
gollark: +>markov
gollark: +>markov

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.