ZFS: Difference between revisions
imported>2r zfs root |
imported>2r update auto-snapshot |
||
Line 65: | Line 65: | ||
fileSystems."/etc/nixos" = { | fileSystems."/etc/nixos" = { | ||
device = "/altroot/etc/nixos"; | device = "/altroot/etc/nixos"; | ||
fsType = "none"; | fsType = "none"; | ||
options = [ "bind" "X-mount.mkdir" ]; | options = [ "bind" "X-mount.mkdir" ]; | ||
Line 155: | Line 93: | ||
== Reservations == | == Reservations == | ||
On ZFS, the performance will deteriorate significantly when more than 80% of the available space is used. To avoid this, reserve disk space beforehand. | |||
To reserve | |||
To reserve space create a new unused dataset that gets a guaranteed disk space of 10GB. | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# zfs | # zfs create -o refreservation=10G -o mountpoint=none zroot/reserved | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 178: | Line 109: | ||
== Take snapshots automatically == | == Take snapshots automatically == | ||
See <code>services.sanoid</code> section in <code>man configuration.nix</code>. | |||
== Remote unlock == | |||
=== Unlock encrypted zfs via ssh on boot === | |||
== Unlock encrypted zfs via ssh on boot == | |||
{{note|As of 22.05, rebuilding your config with the below directions may result in a situation where, if you want to revert the changes, you may need to do some pretty hairy nix-store manipulation to be able to successfully rebuild, see https://github.com/NixOS/nixpkgs/issues/101462#issuecomment-1172926129}} | {{note|As of 22.05, rebuilding your config with the below directions may result in a situation where, if you want to revert the changes, you may need to do some pretty hairy nix-store manipulation to be able to successfully rebuild, see https://github.com/NixOS/nixpkgs/issues/101462#issuecomment-1172926129}} | ||
Line 259: | Line 159: | ||
* If your network card isn't started, you'll need to add the according kernel module to the initrd as well, e.g. <syntaxhighlight lang="nix" inline>boot.initrd.kernelModules = [ "r8169" ];</syntaxhighlight> | * If your network card isn't started, you'll need to add the according kernel module to the initrd as well, e.g. <syntaxhighlight lang="nix" inline>boot.initrd.kernelModules = [ "r8169" ];</syntaxhighlight> | ||
== Import and unlock multiple encrypted pools/dataset at boot == | === Import and unlock multiple encrypted pools/dataset at boot === | ||
If you have not only one encrypted pool/dataset but multiple ones and you want to import and unlock them at boot, so that they can be automounted using the hardware-configuration.nix, you could just amend the <code>boot.initrd.network.postCommands</code> option. | If you have not only one encrypted pool/dataset but multiple ones and you want to import and unlock them at boot, so that they can be automounted using the hardware-configuration.nix, you could just amend the <code>boot.initrd.network.postCommands</code> option. | ||
Line 311: | Line 211: | ||
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] | ||
=== Alternative 1 | === Alternative 1: Enable Mail Notification without Re-compliation === | ||
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: | ||
Line 402: | Line 271: | ||
# zpool scrub $pool | # zpool scrub $pool | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Alternative 2: Rebuild ZFS with Mail Support === | |||
The <code>zfs</code> package can be rebuilt with mail features. However, please note that this will cause Nix to recompile the entire ZFS package on the computer, and on every kernel update, which could be very time-consuming on lower-end NAS systems. | |||
An alternative solution that does not involve recompliation can be found above. | |||
The following override is needed as <code>zfs</code> is implicitly used in partition mounting: | |||
<syntaxhighlight lang="nix"> | |||
nixpkgs.config.packageOverrides = pkgs: { | |||
zfsStable = pkgs.zfsStable.override { enableMail = true; }; | |||
}; | |||
</syntaxhighlight> | |||
A mail sender like [[msmtp]] or [[postfix]] is required. | |||
A minimal, testable ZED configuration example: | |||
<syntaxhighlight lang="nix"> | |||
services.zfs.zed.enableMail = true; | |||
services.zfs.zed.settings = { | |||
ZED_EMAIL_ADDR = [ "root" ]; | |||
ZED_NOTIFY_VERBOSE = true; | |||
}; | |||
</syntaxhighlight> | |||
Above, <code>ZED_EMAIL_ADDR</code> is set to <code>root</code>, which most people will have an alias for in their mailer. You can change it to directly mail you: <code>ZED_EMAIL_ADDR = [ "you@example.com" ];</code> | |||
ZED pulls in <code>mailutils</code> and runs <code>mail</code> by default, but you can override it with <code>ZED_EMAIL_PROG</code>. If using msmtp, you may need <code>ZED_EMAIL_PROG = "${pkgs.msmtp}/bin/msmtp";</code>. | |||
You can customize the mail command with <code>ZED_EMAIL_OPTS</code>. For example, if your upstream mail server requires a certain FROM address: <code>ZED_EMAIL_OPTS = "-r 'noreply@example.com' -s '@SUBJECT@' @ADDRESS@";</code> | |||
[[Category:Guide]] | [[Category:Guide]] |