Skip to content

fix: Ubuntu 24.04 mounts disks when available, can change mountpoints" #1747

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

Merged
merged 5 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
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
58 changes: 41 additions & 17 deletions ansible/files/admin_api_scripts/grow_fs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,61 @@ set -euo pipefail

VOLUME_TYPE=${1:-data}

# lsb release
UBUNTU_VERSION=$(lsb_release -rs)

if pgrep resizefs; then
echo "resize2fs is already running"
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')
# install amazon disk utilities if not present on 24.04
if [ "${UBUNTU_VERSION}" = "24.04" ] && ! dpkg -l | grep -q amazon-ec2-utils; then
apt-get update
apt-get install -y amazon-ec2-utils || true
fi

# We currently mount 3 possible disks
# - /dev/xvda (root disk)
# - /dev/xvdh (data disk)
# - /dev/xvdp (upgrade data disk), not used here
# Initialize variables at 20.04 levels
XVDA_DEVICE="/dev/nvme0n1"
XVDH_DEVICE="/dev/nvme1n1"
# Map AWS devices to NVMe for ubuntu 24.04 and later
if [ "${UBUNTU_VERSION}" = "24.04" ] && dpkg -l | grep -q amazon-ec2-utils; then
for nvme_dev in $(lsblk -dprno name,type | grep disk | awk '{print $1}'); do
if [ -b "$nvme_dev" ]; then
mapping=$(ebsnvme-id -b "$nvme_dev" 2>/dev/null)
case "$mapping" in
"xvda"|"/dev/xvda") XVDA_DEVICE="$nvme_dev" ;;
"xvdh"|"/dev/xvdh") XVDH_DEVICE="$nvme_dev" ;;
esac
fi
done
fi

echo "Using devices - Root: $XVDA_DEVICE, Data: $XVDH_DEVICE"

# Get root partition using findmnt
ROOT_DEVICE_FULL=$(findmnt -no SOURCE /)
ROOT_DEVICE=$(lsblk -no PKNAME "$ROOT_DEVICE_FULL")
ROOT_PARTITION_NUMBER=$(echo "$ROOT_DEVICE_FULL" | sed "s|.*${ROOT_DEVICE}p||")

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 [ -b "${XVDH_DEVICE}" ] ; then
if [[ "${VOLUME_TYPE}" == "data" ]]; then
resize2fs /dev/nvme1n1
resize2fs "${XVDH_DEVICE}"

elif [[ "${VOLUME_TYPE}" == "root" ]] ; then
PLACEHOLDER_FL=/home/ubuntu/50M_PLACEHOLDER
rm -f "${PLACEHOLDER_FL}" || true
growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}"
resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}"
growpart "${XVDA_DEVICE}" "${ROOT_PARTITION_NUMBER}"
resize2fs "${XVDA_DEVICE}p${ROOT_PARTITION_NUMBER}"
if [[ ! -f "${PLACEHOLDER_FL}" ]] ; then
fallocate -l50M "${PLACEHOLDER_FL}"
fi
Expand All @@ -43,7 +67,7 @@ if [ -b /dev/nvme1n1 ] ; then
exit 1
fi
else
growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}"
resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}"
growpart "${XVDA_DEVICE}" "${ROOT_PARTITION_NUMBER}"
resize2fs "${XVDA_DEVICE}p${ROOT_PARTITION_NUMBER}"
fi
echo "Done resizing disk"
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function initiate_upgrade {
fi

# Fallback to lsblk if ebsnvme-id is not available or no mapping found, pre ubuntu 20.04
if [ -z "$BLOCK_DEVICE" ]; then
if [ -z "${BLOCK_DEVICE:-}" ]; then
echo "No block device found using ebsnvme-id, falling back to lsblk"
# awk NF==3 prints lines with exactly 3 fields, which are the block devices currently not mounted anywhere
# excluding nvme0 since it is the root disk
Expand Down
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ postgres_major:

# Full version strings for each major version
postgres_release:
postgresorioledb-17: "17.5.1.015-orioledb"
postgres17: "17.4.1.072"
postgres15: "15.8.1.129"
postgresorioledb-17: "17.5.1.016-orioledb"
postgres17: "17.4.1.073"
postgres15: "15.8.1.130"

# Non Postgres Extensions
pgbouncer_release: "1.19.0"
Expand Down