[Linux] Initramfs Guide
Introduction
To boot a Linux OS on an ARMv8 architecture CPU, at least three components must be present:
- A bootloader to initiate the kernel (often U-Boot).
- The Linux kernel itself.
- A root file system (RootFS).
Initramfs (Initial RAM File System) acts as a bridge before the final file system is mounted. It is a RAM-based file system that identifies and mounts essential devices. Once the basic configuration is complete, it performs a pivot_root to transition to the main file system, such as Ubuntu.
For a method to boot without Initramfs, refer to: Booting Linux without Initramfs (Note: This is a legacy method used before Initramfs became standard.)
In contrast, the modern approach involves creating a file system tree, adding an init script, and packaging it using the mkimage command. Ensure that CONFIG_BLK_DEV_INITRD is enabled in your kernel configuration:
CONFIG_BLK_DEV_INITRD=y
mkimage
mkimage is part of the u-boot-tools package. It is used to wrap the file system image with a header that U-Boot understands.
Creating Initramfs
- Prepare your root directory structure.
- Create an
initscript. - Package it using
cpioandgzip. - Wrap it with
mkimage.
# Example command
find . | cpio -H newc -o | gzip -9 > ../initramfs.cpio.gz
mkimage -A arm64 -O linux -T ramdisk -d ../initramfs.cpio.gz ../initramfs.uimg
Leave a comment