Advertisement
CiceroCalls

boot rescue methods

Jun 18th, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. If able to boot into the system, Simple Method.
  2. If unable, Live Session Method, e.g., because a Windows update has overwritten the boot loader, boot a live session and try the second method. Usually this works.
  3. If still no, Chroot Method.
  4. And if all else fails, Purge-And-Reinstall method.
  5. Boot Repair app=bad. Do not use.
  6.  
  7. References: grub-install man page; GNU Grub Manual; Ubuntu Help; Arch Wiki.
  8.  
  9. Simple method. Run sudo grub-install /dev/sdx, where x = device to which installing the boot loader. Works for both BIOS and UEFI. For example, returns control of Grub to the primary system after installing a second as a test box (by default, the last system installed controls Grub). As mentioned, for this to work, you have to be booted into the system you want to control Grub.
  10.  
  11. Live session method. Works with both BIOS and UEFI, but the commands are a bit different. First you mount the system partition to /mnt. If there is a boot partition, this must be mounted also; insert a new second step: sudo mount sdxn /mnt/boot, where sdxn is the boot partition's ID. Then, in UEFI, you mount the EFI partition. The command to install Grub is very simple because it invokes a script which does most of the work behind the scenes. Notice the target for grub always is the device, for illustration sda. This is true in UEFI as well as BIOS. See GNU Grub Manual.
  12.  
  13. For BIOS, assuming the system/root partition is sda1.
  14. Code:
  15. sudo mount /dev/sda1 /mnt
  16. sudo grub-install /dev/sda --boot-directory=/mnt/boot
  17.  
  18. For UEFI, assuming the system partition is sda2 and the EFI partition is sda1:
  19.  
  20. Code:
  21. apt install grub-efi-amd64-signed shim-signed
  22. sudo mount /dev/sda2 /mnt
  23. sudo mount /dev/sda1 /mnt/boot/efi
  24. sudo grub-install /dev/sda --boot-directory=/mnt/boot --uefi-secure-boot
  25.  
  26. Notes: For reasons unknown, grub-install only installs the secure boot loaders if the live session is connected to the internet. If secure boot is disabled, will get a squawk to that effect, but the command will complete without issue. If you want to install Grub without secure boot, change the first line to apt install grub-efi-amd64 (no -signed or shim-signed) and omit --uefi-secure-boot from the last line; internet access not needed, but doesn't hurt.
  27.  
  28. Chroot Method. Mainly useful if for some reason you need to run update-grub, as well as install/reinstall Grub. For that matter, if all you need to do is update Grub from the live session, you do that the same way; just leave out the grub-install line. As with the regular live session method, if you have a boot partition, you need to insert a second step to mount it.
  29.  
  30. For BIOS, still assuming the system partition is sda1:
  31.  
  32. Code: Select all
  33.  
  34. sudo mount /dev/sda1 /mnt
  35. for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
  36. sudo chroot /mnt
  37. grub-install /dev/sda
  38. update-grub
  39. exit
  40. sudo umount -R /mnt
  41.  
  42. FYI, the second line is a compact way of doing bind mounts (sudo mount --bind /dev /mnt/dev, etc.), so those directories are available in the chroot environment. Per Arch Wiki, adding -R (--recursive) to the unmount command also releases the bind mounts.
  43.  
  44. For UEFI, assuming the system partition is sda2 and the EFI partition is sda1:
  45.  
  46. Code: Select all
  47.  
  48. sudo mount /dev/sda2 /mnt
  49. sudo mount /dev/sda1 /mnt/boot/efi
  50. for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
  51. sudo cp /etc/resolv.conf /mnt/etc
  52. modprobe efivars
  53. sudo chroot /mnt
  54. apt install grub-efi-amd64-signed shim-signed
  55. grub-install /dev/sda --uefi-secure-boot
  56. update-grub
  57. exit
  58. sudo umount /mnt/boot/efi
  59. sudo umount -R /mnt
  60.  
  61. As mentioned above, grub-install needs access to the internet to install the secure boot loader. That's what the fourth and fifth lines do. Be sure to set up a connection in the live session before running the commands. As with the regular method, you'll get a squawk if secure boot isn't enabled. And you can install without secure boot; modify the apt install and grub-install lines as described above.
  62.  
  63. Purge-and-Reinstall Method. It's rare to need to escalate this far. The few cases I've noticed entailed someone or something having bollixed the Grub scripts in /etc/grub.d (yes, I'm looking at you, Grub Customizer). If still able to boot, the commands are simple:
  64.  
  65. For BIOS: Run apt purge grub-common; will be prompted to confirm removal of boot loader. Then run apt install grub-pc os-prober. Select destination for boot loader when prompted (tap space key to select). Unless you have a very good reason, install to the device, not the system partition.
  66.  
  67. os-prober is removed by purge but only a recommended package on reinstall, so specifying additionally. Same with shim-signed for UEFI.
  68.  
  69. For UEFI: Similar, but the packages to install are different. Run apt purge grub-common, then apt install grub-efi-amd64-signed os-prober shim-signed. Select destination for boot loader if prompted (probably won't be).
  70.  
  71. Purge-and-Reinstall in chroot. This is for the scenario where can't boot. Remember, if you have a boot partition, insert a second step to mount it.
  72.  
  73. For BIOS, assuming the system partition is sda1:
  74.  
  75. Code:
  76. sudo mount /dev/sda1 /mnt
  77. for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
  78. sudo cp /etc/resolv.conf /mnt/etc
  79. sudo chroot /mnt
  80. apt purge grub-common
  81. apt install grub-pc os-prober
  82. exit
  83. sudo umount -R /mnt
  84.  
  85. For UEFI, assuming the system partition is sda2 and the EFI partition is sda1. Again, you need to set up an internet connection.
  86.  
  87. Code:
  88. sudo mount /dev/sda2 /mnt
  89. sudo mount /dev/sda1 /mnt/boot/efi
  90. for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
  91. sudo cp /etc/resolv.conf /mnt/etc
  92. modprobe efivars
  93. sudo chroot /mnt
  94. apt purge grub-common
  95. apt install grub-efi-amd64-signed os-prober shim-signed
  96. exit
  97. sudo umount /mnt/boot/efi
  98. sudo umount -R /mnt
  99.  
  100. Frankly, if you've gotten this far and still no joy, probably no alternative except reinstall of the whole system.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement