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

Author Topic: [EN] UEFI How to reinstall broken grub  (Read 6366 times)

Offline dibl

  • siduction community member
  • Global Moderator
  • User
  • *****
  • Posts: 2.345
    • Land of the Buckeye
[EN] UEFI How to reinstall broken grub
« on: 2018/08/15, 14:57:01 »
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, SSD 970 EVO Plus;  Asus ROG STRIX X299-E, Core i7-7740X, Nvidia GTX-1060, dual monitors, SSD 860 EVO

Offline melmarker

  • User
  • Posts: 2.799
    • g-com.eu
Re: UEFI How to reinstall broken grub
« Reply #1 on: 2018/08/16, 00:22:24 »
@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:
Code: [Select]
% 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)

Offline dibl

  • siduction community member
  • Global Moderator
  • User
  • *****
  • Posts: 2.345
    • Land of the Buckeye
Re: UEFI How to reinstall broken grub
« Reply #2 on: 2018/08/16, 01:15:17 »
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:

Code: [Select]
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
« Last Edit: 2018/08/16, 11:06:34 by dibl »
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

Offline dibl

  • siduction community member
  • Global Moderator
  • User
  • *****
  • Posts: 2.345
    • Land of the Buckeye
Re: UEFI How to reinstall broken grub
« Reply #3 on: 2018/08/16, 18:19:46 »
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, SSD 970 EVO Plus;  Asus ROG STRIX X299-E, Core i7-7740X, Nvidia GTX-1060, dual monitors, SSD 860 EVO

Offline dibl

  • siduction community member
  • Global Moderator
  • User
  • *****
  • Posts: 2.345
    • Land of the Buckeye
Re: UEFI How to reinstall broken grub
« Reply #4 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.
Code: [Select]
#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!
« Last Edit: 2018/08/17, 21:56:57 by dibl »
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

Offline melmarker

  • User
  • Posts: 2.799
    • g-com.eu
Re: UEFI How to reinstall broken grub
« Reply #5 on: 2018/08/17, 20:38:50 »
--efi-directory=/mnt/sda1 ???
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)

Offline dibl

  • siduction community member
  • Global Moderator
  • User
  • *****
  • Posts: 2.345
    • Land of the Buckeye
Re: UEFI How to reinstall broken grub
« Reply #6 on: 2018/08/17, 21:55:34 »
Whooops!  Thanks for that -- will edit to fix.

Anything else?
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

Offline tranquil

  • User
  • Posts: 111
Re: UEFI How to reinstall broken grub
« Reply #7 on: 2018/10/16, 22:05:11 »
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.

Offline Colonel Panic

  • User
  • Posts: 17
Re: UEFI How to reinstall broken grub
« Reply #8 on: 2023/05/09, 12:22:58 »
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.
Code: [Select]
#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.

Offline devil

  • Administrator
  • User
  • *****
  • Posts: 4.838
Re: UEFI How to reinstall broken grub
« Reply #9 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.

Offline eriefisher

  • User
  • Posts: 264
Re: UEFI How to reinstall broken grub
« Reply #10 on: 2023/05/13, 12:59:22 »
@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!

Offline dibl

  • siduction community member
  • Global Moderator
  • User
  • *****
  • Posts: 2.345
    • Land of the Buckeye
Re: UEFI How to reinstall broken grub
« Reply #11 on: 2023/05/14, 11:35:31 »
@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, SSD 970 EVO Plus;  Asus ROG STRIX X299-E, Core i7-7740X, Nvidia GTX-1060, dual monitors, SSD 860 EVO