ZFS: Difference between revisions
Musicmatze (talk | contribs) Typo |
→Remote unlock: Remove a note to a closed issue, assuming this has been resolved already. |
||
| (16 intermediate revisions by 7 users not shown) | |||
| Line 49: | Line 49: | ||
==== Partial support for swap on ZFS ==== | ==== 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 | 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 ==== | ==== Zpool not found ==== | ||
| Line 62: | Line 62: | ||
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>. | 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 == | ||
=== | === Root on ZFS with disko === | ||
disko[https://github.com/nix-community/disko/blob/master/example/zfs.nix] can partition disks declaratively and handle mount points at install time. | |||
It | Don't follow the Root on ZFS guide found in OpenZFS documentation. It was abandoned and has not been updated in years. See commit log for the openzfs-docs repo for details. | ||
=== Simple NixOS ZFS on root installation === | === Simple NixOS ZFS on root installation === | ||
| Line 330: | 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 343: | 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 426: | 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 441: | Line 435: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Only this line is needed. Configure firewall if necessary, as described in [[NFS]] article. | Only this line is needed. Configure firewall if necessary, as described in [[NFS]] article. | ||
{{warning|<code>zfs share</code> or <code>sharenfs</code> does not work if the <code>mountpoint</code> is set to <code>legacy</code> (or <code>none</code>, of course). I was unable to find a source for this behaviour, but I was stuck on the problem for days, until I realized the problem. ::Reply: sharenfs controlls what | |||
is written into <code>/etc/exports</code>. If ZFS does not know the mountpoint, as is the case in | |||
mountpoint legacy or none, the contents of <code>/etc/exports</code> would be wrong}} | |||
Then, set <code>sharenfs</code> property: | Then, set <code>sharenfs</code> property: | ||
| Line 453: | Line 451: | ||
ZFS Event Daemon (zed) monitors events generated by the ZFS Kernel module and runs configured tasks. It can be configured to send an email when a pool scrub is finished or a disk has failed. [https://search.nixos.org/options?query=services.zfs.zed zed options] | ZFS Event Daemon (zed) monitors events generated by the ZFS Kernel module and runs configured tasks. It can be configured to send an email when a pool scrub is finished or a disk has failed. [https://search.nixos.org/options?query=services.zfs.zed zed options] | ||
First, we need to configure a mail transfer agent, the program that sends email: | First, we need to configure a mail transfer agent, the program that sends email: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
age.secrets.msmtp = { | |||
file = "${inputs.self.outPath}/secrets/msmtp.age"; | |||
}; | |||
# for zed enableMail, enable sendmailSetuidWrapper | |||
services.mail.sendmailSetuidWrapper.enable = true; | |||
programs.msmtp = { | programs.msmtp = { | ||
enable = true; | enable = true; | ||
| Line 464: | Line 467: | ||
defaults = { | defaults = { | ||
aliases = "/etc/aliases"; | aliases = "/etc/aliases"; | ||
port = | port = 587; | ||
auth = "plain"; | |||
tls = "on"; | tls = "on"; | ||
tls_starttls = "on"; | |||
tls_starttls = " | |||
}; | }; | ||
accounts = { | accounts = { | ||
default = { | default = { | ||
host = "mail.example.com"; | host = "smtp.mail.example.com"; | ||
passwordeval = "cat | passwordeval = "cat ${config.age.secrets.msmtp.path}"; | ||
user = " | user = "myname@example.com"; | ||
from = " | from = "myname@example.com"; | ||
}; | }; | ||
}; | }; | ||
| Line 487: | Line 489: | ||
{ | { | ||
environment.etc.aliases.text = '' | environment.etc.aliases.text = '' | ||
root: | root: admin@example.com | ||
''; | ''; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Finally, | Finally, enable zed mail notification: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
services.zfs.zed | services.zfs.zed = { | ||
enableMail = true; | |||
ZED_EMAIL_ADDR = [ "root" ]; | settings = { | ||
ZED_EMAIL_ADDR = [ "root" ]; | |||
# send notification if scrub succeeds | |||
ZED_NOTIFY_VERBOSE = true; | |||
}; | |||
}; | }; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 517: | Line 513: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Guide]] | [[Category:Guide]] | ||