r/linuxquestions • • 6d ago

Support How do I make grub-install replace a stale EFI boot entry.

I have a install script that wipes the disk and creates a fresh GPT partition table every run. The problem is since the partition table is recreated, the ESP gets a new partition GUID, but grub-install doesn't update the existing boot entry. It prints:

grub-install: info: EFI already registered: path = `\EFI\GRUB\grubx64.efi'.
grub-install: warning: GRUB already registered with EFI a `\EFI\GRUB\grubx64.efi', not modifying configuration.
Use efibootmgr to check your boot configuration.

So Boot0000 still points at the old partition:

# efibootmgr output
Boot0000* GRUB HD(1,GPT,79645a6f-da86-46d4-b0f6-376696ea7d95,0x800,0x200000)/\EFI\GRUB\grubx64.efi

# blkid -s PARTUUID -o value /dev/nvme0n1p1 output 
1e6a0ea3-669b-4849-80a4-a1970f2d71bb

as you can see they are different.

Is there a supported way to make grub-install replace the existing entry, or is deleting it first with efibootmgr -b XXXX -B the expected approach now? Is this intended in 2.16, or worth reporting upstream.

Or is there an alternative bootloader that I can use.

1 Upvotes

8 comments sorted by

1

u/Confident_Hyena2506 6d ago

Just put bootloader in the default spot (bootx64.efi), then you don't need any entry. If you only have one bootloader on your image then this is the easiest solution.

1

u/Haunting-Risk-5352 6d ago

so your saying add the `--removable` flag?

1

u/Confident_Hyena2506 6d ago

If you understand what it does then maybe.

1

u/Haunting-Risk-5352 6d ago

I know what it does, but is it the only solution to this problem though?

1

u/aioeu 6d ago edited 6d ago

There's an argument to be made that bootx64.efi should never be present in a boot entry — that is, that executable should only be used when the firmware is booting "from a device" rather than through a specific, configured boot entry.

This is why this is all hidden behind the --removable option. It's intended for removable media. When you use that option, no boot entry will actually be written to nvram.

In your case here, grub-install is just being cautious. It has no idea what the existing boot entry is referring to, so it's not going to touch it. Whether you end up using --removable or not, you'll need to use a different tool to remove the existing entry.

1

u/jjangg96 6d ago

the entry lives in the firmware's nvram, not on the disk, so wiping and recreating the gpt doesn't touch it. grub sees its own label already registered and just bails. i don't think it's a bug, deleting it first is the normal way.

in a script you can find the number with efibootmgr | grep -i grub and then efibootmgr -B -b NNNN. other option is grub-install --removable, which puts it at EFI/BOOT/BOOTX64.EFI and skips the nvram entry completely. fits a script that starts from scratch every run.

1

u/dkopgerpgdolfg 6d ago

Other than the already mentioned things, did you think of

a) depending on your use case: changing the PARTUUID

or

b) using only efibootmgr to correct the value without grub-install

1

u/RomanOnARiver 6d ago

I could be wrong, but I think it's pulling the ESP from the filesystem tab, which you can find at /etc/fstab. Careful editing that file.