Dual Booting NixOS and Windows: Difference between revisions

From NixOS Wiki
imported>Samueldr
m Fixes title levels (= → ==)
imported>Samueldr
m Mirrors structure for == MBR ==
Line 1: Line 1:
== MBR + Grub ==
== MBR ==
 
All MBR bootloaders will need at least some configuration to chainload Windows.
 
=== MBR + Grub ===


When using MBR on your disk then you can configure grub chain-loading:
When using MBR on your disk then you can configure grub chain-loading:

Revision as of 12:04, 17 March 2018

MBR

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

MBR + Grub

When using MBR on your disk then you can configure grub chain-loading:

{
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  boot.loader.grub.device = "/dev/sda";
  boot.loader.grub.extraEntries = ''
    menuentry "Windows 7" {
      chainloader (hd0,1)+1
    }
  '';
}

Source: https://www.reddit.com/r/NixOS/comments/31lx3i/windows_and_nixos_dual_boot/

EFI

After setting up a 256mb EFI Partition dualboot should work out of the box (at least for windows10)

Source: https://zimbatm.com/journal/2016/09/09/nixos-window-dual-boot/

EFI + Grub

systemd-boot can not load EFI binaries from other partitions, and a pre-exisitng EFI partition from a Windows install may be smaller than we would like our /boot partition to be. If we still want Windows and NixOS to use the same EFI partition, we can use GRUB instead.

Here we assume:

  • the EFI partition has been mounted on /boot/efi
  • $FS_UUID is the UUID of the EFI partition
  • the boot.loader.systemd-boot.enable = true; line added to configuration.nix by nixos-generate-config has been removed
{ config, ... }:

{
  boot.loader = {
    efi = {
      canTouchEfiVariables = true;
      # assuming /boot/efi is the mount point of the  EFI partition in NixOS
      efiSysMountPoint = "/boot/efi";
    };
    grub = {
      # despite what the configuration.nix manpage seems to indicate,
      # as of release 17.09, setting device to "nodev" will still call
      # `grub-install` if efiSupport is true
      # (the devices list is not used by the EFI grub install,
      # but must be set to some value in order to pass an assert in grub.nix)
      devices = [ "nodev" ];
      efiSupport = true;
      enable = true;
      # set $FS_UUID to the UUID of the EFI partition
      extraEntries = ''
        menuentry "Windows" {
          insmod part_gpt
          insmod fat
          insmod search_fs_uuid
          insmod chain
          search --fs--uid --set=root $FS_UUID
          chainloader /EFI/Microsoft/Boot/bootmgfw.efi
        }
      '';
      version = 2;
    };
  };
}

Sources: