ThinkCenter UEFI hack
I have an old Lenovo ThinkCenter M91p, which I use to host BorgBackup repository and my music library with Navidrome.
Up untill last week I had NixOS installed on it with Legacy Boot.
It worked fine for a while, but after an update, GRUB started to
complain that it couldn’t find /grub/i386-pc/normal.mod
file anymore. I suspect that it had to do something with me pairing
it with BTRFS partition.
Without looking too much into it, I decided to finally take my time and setup NixOS with UEFI. After all, because of nix, I have to only deal with this once (right?).
I knew that ThinkCenters UEFI implementation did not follow standards. You can tell immediately by installing linux distribution of your choice and being greeted with this message after reboot:
Error 1962 “No Operating System Found”
After digging through “the internet” I have found a solution:
This is an error specific to some models of Lenovo computers. […] To fix this issue you need to add a custom EFI entry from within the live environment. You will name the custom entry “Windows Boot Manager” to trick the BIOS. Here’s an example on how to do that:
sudo efibootmgr -c \ -d /dev/sda1 -p 1 \ -L "Windows Boot Manager" \ -l "\EFI\boot\grubx64.efi"
Interesting, should be fairly easy to add this to my config:
boot.loader.systemd-boot.extraInstallCommands =
let
efimgr = "${pkgs.efibootmgr}/bin/efibootmgr";
grep = "${pkgs.toybox}/bin/grep";
new = "Windows Boot Manager";
old = "Linux Boot Manager";
in
''
echo "Applying 'ThinkCenter' hack"
${efimgr} --label "${old}" -B -q 2>/dev/null || echo "EFI entry '${old}' already deleted"
if [ -z "$(${efimgr} | ${grep} "${new}")" ]; then
echo "Creating '${new}' EFI entry"
${efimgr} --create -q \
--label "${new}" \
--loader '\EFI\systemd\systemd-bootx64.efi' \
--disk ${cfg.device} \
--part 1
else
echo "EFI entry '${new}' already exists"
fi
'';Lets see how long it takes before this breaks.