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.
| Variable | Content | Effect |
|---|---|---|
| MODULES | Kernel module names | Forces modules into the image and loads them early |
| BINARIES | Executable paths | Adds tools with their libraries |
| FILES | Arbitrary file paths | Adds keyfiles or configuration |
| HOOKS | Ordered hook names | Defines the build and runtime logic |
| COMPRESSION | zstd, gzip, xz, lz4 and others | Sets image compressor; zstd is the default |
| COMPRESSION_OPTIONS | Compressor flags | Tunes level and threads |
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 hook | systemd hook | Purpose |
|---|---|---|
| base | base (optional) | Basic directory layout and utilities |
| udev | systemd | Device detection and module loading |
| autodetect | autodetect | Shrinks image to modules this machine needs |
| keyboard, keymap | keyboard, sd-vconsole | Input for passphrase prompts |
| encrypt | sd-encrypt | Unlocks LUKS-encrypted root |
| lvm2 | lvm2 | Activates LVM volume groups |
| block, filesystems | block, filesystems | Storage and filesystem drivers |
| fsck | fsck | Checks root before mounting |
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.
| Tool | Main distributions | Extension model | Notable trait |
|---|---|---|---|
| mkinitcpio | Arch, Manjaro, EndeavourOS | Hooks in shell | Simple, explicit configuration |
| dracut | Fedora, RHEL, openSUSE, Gentoo option | Modules in shell | Highly automatic, systemd-centric |
| initramfs-tools | Debian, Ubuntu | Hook and script directories | Long-standing Debian design |
| booster | Arch alternative | Go binary with YAML | Very fast builds and boot |
| ukify | Any systemd system | Assembles UKI from parts | Combines kernel, initramfs and command line |
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 -Prebuilds all presets, the usual step after editing the configuration.mkinitcpio -p linux-ltsrebuilds one preset, for example the LTS kernel only.mkinitcpio -Llists available hooks, andmkinitcpio -H encryptshows help for one hook.lsinitcpio -a /boot/initramfs-linux.imganalyzes 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.
| Setup | Required change | Reason |
|---|---|---|
| LUKS-encrypted root | Add sd-encrypt before filesystems | Root must be unlocked before mounting |
| Root on LVM | Add lvm2 before filesystems | Volume group must be active |
| NVIDIA early KMS | Add nvidia modules to MODULES | Display driver loads before the console starts |
| Btrfs multi-device root | Ensure btrfs support via filesystems hook | All devices must be scanned |
| Non-US keyboard and passphrase | Add sd-vconsole before sd-encrypt | Correct keymap at the prompt |
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 andcryptdevice=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.