Skip to content

Instantly share code, notes, and snippets.

@f4str
Created October 6, 2023 03:59
Show Gist options
  • Select an option

  • Save f4str/29437f4e8d7f0e65efc61a83287a068f to your computer and use it in GitHub Desktop.

Select an option

Save f4str/29437f4e8d7f0e65efc61a83287a068f to your computer and use it in GitHub Desktop.
Btrfs Chroot Guide

Btrfs Chroot Guide

Guide to chroot into Debian or Fedora systems to change the password and/or reinstall GRUB.

Mount Filesystems

Mount the btrfs subvolumes. Subvolumes @ and @home are required. Typically @cache, @log, and @swap are not needed.

sudo mount /dev/nvme0n1p2 /mnt -t btrfs -o subvol=@
sudo mount /dev/nvme0n1p2 /mnt/home -t btrfs -o subvol=@home

Mount the EFI partition. This assumes ESP is on /boot/efi.

sudo mount /dev/nvme0n0p1 /mnt/boot/efi

Mount the virtual filesystems.

sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /run /mnt/run

Load the efivars.

sudo modprobe efivarfs

# if above fails
sudo mount -t efivarfs none /sys/firmware/efi/efivars

Mount the efivars.

sudo mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars

You can now chroot into the system.

sudo chroot /mnt

Change Password

After chrooting in, you can change the password of any user.

passwd USER

Reinstall GRUB

On Debian systems, use the following method. Install to the drive, not the partition.

# reinstall grub package
apt install --reinstall grub-efi

# recreate grub config
grub-install /dev/nvme0n1
update-grub

On Fedora systems, use the following method.

# remove shim
rm /boot/efi/EFI/fedora/grub.cfg

# reinstall grub package
dnf reinstall grub2-efi grub2-efi-modules grub2-common shim

# recreate grub config
grub2-mkconfig -o /boot/grub2/grub.cfg
@AngeLinuX99
Copy link

Awesome !! I managed to recover my Parrot Linux installation. I simply cloned one disk to another with Clonezilla and lost access to the Btrfs partition, but with your help I was able to fix it.

Thank you so much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment