Install Grub with Custom ID – How to Install Grub with a Custom Boot-Loader ID

grub2

I'm able to reinstall grub using default boot-loader ID "ubuntu"

But if I use custom name like "MyUbuntu" I cannot make a successful grub installation.

Test installation on a well-booting Ubuntu 18.04:

1: Delete existing grub:

rm -r /boot/efi/EFI/*

2: Install new grub:

grub-install --target=x86_64-efi --bootloader-id=MyUbuntu /dev/sda

2: Update grub:

update-grub

System now boots into the Grub console.
The EFI was seeing the new boot entry in the boot menu just fine.

enter image description here
enter image description here

Just took a peak into the /boot/grub/grub.cfg, it still says:
menuentry 'Ubuntu' --class ubuntu.....

Best Answer

After I ran into systemd-boot as boot-loader I've never looked back at GRUB. systemd-boot, is in my view, way more stable and has a much better way of configuration. And by "stable" I mean it's not as vulnerable as GRUB. GRUB is so easy to break. Just adding a new disk to your box can give you big trouble (because of maybe identical boot-loader ID's that you cannot change etc.)

Only downside of systemd-boot is the lack of secure-boot support, but that's not an issue for me, and that your kernel must be located in the EFI partition, instead of root partition, as it is the case with GRUP.

With systemd-boot I got back full control of the boot-process...YES

It should be the default boot-loader instead of GRUB.

UPDATE, How to do (Debian/Ubuntu):
(This is a rather superficially guide, but I hope it will get you started. Other sources: Arhlinux.., freedesktop.. and readme..)

1: First copy the kernel files from you root partition, e.g. /boot/vmlinuz-4.9.0-8-amd64 and /boot/initrd.img-4.9.0-8-amd64, to your EFI partition. You can place them in a subfolder of your choice or even in root-folder if you like.

2: Many guides says you need access to the EFI variables, but I'm not sure if this is needed. But to test if you have, run efivar --list.
To Install if missing: apt install efivar

3: Install systemd-boot loader to the EFI partition: bootctl --path=/mnt/efi install (use you own path to your mounted EFI partition)

4: Edit the file /mnt/efi/loader/loader.conf to something like:

timeout 5
# default 6a9857a393724b7a981ebb5b8495b9e-*

(haven't figured out how to use the auto-added UUID in the file, so I just marked it out)

5: Each file in /mnt/efi/loader/entries/*.conf correspond to at boot-entry in the systemd-boot menu. So to add your current OS make a file looking something like:

title      Debian 9 :-)
linux      /debian9/vmlinuz-4.9.0-6-amd64
initrd     /debian9/initrd.img-4.9.0-6-amd64
options    root=UUID=084917b7-8be2-4e86-838d-f771a9902e08`

(Modify the path to the kernel files you copied in step 1. Modify the UUID to the filesystem-UUID of you root partition (use Linux command lsblk -o name,uuid)

General info:
bootctl will install two bootloader-files in your EFI partition:

../BOOT/BOOTX64.EFI
../systemd/systemd-bootx64.efi

These files are identical. Your EFI bios on your motherboard moust boot/point to one of them. Either do it in the BIOS directly or use the Linux command efibootmgr....

To add a new boot entries just create a new /mnt/efi/loader/entries/*.conf files which point to the right kernel files and root partition.

The kernel files MUST be located on the EFI partition (FAT32).
The EFI partition must be sized accordingly. I think the kernel files for e.g. Debian/Ubuntu is about 50-60MB. So if you have two installations you need 120MB.

Related Question