Difference between revisions of "User:Krathalan"

From ArchWiki
Jump to navigation Jump to search
m (Fix file name)
m (Fix file name... :))
Line 105: Line 105:
 
Description = Updating linux initcpios (with dracut!)...
 
Description = Updating linux initcpios (with dracut!)...
 
When = PostTransaction
 
When = PostTransaction
Exec = /usr/bin/bash /home/username/.local/bin/90-dracut-linux.hook
+
Exec = /usr/bin/bash /home/username/.local/bin/90-dracut-linux.sh
 
NeedsTargets</nowiki>
 
NeedsTargets</nowiki>
 
}}
 
}}

Revision as of 21:00, 8 October 2019

This is a WIP draft for the dracut wiki page.

Note: Read the mailing list announcement for a possible Mkinitcpio replacement with 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.

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

Installation

dracut can be installed with the dracut package.

Usage

dracut 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 /boot/initramfs-linux.img

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

Additional flags

The --hostonly flag creates an image that only contains the files needed to boot the local host system, instead of creating a generic image with more files. Using this flag reduces the size of the generated image, but you won't be able to use it on other computers or switch to a different root file system without generating a new image.

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

More flags can be found with man dracut.

Configuration

If you wish to always execute dracut with a certain set of flags, you can save a specified configuration in a .conf file in /etc/dracut.conf.d/. 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 man dracut.conf. Fuller descriptions of each option can be found with man dracut.

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 image> | less

This command will list the arguments passed to dracut when the image was created, the list of included dracut 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/format.

Warning: Make sure your kernel has your chosen decompression support compiled in, otherwise you will not be able to boot. You must also have the chosen compression program package installed. Note that the kernels provided in the Arch repos do not support zstd compression.

Simply add any of the following flags to your dracut command:

--gzip (default)
--bzip2
--lzma
--xz
--lzo
--lz4

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

--compress <program>

Or specify no compression at all:

--no-compress

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 ~/.local/bin:

~/.local/bin/90-dracut-linux.sh
#!/bin/sh
read -r kver
kver=${kver#"usr/lib/modules/"}
kver=${kver%"/pkgbase"}
dracut <your flags> --force /boot/initramfs-linux.img --kver "${kver}"

The next step is creating a pacman hook:

/etc/pacman.d/hooks/90-dracut-linux.hook
[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Target = usr/lib/modules/*/pkgbase

[Action]
Description = Updating linux initcpios (with dracut!)...
When = PostTransaction
Exec = /usr/bin/bash /home/username/.local/bin/90-dracut-linux.sh
NeedsTargets

You can stop mkinitcpio from creating initramfs images as well:

# ln -sf /dev/null /etc/pacman.d/hooks/90-linux.hook

See also