Skip to content

Commit 4433e21

Browse files
authored
fix: Ubuntu 24.04 mounts disks when available, can change mountpoints" (#1747)
* fix: pipefail handling for missing variables * fix: detect disks for ubuntu 24.04 inconsistencies * fix: use findmnt to more robustly discover mount point * custom ami version for testing * fix: bump versions
1 parent a3d559f commit 4433e21

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

ansible/files/admin_api_scripts/grow_fs.sh

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,61 @@ set -euo pipefail
44

55
VOLUME_TYPE=${1:-data}
66

7+
# lsb release
8+
UBUNTU_VERSION=$(lsb_release -rs)
9+
710
if pgrep resizefs; then
811
echo "resize2fs is already running"
912
exit 1
1013
fi
1114

12-
# Parses the output of lsblk to get the root partition number
13-
# Example output:
14-
# NAME MOUNTPOINT
15-
# nvme0n1
16-
# ├─nvme0n1p1 /boot
17-
# └─nvme0n1p3 /
18-
# nvme1n1 /data
19-
#
20-
# Resulting in:
21-
# └─nvme0n1p3 / -> nvme0n1p3 -> 3
22-
ROOT_PARTITION_NUMBER=$(lsblk -no NAME,MOUNTPOINT | grep ' /$' | awk '{print $1;}' | sed 's/.*nvme[0-9]n[0-9]p//g')
15+
# install amazon disk utilities if not present on 24.04
16+
if [ "${UBUNTU_VERSION}" = "24.04" ] && ! dpkg -l | grep -q amazon-ec2-utils; then
17+
apt-get update
18+
apt-get install -y amazon-ec2-utils || true
19+
fi
20+
21+
# We currently mount 3 possible disks
22+
# - /dev/xvda (root disk)
23+
# - /dev/xvdh (data disk)
24+
# - /dev/xvdp (upgrade data disk), not used here
25+
# Initialize variables at 20.04 levels
26+
XVDA_DEVICE="/dev/nvme0n1"
27+
XVDH_DEVICE="/dev/nvme1n1"
28+
# Map AWS devices to NVMe for ubuntu 24.04 and later
29+
if [ "${UBUNTU_VERSION}" = "24.04" ] && dpkg -l | grep -q amazon-ec2-utils; then
30+
for nvme_dev in $(lsblk -dprno name,type | grep disk | awk '{print $1}'); do
31+
if [ -b "$nvme_dev" ]; then
32+
mapping=$(ebsnvme-id -b "$nvme_dev" 2>/dev/null)
33+
case "$mapping" in
34+
"xvda"|"/dev/xvda") XVDA_DEVICE="$nvme_dev" ;;
35+
"xvdh"|"/dev/xvdh") XVDH_DEVICE="$nvme_dev" ;;
36+
esac
37+
fi
38+
done
39+
fi
40+
41+
echo "Using devices - Root: $XVDA_DEVICE, Data: $XVDH_DEVICE"
42+
43+
# Get root partition using findmnt
44+
ROOT_DEVICE_FULL=$(findmnt -no SOURCE /)
45+
ROOT_DEVICE=$(lsblk -no PKNAME "$ROOT_DEVICE_FULL")
46+
ROOT_PARTITION_NUMBER=$(echo "$ROOT_DEVICE_FULL" | sed "s|.*${ROOT_DEVICE}p||")
2347

2448
if ! [[ "$ROOT_PARTITION_NUMBER" =~ ^[0-9]+$ ]]; then
2549
echo "Error: ROOT_PARTITION_NUMBER is not a valid number: $ROOT_PARTITION_NUMBER"
2650
exit 1
2751
fi
2852

29-
if [ -b /dev/nvme1n1 ] ; then
53+
if [ -b "${XVDH_DEVICE}" ] ; then
3054
if [[ "${VOLUME_TYPE}" == "data" ]]; then
31-
resize2fs /dev/nvme1n1
55+
resize2fs "${XVDH_DEVICE}"
3256

3357
elif [[ "${VOLUME_TYPE}" == "root" ]] ; then
3458
PLACEHOLDER_FL=/home/ubuntu/50M_PLACEHOLDER
3559
rm -f "${PLACEHOLDER_FL}" || true
36-
growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}"
37-
resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}"
60+
growpart "${XVDA_DEVICE}" "${ROOT_PARTITION_NUMBER}"
61+
resize2fs "${XVDA_DEVICE}p${ROOT_PARTITION_NUMBER}"
3862
if [[ ! -f "${PLACEHOLDER_FL}" ]] ; then
3963
fallocate -l50M "${PLACEHOLDER_FL}"
4064
fi
@@ -43,7 +67,7 @@ if [ -b /dev/nvme1n1 ] ; then
4367
exit 1
4468
fi
4569
else
46-
growpart /dev/nvme0n1 "${ROOT_PARTITION_NUMBER}"
47-
resize2fs "/dev/nvme0n1p${ROOT_PARTITION_NUMBER}"
70+
growpart "${XVDA_DEVICE}" "${ROOT_PARTITION_NUMBER}"
71+
resize2fs "${XVDA_DEVICE}p${ROOT_PARTITION_NUMBER}"
4872
fi
4973
echo "Done resizing disk"

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ function initiate_upgrade {
363363
fi
364364

365365
# Fallback to lsblk if ebsnvme-id is not available or no mapping found, pre ubuntu 20.04
366-
if [ -z "$BLOCK_DEVICE" ]; then
366+
if [ -z "${BLOCK_DEVICE:-}" ]; then
367367
echo "No block device found using ebsnvme-id, falling back to lsblk"
368368
# awk NF==3 prints lines with exactly 3 fields, which are the block devices currently not mounted anywhere
369369
# excluding nvme0 since it is the root disk

ansible/vars.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ postgres_major:
99

1010
# Full version strings for each major version
1111
postgres_release:
12-
postgresorioledb-17: "17.5.1.015-orioledb"
13-
postgres17: "17.4.1.072"
14-
postgres15: "15.8.1.129"
12+
postgresorioledb-17: "17.5.1.016-orioledb"
13+
postgres17: "17.4.1.073"
14+
postgres15: "15.8.1.130"
1515

1616
# Non Postgres Extensions
1717
pgbouncer_release: "1.19.0"

0 commit comments

Comments
 (0)