How to chroot a system that uses btrfs subvolumes?

If you need to rescue a system, e.g. reinstall GRUB, you might need to boot from a USB stick, assemble the broken system, and chroot into it, in order to run repair commands. But the familiar /boot, /etc, /home, /var, /usr directories aren’t visible when mounting a Fedora root file system. How do I do that?

1 Like

Option 1: Use a netinstall image
These images start-up with a boot menu containing a Troubleshooting submenu, and one of the options is to rescue a Fedora system. This runs Anaconda in rescue mode. It will look at the drive for system roots, mount them, find fstab and assemble your system at /mnt/sysimage. Now you can just chroot /mnt/sysimage.

Option 2: Use your anaconda storage.log as a guide

sudo grep mount /var/log/anaconda/storage.log

The basic strategy is:

mount -o subvol=root /dev/vda3 /mnt/sysimage
mount /dev/vda2 /mnt/sysimage/boot
mount -o umask=0077,shortname=winnt /dev/vda1 /mnt/sysimage/boot/efi
mount -B /dev /mnt/sysimage/dev
mount -B /proc /mnt/sysimage/proc
mount -B /sys /mnt/sysimage/sys
chroot /mnt/sysimage

Extra info: The key thing that makes Btrfs different is the use of the subvol mount option. By default, the name of this subvolume is root. But in a custom installation it could be anything you want, so you 'd need to use the correct name. Everything you’d find in sysroot is found in this subvolume, similar to Fedora 32 and older, there was a fedora-root Logical Volume.

5 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.