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.
- Install windows
- Update windows completely
- 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.
- 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.
- Make sure “Secure boot” is disabled in BIOS
- Download NixOS and get the ISO over to a USB stick
- Using Rufus:
- Partition scheme: GPT
- Target system: UEFI (non CSM)
- File system: FAT32
- Cluster size: 8192 bytes
- Using Rufus:
- Reboot the stationary computer and hit F11 while it’s starting to open the boot menu
- 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: “.
- Install NixOS (loosely following https://stianlagstad.no/2020/06/how-to-install-nixos-on-a-dell-precision-5530/)
sudo su- 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. - Do
lsblkto 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:- One 529M disk
- One 99M disk
- One 16M disk
- And one with the actual Windows install, a ~200G disk.
- Open gdisk:
gdisk /dev/nvme0n1- Press
nto create a new partition - Hit enter to select the suggested partition number (in my case: 5)
- Hit enter to select the default value for the first sector
- Hit enter to select the default value for the second sector
- Write
8e00and hit enter to select “Linux LVM” as the partition type - Press
wto write the changes
- Press
lsblkis 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.- Setup encryption
- Format the partition:
cryptsetup luksFormat /dev/nvme0n1p5and select a password. - Open the formatted partition:
cryptsetup luksOpen /dev/nvme0n1p5 nvme0n1p5-cryptand enter the password that you chose.
- Format the partition:
lsblkshould now show younvme0n1p5-cryptas an entry undernvme0n1p5- Setup LVM within the encrypted partition
- Initiate a physical volume to be used by LVM:
pvcreate /dev/mapper/nvme0n1p5-crypt - Create a volume group:
vgcreate vgnixos /dev/mapper/nvme0n1p5-crypt - 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. - Create a volume for the rest of the space:
lvcreate -l 100%FREE -n nixos vgnixos
- Initiate a physical volume to be used by LVM:
lsblkshould now show the volume group- Create file systems
- Make vgnixos-nixos an ext4 filesystem:
mkfs.ext4 /dev/vgnixos/nixos - Make swap:
mkswap -L swap /dev/vgnixos/swap mount /dev/vgnixos/nixos /mntmkdir /mnt/bootmount /dev/nvme0n1p2 /mnt/boot- NOTE which partition to use here! One of the Windows partitions is the boot partition. The one that’s vfat.swapon /dev/vgnixos/swap- Check the UUID of the LVM:
lsblk -fand 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.)
- Make vgnixos-nixos an ext4 filesystem:
- Make sure you have an internet connection
wpa_passphrase 'name_of_wifi' 'password' > /etc/wpa_supplicant.confsystemctl start wpa_supplicant.servicesystemctl status wpa_supplicant.service- try this command a couple of times until you see that it has startedping google.comshould now show that you have an internet connection. You may have to try this a few times as well.
- Install NixOS
- Generate nix config:
nixos-generate-config --root /mnt - Open the config:
vi /mnt/etc/nixos/configuration.nixand update to match something like what’s shown here - Finally, install NixOS by executing:
nixos-install. After running for a while, the nixos-install command should complete successfully.
- Generate nix config:
Andy White’s notes helped me through this - thanks Andy!