It appears that this question has been asked many many times here, for e.g.:
- Installing GRUB2
- need to re-install grub2 to /boot pbr (not mbr). Use live cd and the grub-install?
- How to install grub on the PBR instead of MBR?
But none of them is fully answered (or maybe to itself, to those questions not listed here, but not fully to the questions asked here). So let me ask it again, so that we can have a fully covered Q&A at a one-stop place.
The situation is simple:
- There is a partition (partition-A) whose boot-loader is damaged, or is missing,
- And we are booting into another Linux system, either from a different partition (partition-B) or Live-CD,
- And the goal is to fully install the grub2 as the boot-loader to it. I.e., from OS in partition-B to OS on partition-A.
The task is simple too:
- Install the grub2 as the boot-loader. This is done by
grub-install
. - Update the grub2 menu to boot whatever kernel found on partition-A. This is done by
update-grub
, right?
OK, now the devil is in the details,
- for
grub-install
to install to PBR,- it complains it is unsafe/unreliable:
GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged..
- And sometime it complains
error: embedding is not possible, but this is required for cross-disk install
too, as I read.
- it complains it is unsafe/unreliable:
- If only use
grub-install
but notupdate-grub
, then- partition-A can be bootable, but only to a black GRUB2 screen with a commandline prompt.
- However I see no option for
update-grub
to opearate on partition-A, instead of its own, partition-B.
So, all in all, please give details steps how to install grub2 to PBR of a different partition, with a menu booting whatever kernel found on partition-A. Thx.
UPDATE:
Alright, to make it fully a one-stop place, for those people who don't even know what PBR is —
PBR is a term normally used in Multi-booting situation, which refers to the Partition Boot Record, apart from the Master Boot Record (MBR).
UPDATE2:
Using the chroot
method into partition-A, this is what I got:
% grub-install /dev/sdc5
Installing for i386-pc platform.
grub-install: warning: File system `ext2' doesn't support embedding.
grub-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged..
grub-install: error: will not proceed with blocklists.
Why it refuse to proceed with blocklists?
% fdisk -l /dev/sdc
Disk /dev/sdc: 74.5 GiB, 80000000000 bytes, 156250000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x44c4f501
Device Boot Start End Sectors Size Id Type
/dev/sdc1 1 12289724 12289724 5.9G 7 HPFS/NTFS/exFAT
/dev/sdc2 * 12289725 28676024 16386300 7.8G 83 Linux
/dev/sdc3 28676025 156248189 127572165 60.9G 5 Extended
/dev/sdc5 28676026 45062324 16386299 7.8G 83 Linux
/dev/sdc6 45062326 61448624 16386299 7.8G 83 Linux
. . .
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
Best Answer
Only for BIOS systems. All systems since Windows 8 released in 2012 are UEFI. So you do not need nor really want to install in the now 35 year old BIOS/MBR configuration.
Installing grub to PBR is only for BIOS boot. And you only can boot from a PBR if booting with another grub installed to MBR as BIOS only boots via MBR.
And now with grub2 there are many better ways to boot another install. And grub has to use blocklists which are hard coded addresses for the rest of grub, not searching. And addresses even can change with a fsck.
Normally grub in MBR, is from last install & it takes control of boot process. If you do not want grub installed from live installer:
You can always boot into any install & install its grub into MBR. From inside your install:
You can use grub2's os-prober to find other installs & add to grub menu. You can use a configfile to load another installs grub. And you can use your own boot stanza in 40_custom to load the link of most current kernel, so no updates of second install's boot entries with newer kernel are required.
Grub in BIOS mode also saves the drive (and partition) info on where to reinstall. That must also be updated if not correct. Enter thru first pages,tab to ok, spacebar to choose/unchoose drive, enter to accept, do not choose partitions or choose nothing so grub will not reinstall anywhere.
https://ubuntuforums.org/showthread.php?t=2189643
Examples of boot stanza for booting link in / to most recent kernel & configfile type grub entries. Not just for USB drive but any install.
How to add a GRUB2 menu entry for booting installed Ubuntu on a USB drive?
You always can manually install grub, either just mounting other install or full chroot. If you really want it in a partition you may need the --force parameter.
https://help.ubuntu.com/community/Grub2/Installing#Fixing_a_Broken_System
See also:
https://help.ubuntu.com/community/Grub2/Setup#Configuring_GRUB_2
https://help.ubuntu.com/community/Grub2/CustomMenus