I found a solution how we can change the prefix permanently.
However, it has the following caveats: We have to change it directly inside the grubx64.efi binary file, and we have to keep the file the same length. And how much space you are given may depend on your distribution. Read along for further explanation.
Disclaimers
- If you want to do this you will have to turn off secure boot as the hash will have changed and the binary will be rejected. Not sure if this can be fixed by installing your own hashes (search for MOK).
- Always make backups of the files you are changing. If you do as I did, you will be able to reverse your changes with a bootable USB stick. If you do not have another system at hand, then please create a bootable USB now and test if you can boot into it.
First the Problem:
Basically, this whole issue is a limitation of Secure Boot. For Secure Boot to accept the grubx64.efi file, it must be signed by an accepted authority. Therefore, this grub executable is signed and prebaked. The current standard to set this prefix seems to be /EFI/$(lsb_release -i -s)
.
This of course also means that - no matter which loader path (for example efibootmgr--loader \\EFI\\other\\SSHIMX64.efi
) - you specify when creating a new boot option, it will have no effect on the prefix variable in the grub bootloader.
The solution:
Let's assume our distro is ubuntu
and we would like to rename that to longubuntu
for some reason, we can do so following these steps:
# List contents of EFI directory
find /boot/efi/EFI;
# Rename the directory
mv /boot/efi/EFI/ubuntu /boot/efi/EFI/longubuntu;
# List contents of EFI/longubuntu for easy access
find /boot/efi/EFI/longubuntu;
# Always make a copy of the original
cp /boot/efi/EFI/longubuntu/BOOTX64.CSV /boot/efi/EFI/longubuntu/BOOTX64.CSV.bak
# Inside the .csv-file change 'ubuntu' to 'longubuntu'
nano /boot/efi/EFI/longubuntu/BOOTX64.CSV
Before proceeding:
Check that there are enough nul-characters available in the binary file. It is important to keep the overall length the same. If you don't do that, it will throw an error - if this happens to you, then copy back the original grubx64.efi and try again. When inspecting my grubx64.efi-binary with VS Code I do have enough available to change the prefix to my hearts content:
![Many nul-characters directly behind /EFI/ubuntu](https://cdn.statically.io/img/i.sstatic.net/gsrmn.png)
Now to the fun and critical part:
As I already said, we need to make sure that we keep the binary file the same length. We can so by either padding the new prefix with nul-chars (\0
) or by padding the text to replace with nul-chars.
So if you want to specify a longer prefix (as in my case), you can do so with:
# Parameter -pi.bak will create a backup for you
perl -pi.perlbak -e 's/EFI\/ubuntu\0\0\0\0/EFI\/longubuntu/g' /boot/efi/EFI/longubuntu/grubx64.efi
If you choose a shorter prefix (for example bent
), then pad the new value with \0
:
# Parameter -pi.bak will create a backup for you
perl -pi.perlbak -e 's/EFI\/ubuntu/EFI\/bent\0\0/g' /boot/efi/EFI/longubuntu/grubx64.efi
You can check the results of your operation with, which will print the line containing the prefix.
$~: grep -a 'EFI\/longubuntu' /boot/efi/EFI/longubuntu/grubx64.efi
Which prints:
![Grep will print the new prefix.](https://cdn.statically.io/img/i.sstatic.net/qvHAJ.png)
Do not forget to add a new boot option!
I will use efibootmgr
. With efibootmgr
we can delete the old boot option and add a new one.
# Print current boot options
:~# efibootmgr -v
BootCurrent: 0000
Timeout: 1 seconds
BootOrder: 0000
Boot0000* ubuntu HD(1,GPT,28bd5547-5802-4f9c-97da-22ddd968dea6,0x800,0x100000)/File(\EFI\UBUNTU\SHIMX64.EFI)
# Delete current
:~# efibootmgr -b 0 -B
# List disks
:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
[...]
nvme0n1 259:0 0 238.5G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
└─nvme0n1p2 259:2 0 238G 0 part /
# Create new boot option
:~# efibootmgr --create --disk /dev/nvme0n1 --part 1 --label "Long Ubuntu Name" --loader \\EFI\\longubuntu\\shimx64.efi
Enjoy:
When you reboot now. You should still boot into your distribution as before.
If not, then boot into the USB stick and mount the EFI-partition. Then undo the changes or copy back the original file. On my device, I mount the EFI-partition like so:
:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
[...]
nvme0n1 259:0 0 238.5G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
└─nvme0n1p2 259:2 0 238G 0 part /
:~# mkdir -p /media/efi; mount /dev/nvme0n1p1 /media/efi