From 55dd84d67da8fb6e70aed7b921d05b66748546e1 Mon Sep 17 00:00:00 2001 From: Kleidi Bujari Date: Sun, 30 Aug 2026 13:57:27 -0700 Subject: [nixos/disk] experiment with autosizing zfs partitions in initrd --- modules/disk.nix | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'modules') diff --git a/modules/disk.nix b/modules/disk.nix index 071c9ea..757d436 100644 --- a/modules/disk.nix +++ b/modules/disk.nix @@ -61,6 +61,7 @@ in kernelParams = [ "nohibernate" "elevator=none" + "rd.systemd.unit=rescue.target" ]; supportedFilesystems = [ "vfat" @@ -115,6 +116,44 @@ in }; }; + boot.initrd.systemd.services."growroot" = { + description = "Grow main partition into any unused disk space."; + serviceConfig.Type = "oneshot"; + + # If dry-run fails, there is nothing to grow + serviceConfig.ExecCondition = "${pkgs.cloud-utils}/bin/growpart /dev/vda 2 --dry-run"; + + wantedBy = [ "zfs.target" ]; + before = [ "zfs-import-zroot.service" ]; + + script = "growpart /dev/vda 2 --verbose"; + }; + + boot.initrd.systemd.services."expand-zroot" = { + description = "Expand zroot to take up entire partition."; + serviceConfig.Type = "oneshot"; + + wantedBy = ["zfs.target"]; + after = ["zfs-import-zroot.service"]; + + script = '' + # pull partuuid from zpool + GUID=$(zpool list -v --json | jq --raw-output '.pools.zroot.vdevs.[].name') + + # re-mark pool as online with '-e' to expand + zpool online -e zroot $GUID + ''; + }; + + boot.initrd.systemd.emergencyAccess = true; + boot.initrd.systemd.initrdBin = [ + pkgs.cloud-utils + pkgs.util-linux + pkgs.busybox + pkgs.jq + pkgs.zfs + ]; + image.modules.depot = { config, modulesPath, ... }: { -- cgit v1.3.1