diff options
author | Arian van Putten <arian.vanputten@gmail.com> | 2023-10-16 11:57:34 +0000 |
---|---|---|
committer | Arian van Putten <arian.vanputten@gmail.com> | 2023-10-19 12:34:27 +0000 |
commit | 80a578580fae24c59611091e45f4d04e7d626a2d (patch) | |
tree | 23a8303175557a14e2d7e02149424357f24d60e5 /nixos/modules/system | |
parent | ca012a02bf8327be9e488546faecae5e05d7d749 (diff) | |
download | nixlib-80a578580fae24c59611091e45f4d04e7d626a2d.tar nixlib-80a578580fae24c59611091e45f4d04e7d626a2d.tar.gz nixlib-80a578580fae24c59611091e45f4d04e7d626a2d.tar.bz2 nixlib-80a578580fae24c59611091e45f4d04e7d626a2d.tar.lz nixlib-80a578580fae24c59611091e45f4d04e7d626a2d.tar.xz nixlib-80a578580fae24c59611091e45f4d04e7d626a2d.tar.zst nixlib-80a578580fae24c59611091e45f4d04e7d626a2d.zip |
nixos/grow-partition: Resize partition online instead of in initrd
There's no reason to do this in initrd. Partitions can be resized online. We just have to make sure it happens before we resize the file system. This also makes grow-partition work with systemd-initrd
Diffstat (limited to 'nixos/modules/system')
-rw-r--r-- | nixos/modules/system/boot/grow-partition.nix | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/nixos/modules/system/boot/grow-partition.nix b/nixos/modules/system/boot/grow-partition.nix index a2764187a533..1ce4d5e56233 100644 --- a/nixos/modules/system/boot/grow-partition.nix +++ b/nixos/modules/system/boot/grow-partition.nix @@ -16,29 +16,28 @@ with lib; }; config = mkIf config.boot.growPartition { - - assertions = [{ - assertion = !config.boot.initrd.systemd.enable; - message = "systemd stage 1 does not support 'boot.growPartition' yet."; - }]; - - boot.initrd.extraUtilsCommands = '' - copy_bin_and_libs ${pkgs.gawk}/bin/gawk - copy_bin_and_libs ${pkgs.gnused}/bin/sed - copy_bin_and_libs ${pkgs.util-linux}/sbin/sfdisk - copy_bin_and_libs ${pkgs.util-linux}/sbin/lsblk - - substitute "${pkgs.cloud-utils.guest}/bin/.growpart-wrapped" "$out/bin/growpart" \ - --replace "${pkgs.bash}/bin/sh" "/bin/sh" \ - --replace "awk" "gawk" \ - --replace "sed" "gnused" - - ln -s sed $out/bin/gnused - ''; - - boot.initrd.postDeviceCommands = '' - rootDevice="${config.fileSystems."/".device}" - if waitDevice "$rootDevice"; then + assertions = [ + { + assertion = !config.boot.initrd.systemd.repart.enable && !config.systemd.repart.enable; + message = "systemd-repart already grows the root partition and thus you should not use boot.growPartition"; + } + ]; + systemd.services.growpart = { + wantedBy = [ "-.mount" ]; + after = [ "-.mount" ]; + before = [ "systemd-growfs-root.service" ]; + conflicts = [ "shutdown.target" ]; + unitConfig.DefaultDependencies = false; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + TimeoutSec = "infinity"; + # growpart returns 1 if the partition is already grown + SuccessExitStatus = "0 1"; + }; + + script = '' + rootDevice="${config.fileSystems."/".device}" rootDevice="$(readlink -f "$rootDevice")" parentDevice="$rootDevice" while [ "''${parentDevice%[0-9]}" != "''${parentDevice}" ]; do @@ -48,11 +47,8 @@ with lib; if [ "''${parentDevice%[0-9]p}" != "''${parentDevice}" ] && [ -b "''${parentDevice%p}" ]; then parentDevice="''${parentDevice%p}" fi - TMPDIR=/run sh $(type -P growpart) "$parentDevice" "$partNum" - udevadm settle - fi - ''; - + "${pkgs.cloud-utils.guest}/bin/growpart" "$parentDevice" "$partNum" + ''; + }; }; - } |