Jump to content

Dual Booting NixOS and Windows: Difference between revisions

mention os-prober
imported>Samueldr
m (→‎EFI + Grub: Fixes comment, the previous statement wasn't false, but may have been surprising when compared to the installation section of the manual)
imported>Symphorien
(mention os-prober)
Line 1: Line 1:
== MBR ==
This article explains various methods to have the bootloader prompt whether to boot windows or NixOS.
 
== Autodetection with os-prober ==
 
<code>os-prober</code> is a tool to autodetect which other systems are present on the machine. Grub can be
told to use os-prober to add a menu-entry for each of them.
 
{{File|/etc/nixos/configuration.nix|nix|<nowiki>
{ config, pkgs, ... }: {
  # ...
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  boot.loader.grub.device = "/dev/sda";
  boot.loader.grub.useOSProber = true;
  # ...
 
}</nowiki>}}
 
== Manual bootloader configuration ==
In case <code>os-prober</code> does not detect your windows partition you can configure your bootloader manually to find it.
 
=== MBR ===


All MBR bootloaders will need at least some configuration to chainload Windows.
All MBR bootloaders will need at least some configuration to chainload Windows.


=== MBR + Grub ===
==== Grub ====


When using MBR on your disk then you can configure grub chain-loading:
Here is an example config:


<syntaxhighlight lang="nix">{
{{File|/etc/nixos/configuration.nix|nix|<nowiki>
{ config, pkgs, ... }: {
  # ...
   boot.loader.grub.enable = true;
   boot.loader.grub.enable = true;
   boot.loader.grub.version = 2;
   boot.loader.grub.version = 2;
Line 16: Line 39:
     }
     }
   '';
   '';
}</syntaxhighlight>
}</nowiki>}}
Source: https://www.reddit.com/r/NixOS/comments/31lx3i/windows_and_nixos_dual_boot/
Source: https://www.reddit.com/r/NixOS/comments/31lx3i/windows_and_nixos_dual_boot/


== EFI ==
=== EFI ===


After setting up a 256mb EFI Partition dualboot should work out of the box (at least for windows10)
After setting up a 256mb EFI Partition dualboot should work out of the box (at least for windows10)
Line 25: Line 48:
Source: https://zimbatm.com/journal/2016/09/09/nixos-window-dual-boot/
Source: https://zimbatm.com/journal/2016/09/09/nixos-window-dual-boot/


=== EFI + Grub ===
==== Grub ====


<nowiki>systemd-boot</nowiki> can not load EFI binaries from other partitions,
<nowiki>systemd-boot</nowiki> can not load EFI binaries from other partitions,
Line 32: Line 55:
Here we assume:
Here we assume:
* the EFI partition has been mounted on <nowiki>/boot/efi</nowiki>
* the EFI partition has been mounted on <nowiki>/boot/efi</nowiki>
* <nowiki>$FS_UUID</nowiki> is the UUID of the EFI partition
* <code>$FS_UUID</code> is the UUID of the EFI partition
* the <nowiki>boot.loader.systemd-boot.enable = true;</nowiki> line added to configuration.nix by <nowiki>nixos-generate-config</nowiki> has been removed
* the <code>boot.loader.systemd-boot.enable = true;</code> line added to configuration.nix by <code>nixos-generate-config</code> has been removed


<syntaxhighlight lang="nix">
{{File|/etc/nixos/configuration.nix|nix|<nowiki>
{ config, ... }:
{ config, ... }:


Line 68: Line 91:
     };
     };
   };
   };
}</syntaxhighlight>
}</nowiki>}}


Sources:
Sources:
* [https://wiki.archlinux.org/index.php/GRUB#Windows_installed_in_UEFI-GPT_Mode_menu_entry Arch Wiki GRUB article]
* [https://wiki.archlinux.org/index.php/GRUB#Windows_installed_in_UEFI-GPT_Mode_menu_entry Arch Wiki GRUB article]
* [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/loader/grub/install-grub.pl NixOS GRUB installer] (check the code block beginning with <nowiki># install EFI GRUB</nowiki>)
* [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/loader/grub/install-grub.pl NixOS GRUB installer] (check the code block beginning with <nowiki># install EFI GRUB</nowiki>)
Anonymous user