diff options
| author | Kleidi Bujari <mail@4kb.net> | 2026-08-30 13:57:27 -0700 |
|---|---|---|
| committer | Kleidi Bujari <mail@4kb.net> | 2026-08-30 13:58:00 -0700 |
| commit | 55dd84d67da8fb6e70aed7b921d05b66748546e1 (patch) | |
| tree | 4a5181fd8e7f4c05f7a3238b84c5ac458c37c8a4 | |
| parent | 2f064549f1be01b956c9193b5b55ff1c2973b9be (diff) | |
| download | depot-55dd84d67da8fb6e70aed7b921d05b66748546e1.tar.gz depot-55dd84d67da8fb6e70aed7b921d05b66748546e1.tar.bz2 depot-55dd84d67da8fb6e70aed7b921d05b66748546e1.zip | |
[nixos/disk] experiment with autosizing zfs partitions in initrd
| -rw-r--r-- | machines/feneri.nix | 19 | ||||
| -rw-r--r-- | modules/disk.nix | 39 |
2 files changed, 58 insertions, 0 deletions
diff --git a/machines/feneri.nix b/machines/feneri.nix new file mode 100644 index 0000000..d731a36 --- /dev/null +++ b/machines/feneri.nix @@ -0,0 +1,19 @@ +{ flake, modulesPath, ... }: + +{ + imports = [ + flake.outputs.nixosModules.disk + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + nixpkgs.hostPlatform.system = "x86_64-linux"; + + depot.disk = { + enable = true; + # device = "/dev/vda"; + }; + + services.getty.autologinUser = "root"; + + networking.hostName = "feneri"; +} 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, ... }: { |
