ZFS: Difference between revisions
Add short command to know the difference between different disk/by-* paths
(fixup some bits in the encrypted zfs pool tutorial) |
(Add short command to know the difference between different disk/by-* paths) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 19: | Line 19: | ||
==== boot.zfs.devNodes ==== | ==== boot.zfs.devNodes ==== | ||
If NixOS fails to import the zpool on reboot, you may need to add <syntaxhighlight lang="nix" inline>boot.zfs.devNodes = "/dev/disk/by-path";</syntaxhighlight> or <syntaxhighlight lang="nix" inline>boot.zfs.devNodes = "/dev/disk/by-partuuid";</syntaxhighlight> to your configuration.nix file. | If NixOS fails to import the zpool on reboot, you may need to add <syntaxhighlight lang="nix" inline>boot.zfs.devNodes = "/dev/disk/by-path";</syntaxhighlight> or <syntaxhighlight lang="nix" inline>boot.zfs.devNodes = "/dev/disk/by-partuuid";</syntaxhighlight> to your configuration.nix file. | ||
The differences can be tested by running <code>zpool import -d /dev/disk/by-id</code> when none of the pools are discovered, eg. a live iso. | |||
==== declarative mounting of ZFS datasets ==== | ==== declarative mounting of ZFS datasets ==== | ||
Line 86: | Line 88: | ||
'''Note:''' zpool config can significantly affect performance (especially the ashift option) so you may want to do some research. The [https://jrs-s.net/2018/08/17/zfs-tuning-cheat-sheet/ ZFS tuning cheatsheet] or [https://wiki.archlinux.org/title/ZFS#Storage_pools ArchWiki] is a good place to start. | '''Note:''' zpool config can significantly affect performance (especially the ashift option) so you may want to do some research. The [https://jrs-s.net/2018/08/17/zfs-tuning-cheat-sheet/ ZFS tuning cheatsheet] or [https://wiki.archlinux.org/title/ZFS#Storage_pools ArchWiki] is a good place to start. | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
zpool create -O encryption=on -O keyformat=passphrase -O keylocation=prompt -O compression= | zpool create -O encryption=on -O keyformat=passphrase -O keylocation=prompt -O compression=zstd -O mountpoint=none -O xattr=sa -O acltype=posixacl -o ashift=12 zpool /dev/nvme0n1p2 | ||
zfs create zpool/root | zfs create zpool/root | ||
Line 93: | Line 95: | ||
zfs create zpool/home | zfs create zpool/home | ||
mkdir /mnt | mkdir -p /mnt | ||
mount -t zfs zpool/root /mnt | mount -t zfs zpool/root /mnt -o zfsutil | ||
mkdir /mnt/nix /mnt/var /mnt/home | mkdir /mnt/nix /mnt/var /mnt/home | ||
Line 140: | Line 142: | ||
{ | { | ||
# Boot loader config for configuration.nix: | # Boot loader config for configuration.nix: | ||
boot.loader. | boot.loader.systemd-boot.enable = true; | ||
# for local disks that are not shared over the network, we don't need this to be random | # for local disks that are not shared over the network, we don't need this to be random | ||
Line 156: | Line 150: | ||
device = "zpool/root"; | device = "zpool/root"; | ||
fsType = "zfs"; | fsType = "zfs"; | ||
# the zfsutil option is needed when mounting zfs datasets without "legacy" mountpoints | |||
options = [ "zfsutil" ]; | options = [ "zfsutil" ]; | ||
}; | }; | ||
Line 180: | Line 175: | ||
device = "/dev/disk/by-partlabel/boot"; | device = "/dev/disk/by-partlabel/boot"; | ||
fsType = "vfat"; | fsType = "vfat"; | ||
}; | }; | ||
Line 189: | Line 183: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Importing on boot == | == Importing on boot == | ||
Line 211: | Line 203: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Zpool created with bus-based disk names === | |||
If you used bus-based disk names in the <syntaxhighlight inline>zpool create</syntaxhighlight> command, e.g., <syntaxhighlight inline>/dev/sda</syntaxhighlight>, NixOS may run into issues importing the pool if the names change. Even if the pool is able to be mounted (with <syntaxhighlight lang="nix" inline>boot.zfs.devNodes = "/dev/disk/by-partuuid";</syntaxhighlight> set), this may manifest as a <syntaxhighlight inline>FAULTED</syntaxhighlight> disk and a <syntaxhighlight inline>DEGRADED</syntaxhighlight> pool reported by <syntaxhighlight inline>zpool status</syntaxhighlight>. The fix is to re-import the pool using disk IDs: | If you used bus-based disk names in the <syntaxhighlight inline>zpool create</syntaxhighlight> command, e.g., <syntaxhighlight inline>/dev/sda</syntaxhighlight>, NixOS may run into issues importing the pool if the names change. Even if the pool is able to be mounted (with <syntaxhighlight lang="nix" inline>boot.zfs.devNodes = "/dev/disk/by-partuuid";</syntaxhighlight> set), this may manifest as a <syntaxhighlight inline>FAULTED</syntaxhighlight> disk and a <syntaxhighlight inline>DEGRADED</syntaxhighlight> pool reported by <syntaxhighlight inline>zpool status</syntaxhighlight>. The fix is to re-import the pool using disk IDs: | ||
Line 218: | Line 211: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The import setting is reflected in <syntaxhighlight inline>/etc/zfs/ | The import setting is reflected in <syntaxhighlight inline="" lang="bash">/etc/zfs/zpool.cache</syntaxhighlight>, so it should persist through subsequent boots. | ||
=== Zpool created with disk IDs === | |||
If you used disk IDs to refer to disks in the <code>zpool create</code> command, e.g., <code>/dev/disk/by-id</code>, then NixOS may consistently fail to import the pool unless <code>boot.zfs.devNodes = "/dev/disk/by-id"</code> is also set. | |||
== Mount datasets at boot == | == Mount datasets at boot == |