Skip to content

Commit

Permalink
growPartition: fix volume resizing on EC2 NVME instances
Browse files Browse the repository at this point in the history
The previous code for this accidentally picked up a "p" when computing the partition number.
This logic should be more robust
  • Loading branch information
Ihor Antonov committed Apr 19, 2018
1 parent b5ca7fe commit 3a47c7e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions nixos/modules/system/boot/grow-partition.nix
Expand Up @@ -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
'';
Expand Down

0 comments on commit 3a47c7e

Please sign in to comment.