I run encrypted ZFS with NixOS on my desktop. I recently bought some hard drives to use as bulk media storage as my phone and laptop were running out of space. I read up on ZFS documentation, ran sudo zpool create storage mirror /dev/sda /dev/sdb
(unencrypted intentionally - it’s on my todo list to switch my desktop to be fully unencrypted so I can reboot remotely), and everything seemed to go well. ZFS auto-mounted the storage at /storage
without explicit configuration from me. This was all fine and dandy and worked well before and after reboots.
This morning I was attempting to upgrade NixOS, but hit several problems (broken package builds, but more annoyingly bugs in nixos-rebuild
). In my process of trying to get builds to work, I rolled back to an earlier NixOS install from the boot menu (likely one before I had set up the ZFS configuration) and rebuilt (without the broken package) from there. The rebuild (and upgrade) succeeded. A little while later, I noticed /storage
was empty. This freaked me out quite a deal.
I started trying to figure out why ZFS didn’t load in my drives. Nothing came up immediately in any of the ZFS systemd service statuses. While fdisk
recognized the physical drives existed, zpool status
, zfs list
, and zfs mount
did not. I started looking around to see if anyone else had this problem and could not find anything: though it’s a little hard to search for. Then I tried adding the /storage
drive to fileSystems
in my hardware configuration file: fileSystems."/storage" = { device = "storage"; fsType = "zfs"; };
. This was a very bad idea. Upon running nixos-rebuild --upgrade
my desktop crashed to tell me “You are in emergency mode.”
So, some stuff I could really use some help with:
-
Why does ZFS not recognize that my two drives at
/dev/sda
and/dev/sdb
should form a mirrored pool?fdisk
certainly recognizes that these drives exist. Butzfs list
,zpool status
, etc show no indication that they do. -
What was it that likely happened to get my drives into this unreadable state to begin with? Was it rolling back to an earlier boot version from the boot menu? Was it rebuilding the system? Was it upgrading the system?
-
What did adding the drives to fileSystems do that made my computer immediately choke and die?
-
How can I avoid this in the future, recover my data now, and get ZFS to auto-mount my mirrored storage drives at
/storage
?
Any help or suggestions for debugging would be appreciated. I’m really very worried I’ve accidentally corrupted the data on these drives.