This guide describes process of re-generating initramfs of Linux installation using chroot (for example, using a Live USB). Such manpilations may be useful, for example, in case the system fails to boot after changing of disks, cryptsetup partitions, re-created partitions with changed UUIDs.
Tesed on:
- Fedora 41 (Legacy BIOS & UEFI)
- Ubuntu 24.04, 24.10 (UEFI)
Assume some rescue Linux system is running and has access to the system disk.
Lets ssume the layout of the systm is the following:
/dev/sda1 - EFI partition
/dev/sda2 - /boot (unencrypted)
/dev/sda3 - / encrypted with LUKS
/dev/sda4 - /home encrypted with LUKS
Unencrypt LUKS partitions with cryptsetup. Names of luks partitions should be the same as in /etc/crypttab
file.
sudo cryptsetup open /dev/sda3 luks-01234567-89ab-cdef-0123-456789abcdef
sudo cryptsetup open /dev/sda4 luks-fedcba98-7654-3210-fedc-ba9876543210
Create folder for mounting the root and mount sub-folders
mkdir /mnt/target
sudo mount /dev/mapper/luks-01234567-89ab-cdef-0123-456789abcdef /mnt/target
sudo mount /dev/mapper/luks-fedcba98-7654-3210-fedc-ba9876543210 /mnt/target/home
sudo mount /dev/sda2 /mnt/target/boot
sudo mount /dev/sda1 /mnt/target/efi # Not needed in case of Legacy BIOS setup
Important. Mount /proc
, /sys
and /dev
from the main system so that it can be safelly unmounted afterwards
(if Live USB is based on systemd there will be a lot of implicit mounts in the subfolders).
sudo mount -t proc /proc /mnt/target/proc
sudo mount --rbind /dev /mnt/target/dev
sudo mount --make-rslave /mnt/target/dev
sudo mount --rbind /sys /mnt/target/sys
sudo mount --make-rslave /mnt/target/sys
Chroot to the mounted system
sudo chroot /mnt/target
For Ubuntu:
update-grub
update-initramfs -k all -c
For Fedora (UEFI):
dracut --regenerate-all --force
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
For Fedora (legacy BIOS):
dracut --regenerate-all --force
grub2-mkconfig -o /boot/grub2/grub.cfg
Exit chroot system and unmount the fs tree
sudo umount --recursive /mnt/target/sys
sudo umount --recursive /mnt/target/dev
sudo umount /mnt/target/proc
sudo umount /mnt/target/home
sudo umount /mnt/target/boot
sudo umount /mnt/target
Re-lock LUKS partitions
sudo cryptsetup close luks-01234567-89ab-cdef-0123-456789abcdef
sudo cryptsetup close luks-fedcba98-7654-3210-fedc-ba9876543210
Restart the system.
- Mounting LVM