initrd (initialisation RAM disk)
What are initramfs and initrd?
initrd and initramfs are temporary root filesystems loaded into memory during the early Linux boot process. Their purpose is to provide the kernel with the necessary drivers, modules, and scripts needed to initialize hardware and mount the real root filesystem before the full operating system loads.
What is initrd (Initial RAM Disk)?
A legacy method using a compressed block device image containing a temporary filesystem. The kernel mounts this image as a virtual disk early in the boot process to access drivers and scripts needed for hardware initialization and mounting the real root filesystem.
What is initramfs (Initial RAM Filesystem)
A modern method using a compressed cpio archive that the kernel unpacks directly into a RAM-based filesystem (tmpfs). It serves the same purpose as initrd but is simpler, faster, and more flexible, becoming the standard approach on most current Linux systems.
Where are initrd & initramfs files stored?
/boot
Naming of initrd/initramfs files can vary between distributions. Some distributions such as Ubuntu will preface the name of an initrd/initramfs file with initrd.img regardless of which type it is. Other distributions will call name the initramfs files differently, typically initramfss.img.
initrd.img-5.15.0-106-generic
You can check whether the file is actually an initrd or initramfs file by using the file command;
initramfs (cpio archive):
file /boot/initrd.img-$(uname -r)
/boot/initrd.img-5.15.0-113-generic: ASCII cpio archive (SVR4 with no CRC)
To check which initrd file is currently being treated as the primary one (which will be loaded on boot), you can check the symlinks (in /boot), as below:
initrd.img -> initrd.img-5.15.0-107-generic
initrd.img.old -> initrd.img-5.15.0-106-generic
Creating an initrd file (mkinitrd)
mkinitrd is a command used for creating or modifying an initrd. mkinitrd is typically used on much older systems. Modern systems have tools in place to automatically detect the modules required for the ram disk.
mkinitrd [options] initrdimagename kernel.version
mkinitrd -f /boot/initrd-$(uname -r).img $(uname -r)
| Option | Function |
| --preload=modulename | Load a module in the initrd image before the loading of other modules. |
| --with=modulename | Load a module in the initrd image after the loading of other modules. |
| -f | Overwrite an existing initrd image file. |
| -nocompress | Disable the compression of the initrd image. |
Creating an initramfs file (dracut)
the dracut command is used for creating or modifying a initramfs file.
dracut /boot/initramfs-$(uname -r).img $(uname -r)
No Comments