From a832ce7be1ef16e0847bc2b4689c21101482713a Mon Sep 17 00:00:00 2001 From: Jack Cummings Date: Tue, 4 Dec 2012 10:17:54 -0800 Subject: [PATCH 1/4] Add zfs module. --- modules/module-list.nix | 1 + modules/tasks/filesystems/zfs.nix | 40 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 modules/tasks/filesystems/zfs.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index f2811fd2f5f6..929941fd8edb 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -220,6 +220,7 @@ ./tasks/filesystems/reiserfs.nix ./tasks/filesystems/vfat.nix ./tasks/filesystems/xfs.nix + ./tasks/filesystems/zfs.nix ./tasks/kbd.nix ./tasks/lvm.nix ./tasks/network-interfaces.nix diff --git a/modules/tasks/filesystems/zfs.nix b/modules/tasks/filesystems/zfs.nix new file mode 100644 index 000000000000..b5742d922489 --- /dev/null +++ b/modules/tasks/filesystems/zfs.nix @@ -0,0 +1,40 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems; + kernel = config.boot.kernelPackages; + +in + +{ + ###### implementation + + config = mkIf (any (fs: fs == "zfs") config.boot.supportedFilesystems) { + + boot.kernelModules = [ "spl" "zavl" "zcommon" "zfs" "zlib_deflate" "znvpair" "zunicode" ] ; + + boot.initrd.kernelModules = mkIf inInitrd [ "spl" "zavl" "zcommon" "zfs" "zlib_deflate" "znvpair" "zunicode" ] ; + + boot.initrd.extraUtilsCommands = mkIf inInitrd + '' + cp -v ${kernel.zfs}/sbin/zfs $out/sbin + cp -v ${kernel.zfs}/sbin/zdb $out/sbin + cp -v ${kernel.zfs}/sbin/zpool $out/sbin + ''; + + boot.initrd.postDeviceCommands = mkIf inInitrd + '' + zpool import -f -a -d /dev + zfs mount -a + ''; + + system.fsPackages = [ kernel.zfs ]; + + environment.systemPackages = [ kernel.zfs ]; + + services.udev.packages = [ kernel.zfs ]; + }; +} From d2789791eeb8923440ba30afd7d9d64d8425b923 Mon Sep 17 00:00:00 2001 From: Jack Cummings Date: Tue, 4 Dec 2012 11:28:05 -0800 Subject: [PATCH 2/4] Need extraModulePackages for spl and zfs modules. --- modules/tasks/filesystems/zfs.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/tasks/filesystems/zfs.nix b/modules/tasks/filesystems/zfs.nix index b5742d922489..b0e30d494ecd 100644 --- a/modules/tasks/filesystems/zfs.nix +++ b/modules/tasks/filesystems/zfs.nix @@ -14,9 +14,10 @@ in config = mkIf (any (fs: fs == "zfs") config.boot.supportedFilesystems) { - boot.kernelModules = [ "spl" "zavl" "zcommon" "zfs" "zlib_deflate" "znvpair" "zunicode" ] ; + boot.kernelModules = [ "spl" "zfs" ] ; + boot.extraModulePackages = [ kernel.zfs kernel.spl ]; - boot.initrd.kernelModules = mkIf inInitrd [ "spl" "zavl" "zcommon" "zfs" "zlib_deflate" "znvpair" "zunicode" ] ; + boot.initrd.kernelModules = mkIf inInitrd [ "spl" "zfs" ] ; boot.initrd.extraUtilsCommands = mkIf inInitrd '' From b42d52eeb0159e716190ea1c96b1fae9c9b619c5 Mon Sep 17 00:00:00 2001 From: Jack Cummings Date: Tue, 4 Dec 2012 11:57:59 -0800 Subject: [PATCH 3/4] Add the hostid option. Refactor code a bit better for initrd(untested) and system operation. --- modules/tasks/filesystems/zfs.nix | 69 +++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/modules/tasks/filesystems/zfs.nix b/modules/tasks/filesystems/zfs.nix index b0e30d494ecd..d8ea66f2cd47 100644 --- a/modules/tasks/filesystems/zfs.nix +++ b/modules/tasks/filesystems/zfs.nix @@ -1,41 +1,68 @@ { config, pkgs, ... }: +# +# todo: +# - crontab for scrubs, etc +# - zfs tunables +# - /etc/zfs/zpool.cache handling + with pkgs.lib; let + cfgSpl = config.environment.spl; inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems; + inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems; kernel = config.boot.kernelPackages; in { + + ###### interface + + options = { + environment.spl.hostid = mkOption { + default = ""; + example = "0xdeadbeef"; + description = '' + ZFS uses a system's hostid to determine if a storage pool (zpool) is + native to this system, and should thus be imported automatically. + Unfortunately, this hostid can change under linux from boot to boot (by + changing network adapaters, for instance). Specify a unique 32 bit hostid in + hex here for zfs to prevent getting a random hostid between boots and having to + manually import pools. + ''; + }; + }; + ###### implementation - config = mkIf (any (fs: fs == "zfs") config.boot.supportedFilesystems) { + config = mkIf ( inInitrd || inSystem ) { - boot.kernelModules = [ "spl" "zfs" ] ; - boot.extraModulePackages = [ kernel.zfs kernel.spl ]; + boot = { + kernelModules = [ "spl" "zfs" ] ; + extraModulePackages = [ kernel.zfs kernel.spl ]; + extraModprobeConfig = mkIf (cfgSpl.hostid != "") "options spl spl_hostid=${cfgSpl.hostid}"; + }; - boot.initrd.kernelModules = mkIf inInitrd [ "spl" "zfs" ] ; - - boot.initrd.extraUtilsCommands = mkIf inInitrd - '' - cp -v ${kernel.zfs}/sbin/zfs $out/sbin - cp -v ${kernel.zfs}/sbin/zdb $out/sbin - cp -v ${kernel.zfs}/sbin/zpool $out/sbin - ''; - - boot.initrd.postDeviceCommands = mkIf inInitrd - '' - zpool import -f -a -d /dev - zfs mount -a - ''; - - system.fsPackages = [ kernel.zfs ]; + boot.initrd = mkIf inInitrd { + kernelModules = [ "spl" "zfs" ] ; + extraUtilsCommands = + '' + cp -v ${kernel.zfs}/sbin/zfs $out/sbin + cp -v ${kernel.zfs}/sbin/zdb $out/sbin + cp -v ${kernel.zfs}/sbin/zpool $out/sbin + ''; + postDeviceCommands = + '' + zpool import -f -a -d /dev + zfs mount -a + ''; + }; + system.fsPackages = [ kernel.zfs ]; # XXX: needed? zfs doesn't have a fsck environment.systemPackages = [ kernel.zfs ]; - - services.udev.packages = [ kernel.zfs ]; + services.udev.packages = [ kernel.zfs ]; # to hook zvol naming, etc. }; } From bdee7f502c737a8fd99e51d170bf9ee77475cd1f Mon Sep 17 00:00:00 2001 From: Jack Cummings Date: Thu, 6 Dec 2012 15:12:10 -0800 Subject: [PATCH 4/4] spl module params in boot.spl.* --- modules/tasks/filesystems/zfs.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/tasks/filesystems/zfs.nix b/modules/tasks/filesystems/zfs.nix index d8ea66f2cd47..8c643511724e 100644 --- a/modules/tasks/filesystems/zfs.nix +++ b/modules/tasks/filesystems/zfs.nix @@ -10,7 +10,7 @@ with pkgs.lib; let - cfgSpl = config.environment.spl; + cfgSpl = config.boot.spl; inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems; inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems; kernel = config.boot.kernelPackages; @@ -22,7 +22,7 @@ in ###### interface options = { - environment.spl.hostid = mkOption { + boot.spl.hostid = mkOption { default = ""; example = "0xdeadbeef"; description = ''