Jump to content

Dual Booting NixOS and Windows: Difference between revisions

→‎Grub: Remove old info
imported>Sinity
No edit summary
(→‎Grub: Remove old info)
 
(14 intermediate revisions by 8 users not shown)
Line 1: Line 1:
= Bootloader =
This section explains various methods to have the bootloader prompt whether to boot windows or NixOS.
 
== Autodetection ==
 
=== systemd-boot ===
 
When {{ic|systemd-boot}} is installed to the same EFI System Partition (ESP) that Windows uses, it will automatically detect the Windows installation ({{ic|/EFI/Microsoft/Boot/bootmgfw.efi}}) and present it as a boot option.
 
You can verify detected boot loaders by running the {{ic|bootctl}} command.
 
A system pre-installed with Windows might have a small ESP partition size that is not sufficient to store the kernel and initrd files for multiple NixOS generations. One solution is to create an additional [https://uapi-group.org/specifications/specs/boot_loader_specification/#the-partitions XBOOTLDR] partition and configure {{ic|systemd-boot}} to use it:


This section explains various methods to have the bootloader prompt whether to boot windows or NixOS.
{{File|/etc/nixos/configuration.nix|nix|<nowiki>
{
  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/57D4-A2B2";
      fsType = "vfat";
    };
  fileSystems."/efi" =
    { device = "/dev/disk/by-uuid/3280-5418";
      fsType = "vfat";
    };
 
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
 
  boot.loader.efi.efiSysMountPoint = "/efi";
  boot.loader.systemd-boot.xbootldrMountPoint = "/boot";
}
</nowiki>}}


== Autodetection with os-prober ==
=== os-prober ===


<code>os-prober</code> is a tool to autodetect which other systems are present on the machine. Grub can be
<code>os-prober</code> is a tool to autodetect which other systems are present on the machine. Grub can be
Line 12: Line 39:
   # ...
   # ...
   boot.loader.grub.enable = true;
   boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
   boot.loader.grub.device = "nodev";
   boot.loader.grub.device = "/dev/sda";
   boot.loader.grub.useOSProber = true;
   boot.loader.grub.useOSProber = true;
   # ...
   # ...
Line 19: Line 45:
}</nowiki>}}
}</nowiki>}}


== Manual bootloader configuration ==
== Manual configuration ==
In case <code>os-prober</code> does not detect your windows partition you can configure your bootloader manually to find it.
In case <code>os-prober</code> does not detect your windows partition you can configure your bootloader manually to find it.


Line 26: Line 52:
All MBR bootloaders will need at least some configuration to chainload Windows.
All MBR bootloaders will need at least some configuration to chainload Windows.


==== Grub ====
==== Grub ====


Here is an example config:
Here is an example config:
Line 34: Line 60:
   # ...
   # ...
   boot.loader.grub.enable = true;
   boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
   boot.loader.grub.device = "/dev/sda";
   boot.loader.grub.device = "/dev/sda";
   boot.loader.grub.extraEntries = ''
   boot.loader.grub.extraEntries = ''
Line 44: Line 69:
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 ===
=== UEFI ===


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 53: Line 78:


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


Here we assume:
Here we assume:
Line 93: Line 115:
       '';
       '';
       version = 2;
       version = 2;
    };
  };
}</nowiki>}}
==== EFI with multiple disks ====
When Windows is installed on another disk with a separate EFI partition, the following might work:
{{File|/etc/nixos/configuration.nix|nix|<nowiki>
{ config, ... }:
{
  boot.loader = {
    efi.canTouchEfiVariables = true;
    grub = {
      enable = true;
      devices = [ "nodev" ];
      efiSupport = true;
      useOSProber = true;
     };
     };
   };
   };
Line 103: Line 144:
Setting RTC time standard to localtime, compatible with Windows in its default configuration:
Setting RTC time standard to localtime, compatible with Windows in its default configuration:


{{File|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{ config, pkgs, ... }: {
{
  # ...
   time.hardwareClockInLocalTime = true;
   time.hardwareClockInLocalTime = true;
  # ...
}</nowiki>}}
}</nowiki>}}


Sources:
See [https://wiki.archlinux.org/title/System_time#Time_standard Arch Linux wiki#System time].
* [https://wiki.archlinux.org/index.php/GRUB#Windows_installed_in_UEFI-GPT_Mode_menu_entry Arch Wiki GRUB article]
 
== See also ==
* [https://wiki.archlinux.org/index.php/GRUB#Windows_installed_in_UEFI-GPT_Mode_menu_entry Arch Linux wiki#GRUB]
* [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>)
[[Category:Cookbook]][[Category:NixOS]]
142

edits