summary refs log tree commit diff
diff options
context:
space:
mode:
authorIhor Antonov <ngortheone@gmail.com>2018-04-19 08:47:10 -0400
committerIhor Antonov <ngortheone@gmail.com>2018-04-19 13:36:03 -0400
commit3a47c7e8f67c6ece266f570d6db9598856512ede (patch)
treeab6a70094b4d6db732838be3a95e09584dd113d7
parentb5ca7fefc45ecec8695685d573db39612e26ae87 (diff)
downloadnixpkgs-3a47c7e8f67c6ece266f570d6db9598856512ede.tar
nixpkgs-3a47c7e8f67c6ece266f570d6db9598856512ede.tar.gz
nixpkgs-3a47c7e8f67c6ece266f570d6db9598856512ede.tar.bz2
nixpkgs-3a47c7e8f67c6ece266f570d6db9598856512ede.tar.lz
nixpkgs-3a47c7e8f67c6ece266f570d6db9598856512ede.tar.xz
nixpkgs-3a47c7e8f67c6ece266f570d6db9598856512ede.tar.zst
nixpkgs-3a47c7e8f67c6ece266f570d6db9598856512ede.zip
growPartition: fix volume resizing on EC2 NVME instances
The previous code for this accidentally picked up a "p" when computing the partition number.
This logic should be more robust
-rw-r--r--nixos/modules/system/boot/grow-partition.nix11
1 files changed, 9 insertions, 2 deletions
diff --git a/nixos/modules/system/boot/grow-partition.nix b/nixos/modules/system/boot/grow-partition.nix
index c4c6d82dc5c..1e6f9e442b6 100644
--- a/nixos/modules/system/boot/grow-partition.nix
+++ b/nixos/modules/system/boot/grow-partition.nix
@@ -32,8 +32,15 @@ with lib;
       rootDevice="${config.fileSystems."/".device}"
       if [ -e "$rootDevice" ]; then
         rootDevice="$(readlink -f "$rootDevice")"
-        parentDevice="$(lsblk -npo PKNAME "$rootDevice")"
-        TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}"
+        parentDevice="$rootDevice"
+        while [ "''${parentDevice%[0-9]}" != "''${parentDevice}" ]; do
+          parentDevice="''${parentDevice%[0-9]}";
+        done
+        partNum="''${rootDevice#''${parentDevice}}"
+        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
     '';