From 9da2671ef49b9cce197bdd5e6995989faf4b8a3c Mon Sep 17 00:00:00 2001 From: Paul Cioanca Date: Tue, 1 Oct 2024 11:45:27 +0300 Subject: [PATCH] fix: correctly select root disk partition --- ansible/files/admin_api_scripts/grow_fs.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ansible/files/admin_api_scripts/grow_fs.sh b/ansible/files/admin_api_scripts/grow_fs.sh index 1bca017b7..71231e875 100644 --- a/ansible/files/admin_api_scripts/grow_fs.sh +++ b/ansible/files/admin_api_scripts/grow_fs.sh @@ -9,6 +9,18 @@ if pgrep resizefs; then exit 1 fi +# Parses the output of lsblk to get the root partition number +# Example output: +# NAME MOUNTPOINT +# nvme0n1 +# ├─nvme0n1p1 /boot +# └─nvme0n1p3 / +# nvme1n1 /data +# +# Resulting in: +# └─nvme0n1p3 / -> nvme0n1p3 -> 3 +ROOT_PARTITION_NUMBER=$(lsblk -no NAME,MOUNTPOINT | grep ' /$' | awk '{print $1;}' | sed 's/.*nvme[0-9]n[0-9]p//g') + if [ -b /dev/nvme1n1 ] ; then if [[ "${VOLUME_TYPE}" == "data" ]]; then resize2fs /dev/nvme1n1 @@ -16,8 +28,8 @@ if [ -b /dev/nvme1n1 ] ; then elif [[ "${VOLUME_TYPE}" == "root" ]] ; then PLACEHOLDER_FL=/home/ubuntu/50M_PLACEHOLDER rm -f "${PLACEHOLDER_FL}" || true - growpart /dev/nvme0n1 2 - resize2fs /dev/nvme0n1p2 + growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}" + resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}" if [[ ! -f "${PLACEHOLDER_FL}" ]] ; then fallocate -l50M "${PLACEHOLDER_FL}" fi @@ -26,7 +38,7 @@ if [ -b /dev/nvme1n1 ] ; then exit 1 fi else - growpart /dev/nvme0n1 2 - resize2fs /dev/nvme0n1p2 + growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}" + resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}" fi echo "Done resizing disk"