0

I moved an Ubuntu 20.04.4 to a 4TB GPT disk, booted bios_grub (i.e. using legacy BIOS). Grub2 allows this, as long as its stage2 code is installed at the start of the disk (like in sectors 34-2047).
That was the occasion to find out (the hard way) that by default, Grub2 uses the BIOS firmware disk drivers rather than its own native disk drivers. This is not so good since the BIOS disk drivers are limited to 32-bit LBA addresses, accessing at most the first 2TiB of the disk.
Fortunately, Grub2 has a nativedisk command that tells grub to switch to its native disk drivers, that are apparently 64-bit enabled. I could confirm from the live rescue console that the nativedisk grub command would fix a nasty semi-random boot problem I had: some kernel images would be located just before the 2TiB mark in the ext4 partitions (those would successfully boot), some would be located above (those wouldn't boot).
In the latter case, I would get a nasty
error: attempt to read or write outside of disk 'hd0'
when Grub attempted to load the kernel.
Finally, according to the Grub manual, the nativedisk command is not limited to the grub interactive console, but can also be used in scripts / menus.
Now the question is:
what is the cleanest/safest script/config spot to stuff that nativedisk command into, so it executes early enough in the boot process, i.e. before Grub attempts to load its kernel and initramfs files?
I'm looking for a place that would at least resist a
grub-update
command, such as those that routine Ubuntu updates trigger every other day, when fixing the kernel.
(and yes, I unfortunately understand that in the current grup_pc version, no scripting / config change will probably resist an update of the grub-pc package itself).

2
  • Do you have large / or part of / beyond the 2TB limit? You might try a smaller / totally within first 2TB of drive and /home and/or data partition(s) for rest of drive. Back with some old BIOS with 20GB limits, and then a newer larger drive similar configuration was required with / fully inside first 20GB. Then no parts of grub or kernel are beyond what driver can see.
    – oldfred
    Apr 23 at 17:52
  • I sure considered that, but only as a last resort. This should work, knowing that Grub2 supports GPT with 64-bit sector addresses, and the grub code is located in the 2047 first sectors of the disk...
    – filofel
    Apr 23 at 23:05

1 Answer 1

0

I didn't find a way to insert "nativedriver" in the Grub scripts, but I found a better solution:
Insert the native driver in the Grub bootblocks so it is used instead of the limited BIOS ones.
This can be done by running something like
grub-install --disk-module=ahci /dev/sdX
where your controller might be ahci, ehci, ATA, ohci or uhci according to your harware, and /dev/sdX is your drive (like sda, NOT like sda1).
Of course, a later grub-install that would not include that parameter will resurrect the broken boot, and this might even be triggered by an automatic Ubuntu update / upgrade...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.