ZFS: Difference between revisions
→Limitations: update |
→Remote unlock: Remove a note to a closed issue, assuming this has been resolved already. |
||
| (6 intermediate revisions by 5 users not shown) | |||
| Line 5: | Line 5: | ||
ZFS integrates into NixOS via the {{nixos:option|boot.zfs}} and {{nixos:option|services.zfs}} options. | ZFS integrates into NixOS via the {{nixos:option|boot.zfs}} and {{nixos:option|services.zfs}} options. | ||
== Limitations == | |||
==== Latest Kernel compatible with ZFS ==== | |||
ZFS often does not support the latest Kernel versions. It is recommended to use an LTS Kernel version whenever possible; the NixOS default Kernel is generally suitable. See [[Linux kernel|Linux Kernel]] for more information about configuring a specific Kernel version. | |||
If your config specifies a Kernel version that is not officially supported by upstream ZFS, the ZFS module will fail to evaluate with an error that the ZFS package is "broken". Upstream ZFS changed in 2.3 to refuse to build by default, regardless of Nixpkgs’ broken marking (or ignoring). | |||
= | ===== Selecting the latest ZFS-compatible Kernel ===== | ||
{{Warning|This will often result in the Kernel version going backwards as Kernel versions become end-of-life and are removed from Nixpkgs. If you need more control over the Kernel version due to hardware requirements, consider simply pinning a specific version rather than calculating it as below.}} | |||
To use the latest ZFS-compatible Kernel currently available, the following configuration may be used. | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | |||
config, | |||
lib, | |||
pkgs, | |||
... | |||
}: | |||
let | |||
zfsCompatibleKernelPackages = lib.filterAttrs ( | |||
name: kernelPackages: | |||
(builtins.match "linux_[0-9]+_[0-9]+" name) != null | |||
&& (builtins.tryEval kernelPackages).success | |||
&& (!kernelPackages.${config.boot.zfs.package.kernelModuleAttribute}.meta.broken) | |||
) pkgs.linuxKernel.packages; | |||
latestKernelPackage = lib.last ( | |||
lib.sort (a: b: (lib.versionOlder a.kernel.version b.kernel.version)) ( | |||
builtins.attrValues zfsCompatibleKernelPackages | |||
) | |||
); | |||
in | |||
{ | |||
# Note this might jump back and forth as kernels are added or removed. | |||
boot.kernelPackages = latestKernelPackage; | |||
} | |||
</syntaxhighlight> | |||
===== Using unstable, pre-release ZFS ===== | |||
{{Warning|Pre-release ZFS versions may be less well-tested, and may have critical bugs that may cause data loss.}}{{Warning|Running ZFS with a Kernel unsupported by upstream “is considered EXPERIMENTAL by the OpenZFS project. Even if it appears to build and run correctly, there may be bugs that can cause SERIOUS DATA LOSS.”}} | |||
In some cases, a pre-release version of ZFS may be available that supports a newer Kernel. Use it with <code>boot.zfs.package = pkgs.zfs_unstable;</code>. Using zfs_unstable may allow the use of an unsupported Kernel; as warned above, [https://github.com/openzfs/zfs/blob/6a2f7b38442b42f4bc9a848f8de10fc792ce8d76/config/kernel.m4#L473-L487 upstream considers this experimental]. | |||
</ | |||
= | ==== Partial support for swap on ZFS ==== | ||
ZFS does not support swapfiles. swap devices can be used instead. Additionally, hibernation is disabled by default due to a [https://github.com/NixOS/nixpkgs/pull/208037 high risk] of data corruption. Note that even if that pull request is merged, it does not fully mitigate the risk. If you wish to enable hibernation regardless and made sure that swapfiles on ZFS are not used, set <code>boot.zfs.allowHibernation = true</code>. | |||
</ | |||
= | ==== Zpool not found ==== | ||
<syntaxhighlight lang="nix"> | 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. | ||
</syntaxhighlight> | |||
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. | |||
< | |||
</ | |||
= | ==== ZFS conflicting with systemd ==== | ||
ZFS will manage mounting non-legacy ZFS filesystems, but NixOS tries to manage mounting with systemd. ZFS native mountpoints are not managed as part of the system configuration (but better support hibernation with a separate swap partition). This can lead to conflicts if the ZFS mount service is also enabled for the same datasets. | |||
Disable the mount service with <code>systemd.services.zfs-mount.enable = false;</code> or remove the <code>fileSystems</code> entries in hardware-configuration.nix. Otherwise, use legacy mountpoints (created with e.g. <code>zfs create -o mountpoint=legacy</code>). Mountpoints must be specified with <code>fileSystems."/mount/point" = {};</code> or with <code>nixos-generate-config</code>. | |||
==== Nix builds and ZFS properties like normalization or utf8only ==== | |||
These options are often suggested in guides to setting up ZFS. <code>normalization</code> makes filenames compare the same in cases where there exists more than one UTF8 bytestring that represents the same characters. <code>utf8only</code> prevents the creation of files with non-UTF8 filenames, e.g. filenames using a Latin1 character set. These are non-POSIX and will make the tests for certain packages fail, which may interfere with builds. After nix 2.30, builds no longer happen in /tmp by default, instead they happen in <code>/nix/var/nix/builds</code>. On any system where you plan to run nix builds, you should ensure that this filesystem is POSIX-compliant. Either mounting a tmpfs in that directory (if you have lots of RAM + swap) or creating a zfs dataset there which does not have these or other non-POSIX settings like <code>noatime</code>, <code>snapdir=visible</code>, <code>acltype=nfsv4</code>, or <code>caseinsensitivity=insensitive</code>. Many of these cannot be changed after dataset creation so if this is your root filesystem, you will need to restore from a backup in order to recreate them. | |||
== Guides == | == Guides == | ||
| Line 461: | Line 326: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
You can confirm whether any specified configuration/tuning got applied via commands like <code> | You can confirm whether any specified configuration/tuning got applied via commands like <code>zarcsummary</code> and <code>zarcstat -a -s " "</code>. | ||
== Automatic scrubbing == | == Automatic scrubbing == | ||
| Line 474: | Line 339: | ||
=== Unlock encrypted ZFS via SSH on boot === | === Unlock encrypted ZFS via SSH on boot === | ||
{{ | {{merge|Remote_disk_unlocking}}In case you want unlock a machine remotely (after an update), having an ssh service in initrd for the password prompt is handy: | ||
In case you want unlock a machine remotely (after an update), having an ssh service in initrd for the password prompt is handy: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 557: | Line 420: | ||
== Take snapshots automatically == | == Take snapshots automatically == | ||
See {{nixos:option|services.sanoid}} section in <code>man configuration.nix</code>. | See {{nixos:option|services.zfs.autoSnapshot}} or {{nixos:option|services.sanoid}} section in <code>man configuration.nix</code>. | ||
== NFS share == | == NFS share == | ||
| Line 634: | Line 497: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
services.zfs.zed | services.zfs.zed = { | ||
enableMail = true; | enableMail = true; | ||
settings = { | settings = { | ||