# EFI notes ## Dual Boot We can use the EFI `NextBoot` feature to signal that the system should boot the 2nd OS. For initial setup, find the 2nd OS boot entry: ```sh PS C:\Users\pleb\Documents\windows-scripts> PowerShell.exe -ExecutionPolicy Bypass -File .\List-BootEntries.ps1 Found Boot0000 Found Boot0002 ``` Hard-code the boot entry in the `Set-BootNext.ps1` script: ```powershell # NixOS boot entry ID $NixOSBootEntryID = "0002" ``` Then whenever you want to run NixOS, run the script: ```sh PowerShell.exe -ExecutionPolicy Bypass -File \Users\pleb\Documents\windows-scripts\Set-BootNext.ps1 ``` ## EFI Recovery Sometimes Windows Update will trample the EFI boot entry for NixOS. ## Linux * Boot into a NixOS live environment (USB or CD). * Mount your NixOS root partition and the ESP (EFI System Partition): ```sh mount /dev/nvme0n1p4 /mnt mount /dev/nvme0n1p1 /mnt/boot ``` * Chroot into your NixOS installation: ```sh nixos-enter --root /mnt ``` * Manually reinstall the bootloader: ```sh bootctl install --path /boot ``` * Exit the chroot environment: ```sh exit ``` * Unmount the partitions: ```sh umount /mnt/boot umount /mnt ``` 8. Ensure the boot order is to your satisfaction ```sh efibootmgr -v efibootmgr -o XXXX,YYYY ``` 9. Reboot your system. By following these steps, you should be able to recover your NixOS boot option if it disappears after a Windows update. ## Windows In the unlikely scenario that the Windows boot entry is removed, here's how to recover from that: * Mount the EFI System Partition if it's not already mounted: ```sh mount /dev/nvme0n1p1 /mnt/boot ``` (Replace nvme0n1p1 with the correct partition if different) * Verify that the Windows bootloader files exist: ```sh ls /mnt/boot/EFI/Microsoft/Boot/ ``` You should see a file named `bootmgfw.efi`. * If the files are present, you can create a new boot entry for Windows using `efibootmgr`: ```sh efibootmgr -c -d /dev/nvme0n1 -p 1 -L "Windows" -l '\EFI\Microsoft\Boot\bootmgfw.efi' ``` This command creates a new boot entry labeled "Windows" that points to the Windows bootloader file. * Verify that the new entry was created: ```sh efibootmgr -v ```