Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: [EN] How I fixed a non-booting Grub + LUKS + BtrFS system  (Read 3711 times)

Offline PhillyBass

  • User
  • Posts: 7
    • Flint Weller
[EN] How I fixed a non-booting Grub + LUKS + BtrFS system
« on: 2023/07/15, 01:57:57 »
This is not a request for help.
I am sharing what I did to fix my system for others to use as a reference.

This is a story about how I broke my Grub2 EFI Cryptodisk bootloader and then how I fixed it
Note: I don't know the proper name for the little Grub that unlocks LUKS partitions before loading the bigger Grub

How did I notice the problem?
I turned on my computer and was presented with the usual Grub2 EFI Cryptodisk unlock request

Code: [Select]
Welcome to GRUB!
Attempting to decrypt master key...
Enter passphrase for hd2,gpt2 (a3.....
Slot 0 opened

But then there was an error I had never seen before

Code: [Select]
error: file `/@snapshots/122/snapshot/boot/grub/x86_64-efi/normal.mod' not found.
I realize now that I deleted snapshot 122 and never updated Grub.  The process below is an abridged version of what actually transpired.  These are my notes that I typed into a second computer as I performed the fixing process.

# Useful articles I found on the Internet to educate myself on how Grub works
https://nixventure.blogspot.com/2015/08/grub-rescue-btrfs.html
https://superuser.com/questions/1588626/grub-bootloader-with-luks-encryption-stuck
https://www.linuxfoundation.org/blog/blog/classic-sysadmin-how-to-rescue-a-non-booting-grub-2-on-linux


# We are starting in the EFI limited functionality Grub bootloader

# Use the set command to see settings
Code: [Select]
grub rescue> set
# Some minimal settings are provided
Code: [Select]
cmdpath=(hd2,gpt1)/EFI/siduction
prefix=(cryptouuid/####a_bunch_of_hex_codes/@snapshots/122/snapshot/boot.....

# Set the root to crypto0 because I already provided the LUKS password
Code: [Select]
grub rescue> set root=(crypto0)
# Set the prefix to where the grub bootloader is located
Code: [Select]
grub rescue> set prefix=(crypto0)/@/boot/grub/
# Load the normal module
# In normal mode, commands, filesystem modules, and cryptography modules
# are automatically loaded, and the full GRUB script parser is available.
Code: [Select]
grub rescue> insmod normal
# Call normal to load the full-service Grub
Code: [Select]
grub rescue> normal
# Now we are in the normal highly-functioning Grub bootloader

# Type the letter "C" to get to the Grub command line
Code: [Select]
c
# Show settings
Code: [Select]
grub> set# a lot of settings are displayed here

# Prepare Grub by loading necessary modules
# I don't know if I need every one of these
# Loading more than needed will not hurt the process
# Loading fewer than needed will hurt the process
Code: [Select]
grub> insmod cryptodisk
grub> insmod luks
grub> insmod lvm
grub> insmod btrfs
grub> insmod part_msdos

# Instruct Grub to automatically mount all LUKS partitions
Code: [Select]
grub> cryptomount -a# Provide my LUKS password here

# Set the root device
Code: [Select]
grub> set root=(crypto0)
# List the kernel and initrd files available
Code: [Select]
grub> ls /@/boot# Decide which kernel to use

# Specify the kernel and initrd
# Do not fail to pass the root and rootflags to the kernel
# Notice the ro means to mount filesystems as read-only
Code: [Select]
grub> linux /@/boot/vmlinuz-6.3.8-2-siduction-amd64 root=/dev/dm-0 ro rootflags=subvol=@
grub> initrd /@/boot/initrd.img-6.3.8-2-siduction-amd64

# Boot
Code: [Select]
grub> boot
# If the process failed, then you will likely be dropped into the initramfs
# This is how I discovered the proper root device name to pass to the kernel
Code: [Select]
(initramfs) fdisk -l
/dev/dm-0   # This is the root filesystem
/dev/dm-1   # This is the swap partition

# The process worked, I am presented with the usual login screen

# Install and update Grub
Code: [Select]
$ sudo grub-install
$ sudo update-grub

# Reboot to see if the system has been fixed









Offline edlin

  • User
  • Posts: 557
Re: How I fixed a non-booting Grub + LUKS + BtrFS system
« Reply #1 on: 2023/07/16, 15:28:46 »
Thank you for your detailed report. I hope no one needs it, but if they do, it's a verified guide. Thank you.

edlin
Der Kluge lernt aus allem und von jedem,
der Normale aus seinen Erfahrungen
und der Dumme weiß alles besser.

Sokrates

Offline dibl

  • siduction community member
  • Global Moderator
  • User
  • *****
  • Posts: 2.367
    • Land of the Buckeye
Re: How I fixed a non-booting Grub + LUKS + BtrFS system
« Reply #2 on: 2023/07/16, 19:03:36 »
+1
System76 Oryx Pro, Intel Core i7-11800H, SSD 970 EVO Plus;  Asus ROG STRIX X299-E, Core i7-7740X, Nvidia GTX-1060, dual monitors, SSD 860 EVO