LinuxCommandLibrary

mkinitcpio

Create initial RAM disk environment

TLDR

Perform a dry run (print what would be done without actually doing it)

$ mkinitcpio
copy

Generate ramdisk environments based on all existing presets (used to regenerate all the initramfs images after a change in /etc/mkinitcpio.conf)
$ sudo mkinitcpio [[-P|--allpresets]]
copy

Generate a ramdisk environment based on the linux preset
$ sudo mkinitcpio [[-p|--preset]] [linux]
copy

Generate a ramdisk environment based on the linux-lts preset
$ sudo mkinitcpio [[-p|--preset]] [linux-lts]
copy

Generate an initramfs image using an alternative configuration file
$ sudo mkinitcpio [[-c|--config]] [path/to/mkinitcpio.conf] [[-g|--generate]] [path/to/initramfs.img]
copy

Generate an initramfs image for a kernel other than the one currently running (the installed kernel releases can be found in /usr/lib/modules/)
$ sudo mkinitcpio [[-k|--kernel]] [kernel_version] [[-g|--generate]] [path/to/initramfs.img]
copy

List all available hooks
$ mkinitcpio [[-L|--listhooks]]
copy

Display help for a specific hook
$ mkinitcpio [[-H|--hookhelp]] [hook_name]
copy

SYNOPSIS

mkinitcpio [options] [image]

PARAMETERS

-c
    Use as an alternative config file.

-d


    Use as an alternative hook directory.

-g
    Generate initramfs image.

-k
    Use kernel version to create image.

-m
    Add kernel module to the image.

-H
    Add hook to the image.

-p
    Use preset from /etc/mkinitcpio.d/

-r
    Use modules from to create image.

-S
    Set the kernel version string.

-t
    Print what would be done to standard output.

-u
    Update all initramfs images for the current kernel.

-A
    Update initramfs image for kernel .

-v
    Be verbose.

-V
    Print version and exit.

-X
    Disable auto-compression.

-h
    Show help.

DESCRIPTION

mkinitcpio is a command-line tool used to create initial ramdisk environments, also known as initrd images, which are necessary for booting a Linux system.
An initrd is a small filesystem that is loaded into memory by the bootloader before the root filesystem is mounted. It contains essential device drivers and utilities that are needed to mount the root filesystem and complete the boot process.
mkinitcpio reads configuration files located in /etc/mkinitcpio.conf and /etc/mkinitcpio.d/ to determine which modules and hooks to include in the initrd image. The modules are kernel modules providing hardware support, filesystems etc. while the hooks are shell scripts doing a variety of tasks at different stages of the initrd creation, such as compressing the image, adding files or generating configuration files.
mkinitcpio allows for highly customized initrd images, enabling users to tailor the boot process to their specific hardware and software configurations. This customization is important for systems with non-standard hardware or complex boot requirements, such as encrypted root partitions or custom filesystem configurations.
The output is a cpio archive which optionally can be compressed (default compression method is gzip).

CAVEATS

Using incorrect configurations with mkinitcpio can render your system unbootable. Ensure you understand the implications of changes made to mkinitcpio.conf or custom hooks.

CONFIGURATION FILES

/etc/mkinitcpio.conf: Main configuration file for mkinitcpio.
/etc/mkinitcpio.d/*.preset: Configuration presets defining kernel versions and image filenames.

HOOKS

Hooks are shell scripts which are executed at different stages of initrd creation. They can perform actions such as copying files, generating configuration files, or setting up networking. They are placed under /usr/lib/initcpio/hooks/.

HISTORY

mkinitcpio has evolved as a replacement for older initrd generation tools. It was designed to be more flexible and configurable, allowing for better adaptation to modern Linux systems with diverse hardware configurations. It is widely used in Arch Linux and other distributions to generate initrd images.

SEE ALSO

dracut(8), bootctl(1)

Copied to clipboard