Linux grub

From Lolly's Wiki
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

grub rescue>

The problem:

...
Entering rescue mode...                                                         
grub rescue>


Get into the normal grub

Find your devices:

grub rescue> ls

Find the directory where the normal.mod file resides

In this example we have LVM and the /boot/grub is in VG vg-root and the LV lv-root.

grub rescue> ls (lvm/vg--root-lv--root)/boot/grub/i386-pc
... normal.mod ...

Set the prefix to the right place

grub rescue> set prefix=(lvm/vg--root-lv--root)/boot/grub

Now you can load and start the module called "normal"

grub rescue> insmod normal
grub rescue> normal

If the menu not occurs you get something like this:

                  GNU GRUB  version 1.99,5.11.0.175.2.0.0.42.2

   Minimal BASH-like line editing is supported. For the first word, TAB
   lists possible command completions. Anywhere else TAB lists possible
   device or file completions.

grub>

Normal grub is bootet, now start the Kernel

Example for LVM

insmod gzio
insmod part_msdos
insmod lvm
insmod ext2
set root='lvmid/KAlPF4-Qb8I-Sx41-10cC-lACw-Msoh-3qEohv/pmE9Nt-rLG3-FlNM-CwOT-hy42-gSnm-fZSn3l'
linux   /boot/vmlinuz-4.4.0-53-generic root=/dev/mapper/vg--root-lv--root ro  
initrd  /boot/initrd.img-4.4.0-53-generic

Example for ZFS-Root

insmod gzio
insmod part_msdos
insmod part_gpt
insmod zfs
set root='hd0,msdos4'
linux   /ROOT/ubuntu-15.04@/boot/vmlinuz-4.4.0-57-generic root=ZFS=rpool/ROOT/ubuntu-15.04 boot=zfs zfs_force=1 ro  quiet splash nomdmonddf nomdmonisw $vt_handoff
initrd  /ROOT/ubuntu-15.04@/boot/initrd.img-4.4.0-57-generic

Example for ZFS-Root on GPT with known nothing about the location of kernel and initrd


<TAB> means press tab key.
grub> insmod gzio
grub> insmod part_gpt
grub> insmod part_msdos
grub> insmod zfs
grub> ls (<TAB>
Possible devices are:

 proc memdisk hd0 hd1 hd2

So we have several disks. Let us see what partitions we have:

grub> ls (hd0<TAB>
Possible partitions are:
Device hd0: No known filesystem detected - Sector size 512B - Total size 5242880KiB
        Partition hd0,gpt1: Filesystem type fat - Label `EFI', UID 4711-6C33 - Partition start at 1024KiB - Total size 524288KiB
        Partition hd0,gpt3: Filesystem type zfs - Label `bpool' - Last modification time 2024-07-01 04:36:00 Monday, UUID 001702272575c1blabla - Partition start at 525312KiB - Total size 4717551.5KiB
        Partition hd0,gpt5: No known filesystem detected - Partition start at 24KiB - Total size 1000KiB

Now we know more about the possible partitions and due to the filesystem type and the labels we can see hd0,gpt3 would be a good start to look at. But the Last modification time looks a little old. We will see (Tell me why I don't like Mondays...).

grub> ls (hd0,gpt3)/<TAB>
Possible files are:
 @/ BOOT/

You can use tab until you found the right dataset and than /@/ at the end:

grub> ls (hd0,gpt3)/BOOT/ubuntu_flupdy/@/
efi grub
grub>

Soooo... now we know, our dataset was not properly mounted when configuring grub. But we migrated from all in rpool to rpool and bpool. Maybe we have a snapshot on rpool where still a /boot with a kernel dangles around...

grub> ls (hd1,gpt1)/ROOT/<TAB>
...
@zfs-auto-snap_daily-2024-06-31-06.42.00--7d/
@zfs-auto-snap_daily-2024-06-30-06.42.00--7d/
@zfs-auto-snap_daily-2024-06-29-06.43.00--7d/
@zfs-auto-snap_daily-2024-06-28-06.42.00--7d/
@zfs-auto-snap_daily-2024-06-27-06.44.00--7d/
@zfs-auto-snap_daily-2024-06-26-06.42.00--7d/
...
grub> ls (hd1,gpt1)/ROOT/ubuntu_flupdy/@zfs-auto-snap_daily-2024-06-29-06.43.00--7d/boot/
vmlinuz-6.5.0-45-generic ...

YES! That is what we searched for!

set root='hd1,gpt1'
linux   "/ROOT/ubuntu_flupdy/@zfs-auto-snap_daily-2024-06-29-06.43.00--7d/boot/vmlinuz-6.5.0-45-generic" root=ZFS="rpool/ROOT/ubuntu_flupdy" ro single nomodeset dis_ucode_ldr text console=tty0 console=ttyS0,115200n8 nosplash init_on_alloc=0
initrd  "/ROOT/ubuntu_flupdy/@zfs-auto-snap_daily-2024-06-29-06.43.00--7d/boot/initrd.img-6.5.0-45-generic"
boot

Here we go!