From 7aee0dac1f0995e69d8b2c38ce21b3709bf7c929 Mon Sep 17 00:00:00 2001 From: Ihor Antonov Date: Wed, 25 Apr 2018 17:51:53 -0400 Subject: [PATCH] Fix root volume resizing on EC2 KVM instances (M5, C5, etc) (#39488) (cherry picked from commit 3a47c7e8f67c6ece266f570d6db9598856512ede) --- nixos/modules/virtualisation/grow-partition.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nixos/modules/virtualisation/grow-partition.nix b/nixos/modules/virtualisation/grow-partition.nix index 5039118d78eeeb..0255831fcf64b0 100644 --- a/nixos/modules/virtualisation/grow-partition.nix +++ b/nixos/modules/virtualisation/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 '';