- The initial ramdisk is in essence a very small environment (early userspace) which loads various kernel modules and sets up necessary things before handing over control to
init. This makes it possible to have, for example, encrypted root file systems and root file systems on a software RAID array. mkinitcpio allows for easy extension with custom hooks, has autodetection at runtime, and many other features.
Traditionally, the kernel was responsible for all hardware detection and initialization tasks early in the boot process before mounting the root file system and passing control to
init. However, as technology advances, these tasks have become increasingly complex.
Nowadays, the root file system may be on a wide range of hardware, from SCSI to SATA to USB drives, controlled by a variety of drive controllers from different manufacturers. Additionally, the root file system may be encrypted or compressed; within a software RAID array or a logical volume group. The simple way to handle that complexity is to pass management into userspace: an initial ramdisk. See also: /dev/brain0 » Blog Archive » Early Userspace in Arch Linux.
mkinitcpio has been developed by the Arch Linux developers and from community contributions. See the public Git repository.
Install the package, which is a dependency of the package, so most users will already have it installed.
Advanced users may wish to install the latest development version of mkinitcpio from Git with theAUR package.
Image creation and activation
Every time a kernel is installed or upgraded, a pacman hook automatically generates a .preset file saved in
/etc/mkinitcpio.d/. For example
linux.preset for the official stable kernel package. A preset is simply a list of information required to create initial ramdisk images, instead of manually specifying the various parameters and the location of the output files.
By default, it contains the instructions to create two images:
- the default ramdisk image created following the directives specified in the mkinitcpio #Configuration, and
- the fallback ramdisk image, same as above except that the autodetect hook is skipped during creation, thus including a full range of modules which supports most systems.
After creating the preset, the pacman hook calls the mkinitcpio script which generates the two images, using the information provided in the preset.
To run the script manually, refer to the
--preset option followed by the preset to utilize. For example, for the package, use the command:
# mkinitcpio -p linux
To (re-)generate all existing presets, use the
--allpresets switch. This is typically used to regenerate all the initramfs images after a change of the global #Configuration:
# mkinitcpio -P
Users may create any number of initramfs images with a variety of different configurations. The desired image must be specified in the respective boot loader configuration file.
Users can generate an image using an alternative configuration file. For example, the following will generate an initial ramdisk image according to the directions in
/etc/mkinitcpio-custom.conf and save it as
# mkinitcpio --config /etc/mkinitcpio-custom.conf --generate /boot/initramfs-custom.img
If generating an image for a kernel other than the one currently running, add the kernel release version to the command line. The installed kernel releases can be found in
/usr/lib/modules/, the syntax is consistent with the output of the command
uname -r for each kernel.
# mkinitcpio --generate /boot/initramfs-custom2.img --kernel 5.7.12-arch1-1
Unified kernel images
As of version 31, mkinitpcio can also create unified kernel images.
The primary configuration file for mkinitcpio is
/etc/mkinitcpio.conf. Additionally, preset definitions are provided by kernel packages in the
/etc/mkinitcpio.d directory (e.g.
Users can modify six variables within the configuration file, seefor more details:
- Kernel modules to be loaded before any boot hooks are run.
- Additional binaries to be included in the initramfs image.
- Additional files to be included in the initramfs image.
- Hooks are scripts that execute in the initial ramdisk.
- Used to compress the initramfs image.
- Extra arguments to pass to the
COMPRESSIONprogram. Usage of this setting is strongly discouraged. mkinitcpio will handle special requirements for compressors (e.g. passing
--check=crc32to xz), and misusage can easily lead to an unbootable system.
- Some hooks that may be required for your system like lvm2, mdadm_udev, and encrypt are NOT enabled by default. Read the #HOOKS section carefully for instructions.
- Users with multiple hardware disk controllers that use the same node names but different kernel modules (e.g. two SCSI/SATA or two IDE controllers) should use persistent block device naming to ensure that the right devices are mounted. Otherwise, the root device location may change between boots, resulting in kernel panics.
MODULES array is used to specify modules to load before anything else is done.
Modules suffixed with a
? will not throw errors if they are not found. This might be useful for custom kernels that compile in modules which are listed explicitly in a hook or configuration file.
- If using reiser4, it must be added to the
- When using the encrypt or sd-encrypt hook, the keyboard modules and/or filesystems needed to unlock the LUKS device during system boot need to be added to the
MODULESarray when the target system differs from the one used to run mkinitcpio. For example, if you use a keyfile on an ext2 file system but no ext2 file system is mounted at the time mkinitcpio runs, add
ext2. See dm-crypt/System configuration#cryptkey for more details.
- If using a keyboard through a USB 3 hub and wish to use it to unlock a LUKS device, add
- If using displays connected to a docking station, you might need to add a module for your graphic card to make initrd output visible (e.g.
i915for most Intel cards).
BINARIES and FILES
These options allow users to add files to the image. Both
FILES are added before hooks are run, and may be used to override files used or provided by a hook.
BINARIES are auto-located within a standard
PATH and are dependency-parsed, meaning any required libraries will also be added.
FILES are added as-is. For example:
Note that as both
FILES are Bash arrays, multiple entries can be added delimited with spaces.
HOOKS array is the most important setting in the file. Hooks are small scripts which describe what will be added to the image. For some hooks, they will also contain a runtime component which provides additional behavior, such as starting a daemon, or assembling a stacked block device. Hooks are referred to by their name, and executed in the order they exist in the
HOOKS array of the configuration file.
HOOKS setting should be sufficient for most simple, single disk setups. For root devices which are stacked or multi-block devices such as LVM, RAID, or dm-crypt, see the respective wiki pages for further necessary configuration.
Build hooks are found in
/usr/lib/initcpio/install/, custom build hooks can be placed in
/etc/initcpio/install/. These files are sourced by the bash shell during runtime of mkinitcpio and should contain two functions:
build function describes the modules, files, and binaries which will be added to the image. An API, documented by , serves to facilitate the addition of these items. The
help function outputs a description of what the hook accomplishes.
For a list of all available hooks:
$ mkinitcpio -L
--hookhelp option to output help for a specific hook, for example:
$ mkinitcpio -H udev
Runtime hooks are found in
/usr/lib/initcpio/hooks/, custom runtime hooks can be placed in
/etc/initcpio/hooks/. For any runtime hook, there should always be a build hook of the same name, which calls
add_runscript to add the runtime hook to the image. These files are sourced by the busybox ash shell during early userspace. With the exception of cleanup hooks, they will always be run in the order listed in the
HOOKS setting. Runtime hooks may contain several functions:
run_earlyhook: Functions of this name will be run once the API file systems have been mounted and the kernel command line has been parsed. This is generally where additional daemons, such as udev, which are needed for the early boot process are started from.
run_hook: Functions of this name are run shortly after the early hooks. This is the most common hook point, and operations such as assembly of stacked block devices should take place here.
run_latehook: Functions of this name are run after the root device has been mounted. This should be used, sparingly, for further setup of the root device, or for mounting other file systems, such as
run_cleanuphook: Functions of this name are run as late as possible, and in the reverse order of how they are listed in the
HOOKS array in the configuration file. These hooks should be used for any last minute cleanup, such as shutting down any daemons started by an early hook.
A table of common hooks and how they affect image creation and runtime follows. Note that this table is not complete, as packages can provide custom hooks.
|busybox init||systemd init||Build hook||Runtime hook (busybox init only)|
|base||Sets up all initial directories and installs base utilities and libraries. Always keep this hook as the first hook unless you know what you are doing, as it provides critical busybox init when not using systemd hook.
Optional when using the systemd hook as it only provides a busybox recovery shell.
|udev||systemd||Adds udevd, udevadm, and a small subset of udev rules to your image.||Starts the udev daemon and processes uevents from the kernel; creating device nodes. As it simplifies the boot process by not requiring the user to explicitly specify necessary modules, using it is recommended.|
|usr||Adds support for
||Mounts the |
|resume||–||Tries to resume from the "suspend to disk" state. See Hibernation for further configuration.|
|btrfs||--||Sets the required modules to enable Btrfs for using multiple devices with Btrfs. You need to have installed to use this. This hook is not required for using Btrfs on a single device.||Runs |
|autodetect||Shrinks your initramfs to a smaller size by creating a whitelist of modules from a scan of sysfs. Be sure to verify included modules are correct and none are missing. This hook must be run before other subsystem hooks in order to take advantage of auto-detection. Any hooks placed before 'autodetect' will be installed in full.||–|
|modconf||Includes modprobe configuration files from
|block||Adds all block device modules, formerly separately provided by the fw, mmc, pata, sata, scsi, usb, and virtio hooks.||–|
|net||not implemented||Adds the necessary modules for a network device. You must have #Using net for details.installed to use this, see||Provides handling for an NFS-based root file system.|
|dmraid||?||Provides support for fakeRAID root devices. You must have mdadm with the mdadm_udev hook with fakeRAID if your controller supports it. See #Using RAID for details.installed to use this. Note that it is preferred to use||Locates and assembles fakeRAID block devices using |
|mdadm_udev||Provides support for assembling RAID arrays via udev. You must have
installed to use this. If you use this hook with a FakeRAID array, it is recommended to include ||–|
|keyboard||Adds the necessary modules for keyboard devices. Use this if you have an USB or serial keyboard and need it in early userspace (either for entering encryption passphrases or for use in an interactive shell). As a side effect, modules for some non-keyboard input devices might be added too, but this should not be relied on. Supersedes old usbinput hook.
Note: For systems that are booted with different hardware configurations (e.g. laptops with external keyboard vs. internal keyboard or headless systems), this hook needs to be placed before autodetect in order to be able to use the keyboard at boot time, for example to unlock an encrypted device when using the
|keymap||sd-vconsole||Adds the specified keymap(s) from
||Loads the specified keymap(s) from |
|consolefont||Adds the specified console font from
||Loads the specified console font from |
Note: Take notice of the remarks for the keyboard hook above to unlock an encrypted device during boot, and/or the filesystem remarks in #MODULES when you use a file to unlock.
|Detects and unlocks an encrypted root partition. See #Runtime customization for further configuration.
For sd-encrypt see dm-crypt/System configuration#Using sd-encrypt hook.
|lvm2||Adds the device mapper kernel module and the
|fsck||Adds the fsck binary and file system-specific helpers to allow running fsck against your root device (and
The use of this hook requires the
|filesystems||This includes necessary file system modules into your image. This hook is required unless you specify your file system modules in
The kernel supports several formats for compression of the initramfs:
-T0 option which spawns as many threads as detected cores).
mkinitcpio.conf has the various
COMPRESSION options commented out. Uncomment one if you wish to switch to another compression method and make sure you have the corresponding compression utility installed. If none is specified, the zstd default method is used. If you wish to create an uncompressed image, specify
COMPRESSION=cat in the configuration file or use
-z cat on the command line.
-9), lz4 achieves the fastest decompression speed at the cost of a slower single-threaded compression. For a slightly better compression, lzo is still fast to decompress. zstd offers a versatile solution, with multi-threaded compression and a wide range of compression levels through its options — see . xz achieves the smallest size with a reduction factor around 5 in its high compression preset (
-9), at the cost of a much slower decompression speed.
These are additional flags passed to the program specified by
COMPRESSION, such as:
Runtime configuration options can be passed to
init and certain hooks via the kernel command line. Kernel command-line parameters are often supplied by the bootloader. The options discussed below can be appended to the kernel command line to alter default behavior. See Kernel parameters and Arch boot process for more information.
init from base hook
- This is the most important parameter specified on the kernel command line, as it determines what device will be mounted as your proper root device. mkinitcpio is flexible enough to allow a wide variety of formats, for example:
root=/dev/sda1 # /dev node root=LABEL=CorsairF80 # label root=UUID=ea1c4959-406c-45d0-a144-912f4e86b207 # UUID root=PARTUUID=14420948-2cea-4de7-b042-40f67c618660 # GPT partition UUIDNote: The following boot parameters alter the default behavior of
initin the initramfs environment. See
/usr/lib/initcpio/initfor details. They will not work when
systemdhook is being used since the
basehook is replaced.
initpauses the boot process (after loading hooks, but before mounting the root file system) and launches an interactive shell which can be used for troubleshooting purposes. This shell can be launched after the root has been mounted by specifying
break=postmount. Normal boot continues after exiting from the shell.
- Disable hooks at runtime by adding
disablehooks=hook1[,hook2,...]. For example:
- Alter the order in which modules are loaded by specifying modules to load early via
earlymodules=mod1[,mod2,...]. (This may be used, for example, to ensure the correct ordering of multiple network interfaces.)
See Boot debugging and for other parameters.
net requires the package.
Comprehensive and up-to-date information can be found in the official kernel documentation.
This parameter tells the kernel how to configure IP addresses of devices and also how to set up the IP routing table. It can take up to nine arguments separated by colons:
If this parameter is missing from the kernel command line, all fields are assumed to be empty, and the defaults mentioned in the kernel documentation apply. In general this means that the kernel tries to configure everything using autoconfiguration.
<autoconf> parameter can appear alone as the value to the
ip parameter (without all the
: characters before). If the value is
ip=none, no autoconfiguration will take place, otherwise autoconfiguration will take place. The most common way to use this is
For parameters explanation, see the kernel documentation.
ip=127.0.0.1:::::lo:none --> Enable the loopback interface. ip=192.168.1.1:::::eth2:none --> Enable static eth2 interface. ip=:::::eth0:dhcp --> Enable dhcp protocol for eth0 configuration.
eth0) for the
<device>parameter, the persistent names (e.g.
enp2s0) will not work. See Network configuration#Network interfaces for details.
If you have multiple network cards, this parameter can include the MAC address of the interface you are booting from. This is often useful as interface numbering may change, or in conjunction with pxelinux IPAPPEND 2 or IPAPPEND 3 option. If not given,
eth0 will be used.
BOOTIF=01-A1-B2-C3-D4-E5-F6 # Note the prepended "01-" and capital letters.
nfsroot parameter is NOT given on the command line, the default
/tftpboot/%s will be used.
mkinitcpio -H net for parameter explanation.
Using encrypted root
/usr as a separate partition
If you keep
/usr as a separate partition, you must adhere to the following requirements:
- Add the
/etc/fstabto run the check on the partition at startup. While recommended for everyone, it is mandatory if you want your
/usrpartition to be fsck'ed at boot-up. Without this hook,
/usrwill never be fsck'd.
- If not using the systemd hook, add the
usrhook. This will mount the
/usrpartition after root is mounted.
Extracting the image
If you are curious about what is inside the initramfs image, you can extract it and poke at the files inside of it.
The initramfs image is an SVR4 CPIO archive, generated via the
bsdcpio commands, optionally compressed with a compression scheme understood by the kernel. For more information on the compression schemes, see #COMPRESSION.
mkinitcpio includes a utility calledwhich will list and/or extract the contents of initramfs images.
You can list the files in the image with:
# lsinitcpio /boot/initramfs-linux.img
And to extract them all in the current directory:
# lsinitcpio -x /boot/initramfs-linux.img
You can also get a more human-friendly listing of the important parts in the image:
# lsinitcpio -a /boot/initramfs-linux.img
Recompressing a modified extracted image
build_image function of the
/usr/bin/mkinitcpio script with parameters
build_image outfile compression
It can be done by creating a new script with the contents of the
build_image function and running it with the above parameters.
This will compress the contents present in the current directory in a file named
/boot/initramfs-linux.imgbefore you overwrite it, so you can easily undo your changes. Be prepared for making a mistake that prevents your system from booting. If this happens, you will need to boot through the fallback, or a boot CD, to restore your original, run mkinitcpio to overwrite your changes, or fix them yourself and recompress the image.
"/dev must be mounted" when it already is
The test used by mkinitcpio to determine if
/dev is mounted is to see if
/dev/fd/ is there. If everything else looks fine, it can be "created" manually by:
# ln -s /proc/self/fd /dev/
/proc must be mounted as well. mkinitcpio requires that anyway, and that is the next thing it will check.)
Possibly missing firmware for module XXXX
When initramfs are being rebuild after a kernel update, you might get warnings such as:
==> WARNING: Possibly missing firmware for module: wd719x ==> WARNING: Possibly missing firmware for module: aic94xx ==> WARNING: Possibly missing firmware for module: xhci_pci
If these or similar messages only appear when generating the fallback initramfs image and you do not use the affected hardware, then you can safely ignore them.
If the messages appear when generating an initramfs image using the autodetect hook, then as the warning says, installing additional firmware may be required. Most common firmware files can be acquired by installing the package.
No PS/2 controller found
On some motherboards (mostly ancient ones, but also a few new ones), the i8042 controller cannot be automatically detected. It is rare, but some people will surely be without keyboard. You can detect this situation in advance. If you have a PS/2 port and get
i8042: PNP: No PS/2 controller found. Probing ports directly message, add atkbd to the
Standard rescue procedures
With an improper initial ram-disk a system often is unbootable. So follow a system rescue procedure like below:
Boot succeeds on one machine and fails on another
autodetect hook filters unneeded kernel modules in the primary initramfs scanning
/sys and the modules loaded at the time it is run. If you transfer your
/boot directory to another machine and the boot sequence fails during early userspace, it may be because the new hardware is not detected due to missing kernel modules. Note that USB 2.0 and 3.0 need different kernel modules.
To fix, first try choosing the fallback image from your bootloader, as it is not filtered by
autodetect. Once booted, run mkinitcpio on the new machine to rebuild the primary image with the correct modules. If the fallback image fails, try booting into an Arch Linux live CD/USB, chroot into the installation, and run mkinitcpio on the new machine. As a last resort, try manually adding modules to the initramfs.