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
For mounting LVM:
Check disks for physical volumes:
sudo pvscan
Check disks for volume groups:
sudo vgscan
Mount volume groups:
sudo vgchange -a y
(attach, yes)Mount a specific volume group:
sudo vgchange -a y <volume group name>
Unmount a volume group:
sudo vgchange -a n
(attach, no)Volumes are typically mounted under
/dev/mapper/
with the form:/dev/mapper/<VGname>/<LVname>
or
/dev/mapper/<VGname>--<LVname>
I've seen the latter form in
/etc/fstab
sometimes although the device mapper will also usually create/dev/<VGname>/<LVname>
which is nicer to type when mounting (e.g.sudo mount /dev/my-first-volume-group/root /mnt/target/
). Stack Exchange, reddit, etc has stories of issues using/dev/<VGname>...
and recommend using/dev/mapper/...
For dealing with UEFI EFI missing (on an x86_64 machine & before
dracut ...
&grub2-mkconfig ...
):sudo dnf reinstall grub2-efi-x64 grub2-common
If you're using secure boot, add
shim-x64
to the above and run thedracut ...
andgrub2-mkconfig ...
commands.