Recovering From Firmware Upgrade
Recently, I booted Windows on my laptop for the first time in a while to play Portal 2 with my son. It asked me to upgrade, and I said 'sure, upgrade the BIOS.'
And then I couldn't boot FreeBSD... The BIOS upgrade deleted all the BootXXXX variables. So it only booted Windows. I'm stuck, right? I have to download a FreeBSD image and boot off the USB drive. Or did I?
Note: Even the update program called updating the firmware updating the BIOS. BIOS is the generic term for the bit of code that runs before the OS. Sadly, it's also the term people use to describe the pre-UEFI boot environment on PCs, so it can be a confusing term to use. Firmware seems a bit better, but it's also ambiguous because different bits of hardware (like wireless cards) also need firmware loaded.
How to Recover
I was in windows. I needed to mount the system partition (EFI). So, I opened the Administrative Console and got a command prompt from there on the 'Tools' tab. This lead to the familiar C: prompt. I have no W drive. There I was able to copy FreeBSD's boot loader like so:
C:\WINDOWS\system32> mountvol w: /sC:\WINDOWS\system32>w:W:\> cd EFI\Microsoft\BootW:\EFI\Microsoft\Boot> ren bootmgfw.efi bootmgfw-back.efiW:\EFI\Microsoft\Boot> copy W:\EFI\FreeBSD\loader.efi bootmgfw.efiW:\EFI\Micorsoft\Boot>
I then rebooted from the menu.
I had remembered from my efibootmgr hacking that the boot loader was here. After I booted to FreeBSD, I was able to confirm:
% sudo efibootmgr -vBoot to FW : falseBootCurrent: 0001Timeout : 0 secondsBootOrder : 0001, 2001, 2002, 2003+Boot0001* Windows Boot Manager HD(1,GPT,f859c46d-19ee-4e40-8975-3ad1ab00ac09,0x800,0x82000)/File(\EFI\Microsoft\Boot\bootmgfw.efi)nvd0p1:/EFI/Microsoft/Boot/bootmgfw.efi /boot/efi//EFI/Microsoft/Boot/bootmgfw.efiBoot2001* EFI USB DeviceBoot2002* EFI DVD/CDROMBoot2003* EFI NetworkUnreferenced Variables:%
I was then able to add FreeBSD back with efibootmgr. I mount the ESP on /boot/efi:
% sudo efibootmgr --create --loader /boot/efi/EFI/freebsd/loader.efi --kernel /boot/kernel/kernel --activate --verbose --label FreeBSDBoot to FW : falseBootCurrent: 0001Timeout : 0 secondsBootOrder : 0000, 0001, 2001, 2002, 2003Boot0000* FreeBSD HD(1,GPT,f859c46d-19ee-4e40-8975-3ad1ab00ac09,0x800,0x82000)/File(\EFI\freebsd\loader.efi)nvd0p1:/EFI/freebsd/loader.efi /boot/efi//EFI/freebsd/loader.efiHD(6,GPT,68f0614d-c322-11e9-857a-b1710dd81c0d,0x7bf1000,0x1577e000)/File(boot\kernel\kernel)nvd0p6:boot/kernel/kernel /boot/kernel/kernel+Boot0001* Windows Boot Manager HD(1,GPT,f859c46d-19ee-4e40-8975-3ad1ab00ac09,0x800,0x82000)/File(\EFI\Microsoft\Boot\bootmgfw.efi)nvd0p1:/EFI/Microsoft/Boot/bootmgfw.efi /boot/efi//EFI/Microsoft/Boot/bootmgfw.efiBoot2001* EFI USB DeviceBoot2002* EFI DVD/CDROMBoot2003* EFI NetworkUnreferenced Variables:%
Once this is in place, I needed to undo what I'd done to Windows:
% cd /boot/efi/EFI/Microsoft/Boot% sudo mv bootmgfw-back.efi bootmgfw.efi%
I was then able to reboot to FreeBSD. And fun fact: since the boot order is 0000, 0001, that means I can boot to Windows by just typing 'quit' at the loader prompt. This causes the boot loader to exit with an error, which causes the BIOS to try the next BootXXXX variable, in this case windows.
And there it is: I was able to recover my system without downloading a USB image...
No comments:
Post a Comment