UEFI How to reinstall broken grub

Started by dibl, 2018/08/15, 14:57:01

Previous topic - Next topic

dibl

From years ago, I have a little guide to boot a USB stick and prepare a chroot environment, to allow reinstallation of grub to the mbr of a hdd if it fails to load the boot menu.  But now, with the use of a UEFI boot partition, I think this guide is not accurate.  Is grub actually installed on the partition where / is installed? So, for a UEFI installation on /dev/sda, with /dev/sda1 as the msdos efi partition, does grub go on /dev/sda2?

If that is right, then the chroot needs to do a --bind mount of /boot, correct?  Anything else?

Thanks!
System76 Oryx Pro, Intel Core i7-11800H, ASRock B860 Pro-A, Intel Core Ultra 7 265KF, Nvidia GTX-1060, SSD 990 EVO Plus.

melmarker

@dibl - it's a bit more complicated - but similar:
* the MBR points to a place where a bootloader can be found (one can more than one MBRs - one per disk.
* A UEFI entry point to a bootloader - you can have only one UEFI, but more than one bootloaders.

This look like:

% efibootmgr -v
BootCurrent: 000A
Timeout: 0 seconds
BootOrder: 000A,000B,0000,0008,0009,0005,0006
Boot0000* Windows Boot Manager  HD(2,GPT,2c6e03bb-05f6-426a-ba22-60faccf3bffd,0xe1800,0x32000)/File(\EFI\Microsoft\Boot\bootmgfw.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}...a................
Boot0005* UEFI OS       HD(1,GPT,82ea967a-af96-4482-b2c9-f41ede5b35a5,0x800,0x200000)/File(\EFI\BOOT\BOOTX64.EFI)
Boot0006* Hard Drive    BBS(HD,,0x0)AMGOAMNO........o.C.r.u.c.i.a.l._.C.T.5.2.5.M.X.3.0.0.S.S.D.1....................A...........................>..Gd-.;.A..MQ..L. . . . . . . . .6.1.4.4.4.1.2.8.D.5.9.9......AMBOAMNO........o.C.r.u.c.i.a.l._.C.T.5.2.5.M.X.3.0.0.S.S.D.1....................A...........................>..Gd-.;.A..MQ..L. . . . . . . . .6.1.6.4.4.1.F.A.3.7.5.E......AMBOAMNO........o.S.a.m.s.u.n.g. .S.S.D. .8.5.0. .E.V.O. .2.5.0.G.B....................A...........................>..Gd-.;.A..MQ..L.2.S.P.1.X.N.G.A.3.8.2.8.5.7. .X. . . . ......AMBOAMNO........o.S.a.m.s.u.n.g. .S.S.D. .8.4.0. .P.R.O. .S.e.r.i.e.s....................A...........................>..Gd-.;.A..MQ..L.1.S.R.2.E.N.D.A.2.1.8.8.7.3. .N. . . . ......AMBOAMNO........o.S.T.3.0.0.0.V.N.0.0.0.-.1.H.J.1.6.6....................A...........................>..Gd-.;.A..MQ..L. . . . . . . . . . . . .6.W.2.A.Q.4.Y.Y......AMBOAMNO........o.S.T.3.0.0.0.V.N.0.0.0.-.1.H.J.1.6.6....................A...........................>..Gd-.;.A..MQ..L. . . . . . . . . . . . .6.W.1.A.Z.P.P.D......AMBO
Boot0008* UEFI: IP6 Realtek PCIe GBE Family Controller  PciRoot(0x0)/Pci(0x15,0x1)/Pci(0x0,0x0)/MAC(60a44c62abd1,0)/IPv6([::]:<->[::]:,0,0)AMBO
Boot0009* UEFI: IP4 Realtek PCIe GBE Family Controller  PciRoot(0x0)/Pci(0x15,0x1)/Pci(0x0,0x0)/MAC(60a44c62abd1,0)/IPv4(0.0.0.00.0.0.0,0,0)AMBO
Boot000A* siduction     HD(1,GPT,82ea967a-af96-4482-b2c9-f41ede5b35a5,0x800,0x200000)/File(\EFI\siduction\grubx64.efi)
Boot000B* debian        HD(1,GPT,82ea967a-af96-4482-b2c9-f41ede5b35a5,0x800,0x200000)/File(\EFI\debian\grubx64.efi)
Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety. (Benjamin Franklin, November 11, 1755)
Never attribute to malice that which can be adequately explained by stupidity. (Hanlons razor)

dibl

#2
Good -- thank you Alf.

So, from a chroot into a patience installation with UEFI, will "grub-install --reinstall" know where to install the grub bootloader?

EDIT:  Here is a recent installation on a notebook:

root@dibl-HP350:/home/don# efibootmgr -v
BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0001,3001,0003,2001,2002,2003
Boot0000* Notebook Hard Drive   BBS(HD,,0x500)................-.b.......b.A.b...................................?.........A.........................
Boot0001* EFI HDD Device (Samsung SSD 840 EVO 500GB)    PciRoot(0x0)/Pci(0x1f,0x2)/Sata(0,0,0)/HD(1,GPT,44f19643-7b7e-4cd9-ba96-382b0a354346,0x1001,0x96001)RC
Boot0003* siduction_2018.3.0    HD(1,GPT,44f19643-7b7e-4cd9-ba96-382b0a354346,0x1001,0x96001)/File(\EFI\siduction_2018.3.0\grubx64.efi)
Boot2001* USB Drive (UEFI)      RC
Boot2002* Internal CD/DVD ROM Drive (UEFI)      RC
Boot3001* Internal Hard Disk or Solid State Disk        RC
System76 Oryx Pro, Intel Core i7-11800H, ASRock B860 Pro-A, Intel Core Ultra 7 265KF, Nvidia GTX-1060, SSD 990 EVO Plus.

dibl

Possibly I have asked the wrong question.   :P

Let me try again --

If a UEFI linux installation will fail to boot, with no grub boot menu shown, and only a blinking cursor on black screen, what approach would be used to fix this problem?
System76 Oryx Pro, Intel Core i7-11800H, ASRock B860 Pro-A, Intel Core Ultra 7 265KF, Nvidia GTX-1060, SSD 990 EVO Plus.

dibl

#4
Update:

I have made a little study of the problem of how to restore a broken grub installation on a siduction/debian UEFI setup.  I think this would be the correct approach to use, BUT I have NOT actually tested it on real hardware.

#Use chroot -- assume target root filesystem is on /dev/sda2 and EFI partition is /dev/sda1.  Working as root:

mkdir /mnt/chroot
mount /dev/sda2 /mnt/chroot/
mount --rbind /proc /mnt/chroot/proc && mount --rbind /run /mnt/chroot/run && mount --rbind /sys /mnt/chroot/sys && mount --rbind /dev /mnt/chroot/dev
chroot /mnt/chroot /bin/bash

#Now you are root in the target system:

mount /dev/sda1 /boot/efi
grub-install
update-grub

#Unmount the ESP:

umount /dev/sda1 /boot/efi

#Exit the chroot and unmount the partitions and /dev/sda2:

exit
umount /proc /mnt/chroot/proc
umount /dev /mnt/chroot/dev
umount /sys /mnt/chroot/sys
umount /dev /mnt/chroot/dev
umount /dev/sda2 /mnt/chroot

#Shutdown the Live USB/DVD and reboot the system

# NOTE: The "grub-install" command assumes standard configuration of siduction with EFI partiton at /dev/sda1 and the bootx64.efi file in /boot/efi/EFI/boot directory and the grubx64.efi file in /boot/efi/EFI/siduction_2018.3.0 directory. Other configurations would have to use the full command in the form of:

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=some_name_you_want


I would love to hear feedback and corrections.  I managed to avoid using a UEFI installation until recently, so this is a learning process, but I believe this procedure (or the corrected version of it) would be important for every user to have in his toolkit for system maintenance.

Thanks!
System76 Oryx Pro, Intel Core i7-11800H, ASRock B860 Pro-A, Intel Core Ultra 7 265KF, Nvidia GTX-1060, SSD 990 EVO Plus.

melmarker

Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety. (Benjamin Franklin, November 11, 1755)
Never attribute to malice that which can be adequately explained by stupidity. (Hanlons razor)

dibl

Whooops!  Thanks for that -- will edit to fix.

Anything else?
System76 Oryx Pro, Intel Core i7-11800H, ASRock B860 Pro-A, Intel Core Ultra 7 265KF, Nvidia GTX-1060, SSD 990 EVO Plus.

tranquil

The following doesn't address dealing with a broken GRUB, but it does explain partitioning for Linux in quite some detail:


Partitioning hard disk drives for BIOS-MBR, BIOS-GPT and UEFI-GPT in Linux
Dual-booting Debian Stable and Unstable with Openbox window manager and Tint2 panel.

Colonel Panic

Quote from: dibl on 2018/08/17, 19:30:37
Update:

I have made a little study of the problem of how to restore a broken grub installation on a siduction/debian UEFI setup.  I think this would be the correct approach to use, BUT I have NOT actually tested it on real hardware.

#Use chroot -- assume target root filesystem is on /dev/sda2 and EFI partition is /dev/sda1.  Working as root:

mkdir /mnt/chroot
mount /dev/sda2 /mnt/chroot/
mount --rbind /proc /mnt/chroot/proc && mount --rbind /run /mnt/chroot/run && mount --rbind /sys /mnt/chroot/sys && mount --rbind /dev /mnt/chroot/dev
chroot /mnt/chroot /bin/bash

#Now you are root in the target system:

mount /dev/sda1 /boot/efi
grub-install
update-grub

#Unmount the ESP:

umount /dev/sda1 /boot/efi

#Exit the chroot and unmount the partitions and /dev/sda2:

exit
umount /proc /mnt/chroot/proc
umount /dev /mnt/chroot/dev
umount /sys /mnt/chroot/sys
umount /dev /mnt/chroot/dev
umount /dev/sda2 /mnt/chroot

#Shutdown the Live USB/DVD and reboot the system

# NOTE: The "grub-install" command assumes standard configuration of siduction with EFI partiton at /dev/sda1 and the bootx64.efi file in /boot/efi/EFI/boot directory and the grubx64.efi file in /boot/efi/EFI/siduction_2018.3.0 directory. Other configurations would have to use the full command in the form of:

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=some_name_you_want


I would love to hear feedback and corrections.  I managed to avoid using a UEFI installation until recently, so this is a learning process, but I believe this procedure (or the corrected version of it) would be important for every user to have in his toolkit for system maintenance.

Thanks!

Thanks for this, I've made a text copy of these instructions for future reference.

devil

@dibl: Since our last release, we have a chroot helper on our live media(courtesy of towo), that will set up a chroot with one or two clicks. No more need to type in commands.

eriefisher

Quote from: devil on 2023/05/13, 11:01:12
@dibl: Since our last release, we have a chroot helper on our live media(courtesy of towo), that will set up a chroot with one or two clicks. No more need to type in commands.
And it works perfectly too!
I AM CANADIAN!

dibl

Quote from: devil on 2023/05/13, 11:01:12
@dibl: Since our last release, we have a chroot helper on our live media(courtesy of towo), that will set up a chroot with one or two clicks. No more need to type in commands.
Good news -- good progress!

Thanks to the development team!
System76 Oryx Pro, Intel Core i7-11800H, ASRock B860 Pro-A, Intel Core Ultra 7 265KF, Nvidia GTX-1060, SSD 990 EVO Plus.