Checkpoint
[pwan.org.git] / content / lessons / Nixos.rst
1 NixOS Installation Stumbling Blocks
2 ###################################
3
4 :date: 2017-09-04
5 :tags: lessons,nixos
6 :category: lessons
7 :author: Jude N
8
9 Here are some issues I ran into installing `NixOS`_ and how I eventually got around them.
10
11
12 Setting up a static IP since DHCP wasn't available.
13 ---------------------------------------------------
14 My VM was hosted in an oVirt cluster where DHCP wasn't working/configured, so the installation CD booted without a network. Here's how I manually configred a static IP:
15
16 .. code-block:: bash
17
18 ifconfig enp0s3 <my-static-ip> netmask <my-netmask>
19 route add default gw <gateway-ip>
20 echo "nameserver 8.8.8.8" >> /etc/resolv.conf
21
22
23 Partitioning the disk
24 ---------------------
25 I spent a lot of time messing with various partitioning schemes until I stumbled across one that worked. I didn't need disk encryption, and I didn't want to bother trying `UEFI with ovirt`_, so here's what I ended up with.
26
27 - A 20G disk split into /dev/sda1 and /dev/sda2
28 - /dev/sda1 is a 400MB 'WIN VFAT32' partition (type 'b', not type '4' !!)
29 - /dev/sda2 is a LVM partition with the rest of the space
30 - For the LVM, /dev/vg/swap is an 8G swap partition and /dev/vg/root has the rest of the LVM parition
31
32 In retrospect, I think a lot of my partitioning pain may have been caused by trying to have /dev/sda1 set as a BIOS Parition (type '4'), since I suspect the BIOS partition has to be under 32M.
33
34 Also in retrospect, I see only 23M is actually used on the current /boot parition, so maybe 400MB was way too much and I should have gone with /dev/sda1 being 32M and type '4'. ¯\\_(ツ)_/¯
35
36 I think I also ran into problems using fsck on the boot partition instead of fsck.vfat.
37
38 When the boot partition wasn't working, grub would fall into rescue mode and the various 'set prefix / set root / insmod' fixes like `this one`_ or `this other one`_ didn't work.
39
40 What did work here was booting the system with the install CD again, mounting /mnt/boot manually and seeing that failed, or that /mnt/boot contained gibberish after mounting, and then unmounting /mnt/boot and using `testdisk`_ to fix the partition type. Testdisk really saved the day.
41
42 Mounting the boot partition
43 ---------------------------
44 Before running nixos-install, I had to also mount the boot partition under /mnt/boot:
45
46 .. code-block:: bash
47
48 > mount /dev/vg/root /mnt
49 > mkdir -p /mnt/boot
50 > mount /dev/sda1 /mnt/boot
51 > nixos-install
52
53
54 Verify the /mnt/etc/nixos/hardware-configuration.nix device paths
55 -----------------------------------------------------------------
56 When I was messing with the disk partitioning, I rebuilt the /dev/sda1 partition a couple times. Apparently when you do that, you get new UUID for the device.
57
58 This meant the "/boot" file system in /mnt/etc/nixos/hardware-configuration.nix was using a device path that was no longer valid. I updated the file to point to the current /boot device and reran 'nixos-install'.
59
60 It looks like nixos-install isn't verifying the device paths are valid, since nixos-install ran OK with the invalid device paths.
61
62
63 Configuring a static IP in /mnt/etc/nixos/configuration.nix
64 -----------------------------------------------------------
65 Here's what I ended up adding to the configuration.nix file to set up static IP:
66
67 .. code-block:: bash
68
69 networking = {
70 hostName = '<my hostname>';
71 usePredictableInterfacenames = false;
72 interfaces.eth0.ip4 = [{
73 address= "<my ipv4 address>";
74 prefixLength = <my netmask prefix>;
75 }];
76 defaultGateway = "<my gateway>"
77 nameservers = [ "8.8.8.8" ];
78 };
79
80 I also adding this boot setting:
81
82 .. code-block:: bash
83
84 boot.load.grub.device = "/dev/sda";
85
86 Sources
87 -------
88 - https://chris-martin.org/2015/installing-nixos (useful, but I didn't want UEFI or disk encryption - I got the 'have to mount /mnt/boot' step here)
89 - https://gist.github.com/martijnvermaat/76f2e24d0239470dd71050358b4d5134
90 - https://polycrystal.org/posts/2014-10-27-installing-nix.html
91
92 .. _NixOS: https://nixos.org/
93 .. _UEFI with ovirt: https://bugzilla.redhat.com/show_bug.cgi?id=1327846
94 .. _this one: https://askubuntu.com/questions/119597/grub-rescue-error-unknown-filesystem
95 .. _this other one: https://www.linux.com/learn/how-rescue-non-booting-grub-2-Linux
96 .. _testdisk: http://www.cgsecurity.org/wiki/TestDisk