Location of grub on gpt partition
First, there are two distinct issues involved:
-
BIOS vs. EFI -- This is the type of firmware on the computer; or in some cases, because EFIs include a BIOS emulation layer, EFI-based computers can boot in BIOS/CSM/legacy mode. The version of GRUB 2 installed on the computer depends on the firmware type. Under BIOS, a 16-bit GRUB 2 (from the
grub-pc
package, IIRC) is installed; and under EFI, a GRUB 2 compiled to the same bit depth as the EFI itself (32- or 64-bit) is installed from thegrub-efi-ia32
orgrub-efi-amd64
package. -
MBR vs. GPT -- The partition table type affects the details of where parts of BIOS-mode GRUB is installed -- on an MBR disk, the second stage of the boot loader goes in officially-unallocated sectors immediately following the MBR itself; and on a GPT disk, those second-stage files go in a special partition called the BIOS Boot Partition (identified as being type EF02 in
gdisk
or as having the "bios_grub flag" set inparted
or GParted). For an EFI-mode boot, the partition table type is less important; it's just that the EFI System Partition (ESP) has a type code of EF under MBR usingfdisk
, whereas under GPT, it's identified with a type code of EF00 ingdisk
or by a "boot flag" inparted
or GParted. (Note that the "boot flag" has an entirely different meaning on MBR disks; an ESP cannot be properly identified on an MBR disk usingparted
or GParted.)
In all cases, GRUB 2's code is scattered all over the place. Locations where it might exist include:
- The MBR -- In this context, "MBR" means the first sector of the disk. This location is used by most BIOS-mode installations, for both MBR and GPT disks. The first-stage GRUB code goes here, but the space is limited (just 440 bytes), so it's impossible to fit all of GRUB in the MBR.
- Boot sectors on a Linux filesystem partition -- It's possible to install BIOS-mode GRUB so that its first-stage code goes in a partition rather than in an MBR. This configuration is unusual in Ubuntu.
- Post-MBR sectors -- As noted earlier, on an MBR disk, GRUB stores part of itself immediately after the MBR.
- The BIOS Boot Partition -- As noted earlier, a separate partition exists to take the place of the post-MBR sectors on a GPT disk. (This is done because the post-MBR sectors under GPT are part of the GPT itself, so they can't be used by GRUB.)
- The ESP -- Under EFI, the main GRUB 2 binary goes in a file on the ESP. This file contains the equivalent of a BIOS-mode GRUB 2's MBR and post-MBR/BIOS Boot Partition code. The ESP is not used by GRUB for a BIOS-mode boot.
-
The Linux
/boot
directory -- In all cases, parts of GRUB 2 reside in files it can load from a normal filesystem. These files are normally in the Linux/boot
directory, typically in/boot/grub
or/boot/grub2
.
This last point, really, is the "gotcha;" if you delete Ubuntu from a dual-boot installation, GRUB 2 will be partially removed, and so it will almost certainly launch but not work correctly because you will have deleted these configuration and support files. You'll end up with a grub>
prompt when you try to boot. Under BIOS, your only choice at this point is to re-install the boot loader for your other OS. Under EFI, you can usually get the system booting again by adjusting the boot order using any number of tools (efibootmgr
in Linux, bcdedit
or EasyUEFI in Windows, bless
in OS X, bcfg
in an EFI shell, or system-specific firmware tools in many EFIs). Re-installing another OS's boot loader should also work, but is normally overkill.
Note that most boot loaders lack this particular problem. Under EFI, ELILO, GRUB Legacy, SYSLINUX, gummiboot/systemd-boot, and rEFInd all rely on configuration files stored on the same partition as the boot loader (normally the ESP), so if you delete Ubuntu, the worst that will happen is that you'll end up being unable to boot Ubuntu but you'll still be able to boot anything else you have installed. Under BIOS, LILO should still continue to work; but if I'm not mistaken, GRUB Legacy and SYSLINUX both share GRUB 2's problem.
It's possible to configure GRUB 2 to place its configuration and support files on the ESP rather than on a Linux filesystem. For reasons I don't claim to know, however, Ubuntu's developers chose to put the files on a Linux filesystem, so Ubuntu suffers from this problem.
Related videos on Youtube
Pilot6
Updated on September 18, 2022Comments
-
Pilot6 over 1 year
As far as i undersood the grub program is located fully in the efi partition if i have gpt partition scheme instead just as a link like it was in the older mbr. So now if i remove linux partition will grub be still available? Disclaimer: I don't intend to uninstall Linux i'm just curious
-
TheWanderer over 8 yearsYes it will. This is an issue people have when they uninstall Ubuntu. You may end up at a GRUB rescue prompt, but the essential boot files are in the EFI partition.
-
oldfred over 8 yearsNormal UEFI install does not have all of grub in efi partition. It essentially has the same code that is in MBR & core.img which is in sectors just after MBR. Your menu, scripts and configuration parameters are still in Ubuntu folders in / (root). You can also install grub to boot in BIOS mode and then have to have a bios_grub partition for core.img as there are no sectors after gpt's protective MBR. But with UEFI there are many other ways to configure booting, even without grub.
-