Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly select root disk partition #1244

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions ansible/files/admin_api_scripts/grow_fs.sh
Original file line number Diff line number Diff line change
@@ -9,15 +9,32 @@ 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 ! [[ "$ROOT_PARTITION_NUMBER" =~ ^[0-9]+$ ]]; then
echo "Error: ROOT_PARTITION_NUMBER is not a valid number: $ROOT_PARTITION_NUMBER"
exit 1
fi

if [ -b /dev/nvme1n1 ] ; then
if [[ "${VOLUME_TYPE}" == "data" ]]; then
resize2fs /dev/nvme1n1

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 +43,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"