Dual booting NixOS and Windows 10 - A step by step guide

Here’s a step by step guide on how to dual boot Windows 10 and NixOS.

  1. Install windows
  2. Update windows completely
  3. Turn off “Fast startup”. Open Control panel -> System & Security -> Power Options, click “Choose what the power buttons do” -> “Change settings that are currently unavailable” -> Uncheck -> Save changes.
  4. Open “Disk Management” and make sure you have free space on your disk. One thing you can do is to shrink the Windows volume to free up space on the end of the disk. This free space will be used for NixOS.
  5. Make sure “Secure boot” is disabled in BIOS
  6. Download NixOS and get the ISO over to a USB stick
    1. Using Rufus:
      1. Partition scheme: GPT
      2. Target system: UEFI (non CSM)
      3. File system: FAT32
      4. Cluster size: 8192 bytes
  7. Reboot the stationary computer and hit F11 while it’s starting to open the boot menu
  8. Select “UEFI: SanDisk” from the boot options. If you use a different USB stick in the future then that “SanDisk” name will differ, but do select the one prefixed with “Uefi: “.
  9. Install NixOS (loosely following https://stianlagstad.no/2020/06/how-to-install-nixos-on-a-dell-precision-5530/)
    1. sudo su
    2. Do [ -d /sys/firmware/efi/efivars ] && echo "UEFI" || echo "fail" to verify that we’re in UEFI mode. If this command prints “fail” then you need to go into the BIOS setting and fix that.
    3. Do lsblk to see the disk overview. My disk is called “nvme0n1”. Yours may be called something different. I see that a few partitions that have already been created by Windows. In my case there are 4 partitions in use after the Windows install:
      1. One 529M disk
      2. One 99M disk
      3. One 16M disk
      4. And one with the actual Windows install, a ~200G disk.
    4. Open gdisk: gdisk /dev/nvme0n1
      1. Press n to create a new partition
      2. Hit enter to select the suggested partition number (in my case: 5)
      3. Hit enter to select the default value for the first sector
      4. Hit enter to select the default value for the second sector
      5. Write 8e00 and hit enter to select “Linux LVM” as the partition type
      6. Press w to write the changes
    5. lsblk is now telling me that I have a new partition on the nvme0n1 disk, called nvme0n1p5 - a partition that fills up the rest of the disk.
    6. Setup encryption
      1. Format the partition: cryptsetup luksFormat /dev/nvme0n1p5 and select a password.
      2. Open the formatted partition: cryptsetup luksOpen /dev/nvme0n1p5 nvme0n1p5-crypt and enter the password that you chose.
    7. lsblk should now show you nvme0n1p5-crypt as an entry under nvme0n1p5
    8. Setup LVM within the encrypted partition
      1. Initiate a physical volume to be used by LVM: pvcreate /dev/mapper/nvme0n1p5-crypt
      2. Create a volume group: vgcreate vgnixos /dev/mapper/nvme0n1p5-crypt
      3. Create a swap volume: lvcreate -C y -L 32G -n swap vgnixos. I’m choosing 2x the size of the RAM that I have on my stationary machine.
      4. Create a volume for the rest of the space: lvcreate -l 100%FREE -n nixos vgnixos
    9. lsblk should now show the volume group
    10. Create file systems
      1. Make vgnixos-nixos an ext4 filesystem: mkfs.ext4 /dev/vgnixos/nixos
      2. Make swap: mkswap -L swap /dev/vgnixos/swap
      3. mount /dev/vgnixos/nixos /mnt
      4. mkdir /mnt/boot
      5. mount /dev/nvme0n1p2 /mnt/boot - NOTE which partition to use here! One of the Windows partitions is the boot partition. The one that’s vfat.
      6. swapon /dev/vgnixos/swap
      7. Check the UUID of the LVM: lsblk -f and make note of it! (Here it’s important that you note the UUID of the “crypto_LUKS” disk. You will need to tell NixOS to use that disk by specifying the UUID later.)
    11. Make sure you have an internet connection
      1. wpa_passphrase 'name_of_wifi' 'password' > /etc/wpa_supplicant.conf
      2. systemctl start wpa_supplicant.service
      3. systemctl status wpa_supplicant.service - try this command a couple of times until you see that it has started
      4. ping google.com should now show that you have an internet connection. You may have to try this a few times as well.
    12. Install NixOS
      1. Generate nix config: nixos-generate-config --root /mnt
      2. Open the config: vi /mnt/etc/nixos/configuration.nix and update to match something like what’s shown here
      3. Finally, install NixOS by executing: nixos-install. After running for a while, the nixos-install command should complete successfully.

Andy White’s notes helped me through this - thanks Andy!


comments powered by Disqus