1

It appears that this question has been asked many many times here, for e.g.:

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.
  • If only use grub-install but not update-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
xpt
  • 1,045

2 Answers2

1

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:

sudo ubiquity -b

You can always boot into any install & install its grub into MBR. From inside your install:

sudo grub-install /dev/sdX where sdX is your drive.

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.

sudo dpkg-reconfigure grub-pc 

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

oldfred
  • 12,100
0

I think @oldfred's answer covers mostly everything, your question is a bit confusing though.

Although it is possible to install grub to a PBR, you always install grub of the OS in partition A to the PBR of partition A, you never install grub to the PBR of any other partition.

But if you really want to (re)install an instance of grub to the PBR of partition A while booted into a live session or the OS on partition B, you would have to chroot into the OS on partition A and then run the grub-install command. Example:

sudo mount /dev/sdaX /mnt
for i in dev sys proc dev/pts ; do sudo mount --bind /$i /mnt/$i ; done
chroot /mnt
grub-install --force /dev/sdaX
update-grub
exit
for i in dev sys proc dev/pts ; do sudo umount /mnt/$i ; done
sudo umount /mnt

Adapt the device-names /dev/sdaX in this example to your needs!

Things are going to be more complicated if not impossible though, if the OS on /dev/sdX uses a seperate /boot-partition, I've never used seperate /boot-partitions, so I can't tell you. This example will work if the OS in question does not use a seperate /boot-partition.

mook765
  • 15,925
  • "you always install grub of the OS in partition A to the PBR of partition A, you never install grub to the PBR of any other partition" Provided that partition A is bootable, right? The problem I described is that partition A is not bootable. – xpt Jul 28 '19 at 20:56
  • If partition is not bootable, that is not a grub issue. You may need fsck or chroot to do major repairs to system. You may be able to boot a recovery mode, if grub loads menu. You also many be able to manually boot if some grub issues. https://askubuntu.com/questions/654386/windows-10-upgrade-led-to-grub-rescue/655027#655027 – oldfred Jul 28 '19 at 21:01
  • @xpt You need to understand that grub in PBR is never used unless you chainload from grub in MBR. This looks like an XY-problem, I already described how to install an instance of grub to the PBR of that partition when booted to a live session or another OS on a different partition using chroot. Look at @oldfred's comment, I also have the impression that you have to repair that OS, maybe it needs a file-system check or is otherwise damaged. – mook765 Jul 28 '19 at 21:14
  • Guys, all what I was trying to say is that you can't assume you can always install grub as its own boot-loader, as there are cases that you need to install grub as boot-loader for other partitions. Anyway, I tried the chroot approach, but it didn't work for me. See my updated OP. Thx. – xpt Jul 28 '19 at 21:24
  • @xpt I think best is to run boot-repair to create boot-info-summary, do NOT run recommended repair, open a new question and provide link to boot-info-summary. This way we are hopefully able to help you solving the problem. – mook765 Jul 28 '19 at 21:24
  • Thanks mook765, done -- https://askubuntu.com/questions/1161746/ – xpt Jul 28 '19 at 21:49
  • @xpt I added the --force-option, maybe that helps, I'm unable to test it in my UEFI system. – mook765 Jul 29 '19 at 00:14