mkinitcpio

On this page 7

mkinitcpio is the Bash-based tool that generates the initramfs image on Arch Linux and distributions derived from it, such as Manjaro and EndeavourOS. The image it produces is a compressed cpio archive that the boot loader passes to the kernel, and it contains the minimal userspace needed to find, unlock and mount the real root filesystem.

In Linux system initialization, mkinitcpio occupies the step between the boot loader and the init system. GRUB or systemd-boot loads the kernel and the image, the code inside the image prepares storage, and control then passes to systemd or another init system on the real root. Its counterpart on Fedora, RHEL and many other distributions is dracut.

How mkinitcpio builds an initramfs

mkinitcpio works from a configuration file and a set of presets. The main file, /etc/mkinitcpio.conf or drop-ins in /etc/mkinitcpio.conf.d/, lists modules, binaries, extra files and an ordered array of hooks. Presets in /etc/mkinitcpio.d/, one per installed kernel such as linux.preset, define which kernel version to target and where to write the output.

During a build, mkinitcpio runs each hook’s build script, which copies kernel modules, binaries, libraries and udev rules into a temporary directory. It resolves shared library dependencies automatically, then packs the tree into a cpio archive and compresses it. The result is typically written to /boot/initramfs-linux.img, or embedded in a Unified Kernel Image when UKI output is configured.

Arch packaging triggers this process automatically: a pacman hook regenerates the images whenever a kernel package or a relevant module package is installed or upgraded. Manual runs are needed after editing the configuration, usually with mkinitcpio -P to rebuild every preset.

Configuration variables and hooks

The configuration file is a Bash fragment with a few arrays. Each variable controls a distinct part of the image, as the following table summarizes.

VariableContentEffect
MODULESKernel module namesForces modules into the image and loads them early
BINARIESExecutable pathsAdds tools with their libraries
FILESArbitrary file pathsAdds keyfiles or configuration
HOOKSOrdered hook namesDefines the build and runtime logic
COMPRESSIONzstd, gzip, xz, lz4 and othersSets image compressor; zstd is the default
COMPRESSION_OPTIONSCompressor flagsTunes level and threads
Main variables in mkinitcpio.conf

Hooks carry the real logic, and their order matters because each runs in sequence at boot. Since 2023, the default configuration uses a systemd-based initramfs, replacing the older Busybox-based init; the two families use different hook names.

Busybox hooksystemd hookPurpose
basebase (optional)Basic directory layout and utilities
udevsystemdDevice detection and module loading
autodetectautodetectShrinks image to modules this machine needs
keyboard, keymapkeyboard, sd-vconsoleInput for passphrase prompts
encryptsd-encryptUnlocks LUKS-encrypted root
lvm2lvm2Activates LVM volume groups
block, filesystemsblock, filesystemsStorage and filesystem drivers
fsckfsckChecks root before mounting
Common hooks and their roles

mkinitcpio compared with other initramfs generators

All mainstream generators produce the same kind of artifact, but they differ in design philosophy, default distribution and extension model. The comparison below helps when moving between distributions.

ToolMain distributionsExtension modelNotable trait
mkinitcpioArch, Manjaro, EndeavourOSHooks in shellSimple, explicit configuration
dracutFedora, RHEL, openSUSE, Gentoo optionModules in shellHighly automatic, systemd-centric
initramfs-toolsDebian, UbuntuHook and script directoriesLong-standing Debian design
boosterArch alternativeGo binary with YAMLVery fast builds and boot
ukifyAny systemd systemAssembles UKI from partsCombines kernel, initramfs and command line
Initramfs generators on Linux

dracut and booster are available in the official Arch repositories as alternatives, but mkinitcpio remains the default on a fresh installation. Mixing two generators on the same system is a common source of stale or duplicated images.

Typical tasks and commands

Most administration with mkinitcpio involves adding a hook or module and rebuilding. Several commands cover nearly every situation.

  • mkinitcpio -P rebuilds all presets, the usual step after editing the configuration.
  • mkinitcpio -p linux-lts rebuilds one preset, for example the LTS kernel only.
  • mkinitcpio -L lists available hooks, and mkinitcpio -H encrypt shows help for one hook.
  • lsinitcpio -a /boot/initramfs-linux.img analyzes an existing image and lists its modules and hooks.
  • The fallback image is built without autodetect, so it contains broad driver coverage for recovery.

The configuration needed depends on the storage stack. The decision table below lists typical changes for common setups using the systemd-based initramfs.

SetupRequired changeReason
LUKS-encrypted rootAdd sd-encrypt before filesystemsRoot must be unlocked before mounting
Root on LVMAdd lvm2 before filesystemsVolume group must be active
NVIDIA early KMSAdd nvidia modules to MODULESDisplay driver loads before the console starts
Btrfs multi-device rootEnsure btrfs support via filesystems hookAll devices must be scanned
Non-US keyboard and passphraseAdd sd-vconsole before sd-encryptCorrect keymap at the prompt
Configuration changes for common setups

Common failures and recovery

When an initramfs is wrong, the system usually drops to an emergency shell with a message that the root device cannot be found. The cause is almost always a missing driver or a misordered hook rather than damage to the root filesystem itself.

  • Mixing Busybox and systemd hooks, such as encrypt with systemd, leaves the passphrase prompt missing.
  • The autodetect hook built on a live medium or in a chroot may omit drivers the target hardware needs; boot the fallback image.
  • A full /boot partition causes silent build failures; check free space before kernel upgrades.
  • Kernel command line parameters must match the initramfs type, for example rd.luks.name= for sd-encrypt and cryptdevice= for encrypt.
  • Recovery normally means booting installation media, using arch-chroot to enter the system, fixing the configuration and running mkinitcpio -P.

Explained without jargon

When a Linux computer starts, the kernel needs to reach the disk that holds the operating system, but the tools to do that may themselves live on that disk. mkinitcpio solves this chicken-and-egg problem by packing a small starter kit that is loaded together with the kernel.

The kit holds just enough to recognize the disk, ask for an encryption password if needed and open the main system. Think of it as the key ring you carry outside the house so you can open the front door. If the right key is missing from the ring, the computer stops at the door and waits for help.

A typical use case

A developer installs Arch Linux on a laptop with a LUKS-encrypted root partition on an NVMe drive and a German keyboard layout. After the base installation, the first reboot stops at an emergency shell because the default configuration does not open the encrypted volume.

Booting the installation medium again, the developer enters the system with arch-chroot and edits the HOOKS array to systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt filesystems fsck. The boot entry gets rd.luks.name= with the partition UUID, and mkinitcpio -P rebuilds both the default and fallback images. On the next start, the passphrase prompt appears with the correct German layout, the volume unlocks and the system boots normally in about eight seconds. The developer also keeps the fallback entry in the boot menu as a safety net for future hardware changes.