initramfs
- initrd - old, pre-RHEL7, block based disk image
- initramfs - new, CPIO archive
- initrd vs initramfs - no fixed size, faster, easier to modify, mondern kernels expect it
lsinitramfs /boot/initrd.img-$(uname -r) # view initramfs contents
Debian / Ubuntu:
sudo update-initramfs -u # update current kernel's initramfs
sudo update-initramfs -k all -u # update for all kernels
RHEL / Fedora:
sudo dracut --force # for current kernel, force to overwrite existing image
sudo dracut --force /boot/initramfs-$(uname -r).img $(uname -r) # also for current kernel
sudo dracut --force --hostonly --add systemd # for systemd-boot
sudo dracut --force --no-hostonly /boot/initramfs-minimal.img # minimal, for any system
sudo dracut --force --hostonly /boot/initramfs-hostonly.img # just for this system
sudo dracut --force --add-drivers "nvme.ko xfs.ko" /boot/initramfs-custom.img # add xfs and nvme modules
Arch:
sudo mkinitcpio -p linux
sudo mkinitcpio -g /boot/initramfs-linux.img
Modify
Extract:
mkdir ~/initramfs-extracted
cd ~/initramfs-extracted
sudo zcat /boot/initramfs-$(uname -r).img | cpio -idmv
Pack, update, verify:
find . | cpio -o -H newc | gzip > /boot/initramfs-custom.img
sudo update-grub
lsinitramfs /boot/initramfs-$(uname -r).img | grep xxxxx # verify change
Why
Drivers for:
- RAID
- LVM
- Encrypted FS ( ex. LUKS )
- Network FS ( ex. NFS, iSCSI )
- NVMe or USB Drives !!!
Also, root FS device name may change.
Creating a universal initramfs for a bootable USB
Ubuntu / Debain Universal initramfs
sudo apt update
sudo apt install initramfs-tools busybox
Configure:
sudo nano /etc/initramfs-tools/initramfs.conf
MODULES=most
BUSYBOX=y
COMPRESS=xz # Or gzip for better compatibility
BOOT=local
DEVICE=
NFSROOT=
Add modules:
echo "ahci" >> /etc/initramfs-tools/modules
echo "ext4" >> /etc/initramfs-tools/modules
echo "vfat" >> /etc/initramfs-tools/modules
echo "usb_storage" >> /etc/initramfs-tools/modules
sudo update-initramfs -c -k all
cp /boot/initrd.img-$(uname -r) /mnt/usb/initrd.img
RHEL / Fedora Universal initramfs
sudo dnf install dracut
sudo nano /etc/dracut.conf
add_dracutmodules+=" base udev kernel-modules "
hostonly=no
compress="xz"
sudo dracut --force --add-drivers "ahci ext4 vfat usb_storage"
sudo dracut --force --no-hostonly /mnt/usb/initrd.img
Old Stuff
Manually create initrd ( obsolete ):
mkinitrd /boot/initrd-$(uname -r).img $(uname -r) # SUSE-based systems