From 42a353283d7f3b5cdaf1bc0b25260ddd2e00bb35 Mon Sep 17 00:00:00 2001 From: Vikas Date: Tue, 21 Apr 2026 13:58:23 +0530 Subject: [PATCH] Fix disk resize issue for Centos VMs Signed-off-by: Vikas --- hack/scripts/expand-root-volume.sh | 27 +++++++++++++++++++++++++ hack/scripts/image-prep.template.static | 25 +++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 hack/scripts/expand-root-volume.sh diff --git a/hack/scripts/expand-root-volume.sh b/hack/scripts/expand-root-volume.sh new file mode 100644 index 00000000..d0559c47 --- /dev/null +++ b/hack/scripts/expand-root-volume.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -x + +# 1. Rescan physical paths +for dev in /sys/block/sd*/device/rescan; do echo 1 > "$dev"; done +sleep 2 + +# 2. Resize Multipath Map +multipathd -k"resize map mpatha" +sleep 2 + +# 3. Handle GPT 'Fix' separately and silently +# We pipe 'Fix' to a print command. If there's no error, Fix is ignored. +printf "Fix\n" | parted /dev/mapper/mpatha ---pretend-input-tty print > /dev/null 2>&1 + +# 4. Resize the partition +printf "Yes\n" | parted /dev/mapper/mpatha ---pretend-input-tty resizepart 2 100% + +# 5. Refresh mappings +kpartx -u /dev/mapper/mpatha +udevadm settle + +# 6. Grow Filesystem +xfs_growfs / + +# 7. Flag completion +touch /var/lib/pac-root-expanded diff --git a/hack/scripts/image-prep.template.static b/hack/scripts/image-prep.template.static index f922f483..d7e4627d 100644 --- a/hack/scripts/image-prep.template.static +++ b/hack/scripts/image-prep.template.static @@ -12,6 +12,7 @@ subscription-manager register --force --auto-attach --username={{ .RHNUser }} -- yum update -y && yum install -y yum-utils yum install -y cloud-init firewalld +yum install -y device-mapper-multipath parted kpartx rm -rf /etc/systemd/system/multi-user.target.wants/firewalld.service rpm -vih --nodeps https://public.dhe.ibm.com/software/server/POWER/Linux/yum/download/ibm-power-repo-latest.noarch.rpm sed -i 's/^more \/opt\/ibm\/lop\/notice/#more \/opt\/ibm\/lop\/notice/g' /opt/ibm/lop/configure @@ -56,13 +57,32 @@ done grub2-mkconfig -o /boot/grub2/grub.cfg curl https://raw.githubusercontent.com/IBM/power-access-cloud/refs/heads/main/hack/scripts/prep-pac.sh -o /usr/local/bin/prep-pac.sh +curl https://raw.githubusercontent.com/IBM/power-access-cloud/refs/heads/main/hack/scripts/expand-root-volume.sh -o /usr/local/bin/expand-root-volume.sh chmod +x /usr/local/bin/prep-pac.sh +chmod +x /usr/local/bin/expand-root-volume.sh + +cat <> /usr/lib/systemd/system/expand-root-volume.service +[Unit] +Description=Expand multipath root volume on first boot +DefaultDependencies=no +After=local-fs.target systemd-udev-settle.service multipathd.service +Before=prep-pac.service cloud-final.service +ConditionPathExists=!/var/lib/pac-root-expanded + +[Service] +ExecStart=/usr/local/bin/expand-root-volume.sh +Type=oneshot +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target +EOT cat <> /usr/lib/systemd/system/prep-pac.service [Unit] Description=Prepare the machine for the Power Access Cloud -Requires=cloud-final.service -After=cloud-final.service +Requires=cloud-final.service expand-root-volume.service +After=cloud-final.service expand-root-volume.service [Service] ExecStart=/usr/local/bin/prep-pac.sh @@ -75,6 +95,7 @@ RemainAfterExit=yes WantedBy=cloud-init.target EOT +systemctl enable expand-root-volume.service systemctl enable prep-pac.service #mkdir -p /etc/cloud/cloud.cfg.d #cat <> /etc/cloud/cloud.cfg.d/99-custom-networking.cfg