X-Git-Url: https://pwan.org/git/?p=pwan.org.git;a=blobdiff_plain;f=content%2Flessons%2FNixos.rst;fp=content%2Flessons%2FNixos.rst;h=53f71aa03f61610b1dee4914660c8cdf97c47451;hp=0000000000000000000000000000000000000000;hb=6b4cb8e61e634b989a887c60fdd26d7140a8224f;hpb=78cc7b9eb414b40bc21c491f6809929573fffc7b diff --git a/content/lessons/Nixos.rst b/content/lessons/Nixos.rst new file mode 100644 index 0000000..53f71aa --- /dev/null +++ b/content/lessons/Nixos.rst @@ -0,0 +1,96 @@ +NixOS Installation Stumbling Blocks +################################### + +:date: 2017-09-04 +:tags: lessons,nixos +:category: lessons +:author: Jude N + +Here are some issues I ran into installing `NixOS`_ and how I eventually got around them. + + +Setting up a static IP since DHCP wasn't available. +--------------------------------------------------- +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: + +.. code-block:: bash + + ifconfig enp0s3 netmask + route add default gw + echo "nameserver 8.8.8.8" >> /etc/resolv.conf + + +Partitioning the disk +--------------------- +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. + +- A 20G disk split into /dev/sda1 and /dev/sda2 +- /dev/sda1 is a 400MB 'WIN VFAT32' partition (type 'b', not type '4' !!) +- /dev/sda2 is a LVM partition with the rest of the space +- For the LVM, /dev/vg/swap is an 8G swap partition and /dev/vg/root has the rest of the LVM parition + +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. + +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'. ¯\\_(ツ)_/¯ + +I think I also ran into problems using fsck on the boot partition instead of fsck.vfat. + +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. + +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. + +Mounting the boot partition +--------------------------- +Before running nixos-install, I had to also mount the boot partition under /mnt/boot: + +.. code-block:: bash + + > mount /dev/vg/root /mnt + > mkdir -p /mnt/boot + > mount /dev/sda1 /mnt/boot + > nixos-install + + +Verify the /mnt/etc/nixos/hardware-configuration.nix device paths +----------------------------------------------------------------- +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. + +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'. + +It looks like nixos-install isn't verifying the device paths are valid, since nixos-install ran OK with the invalid device paths. + + +Configuring a static IP in /mnt/etc/nixos/configuration.nix +----------------------------------------------------------- +Here's what I ended up adding to the configuration.nix file to set up static IP: + +.. code-block:: bash + + networking = { + hostName = ''; + usePredictableInterfacenames = false; + interfaces.eth0.ip4 = [{ + address= ""; + prefixLength = ; + }]; + defaultGateway = "" + nameservers = [ "8.8.8.8" ]; + }; + +I also adding this boot setting: + +.. code-block:: bash + + boot.load.grub.device = "/dev/sda"; + +Sources +------- +- 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) +- https://gist.github.com/martijnvermaat/76f2e24d0239470dd71050358b4d5134 +- https://polycrystal.org/posts/2014-10-27-installing-nix.html + +.. _NixOS: https://nixos.org/ +.. _UEFI with ovirt: https://bugzilla.redhat.com/show_bug.cgi?id=1327846 +.. _this one: https://askubuntu.com/questions/119597/grub-rescue-error-unknown-filesystem +.. _this other one: https://www.linux.com/learn/how-rescue-non-booting-grub-2-Linux +.. _testdisk: http://www.cgsecurity.org/wiki/TestDisk