From e1daeae1909a22431467a61454252baef37eb0e2 Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 19 Nov 2025 17:40:34 +0100 Subject: [PATCH] Add script.sh --- script.sh | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 script.sh diff --git a/script.sh b/script.sh new file mode 100644 index 0000000..2c2e2e9 --- /dev/null +++ b/script.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +set -e + +echo "=== Checking Prerequisites ===" + +# Check if running as root +if [ "$(id -u)" -ne 0 ]; then + echo "Error: This script must be run as root." + exit 1 +fi +echo "✔ Running as root." + +# Check if disk /dev/vda exists +if [ ! -b /dev/vda ]; then + echo "Error: /dev/vda not found. Ensure this is a Proxmox host using the default LVM layout." + exit 1 +fi +echo "✔ /dev/vda detected." + +# Check if LVM is installed +if ! command -v pvdisplay >/dev/null 2>&1; then + echo "Error: LVM tools not found. Please install lvm2." + exit 1 +fi +echo "✔ LVM tools detected." + +# Check if /dev/vda3 exists +if [ ! -b /dev/vda3 ]; then + echo "Error: Partition /dev/vda3 not found. Ensure the system uses the default Proxmox LVM layout." + exit 1 +fi +echo "✔ /dev/vda3 detected." + +echo "=== All prerequisites met ===" + +echo "=== Checking for 'growpart' Utility ===" +if ! command -v growpart >/dev/null 2>&1; then + echo "'growpart' is not installed. Installing required package..." + apt update && apt install -y cloud-guest-utils +else + echo "'growpart' is already installed." +fi + + +echo "=== Expanding Partition /dev/vda3 ===" +GROW_OUTPUT=$(growpart /dev/vda 3 2>&1) || true +if echo "$GROW_OUTPUT" | grep -q "NOCHANGE"; then + echo "✔ /dev/vda3 is already at maximum size. No expansion needed." +else + echo "$GROW_OUTPUT" + echo "✔ Partition /dev/vda3 expanded successfully." +fi + +echo "=== Resizing the Physical Volume ===" +pvresize /dev/vda3 + + +echo "=== Extending the Logical Volume to Use All Available Free Space ===" +LV_OUTPUT=$(lvextend -l +100%FREE /dev/pve/root 2>&1) || true +if echo "$LV_OUTPUT" | grep -q "No size change"; then + echo "✔ Logical volume /dev/pve/root is already using all available free space. No extension needed." +else + echo "$LV_OUTPUT" + echo "✔ Logical volume /dev/pve/root extended successfully." +fi + +echo "=== Resizing the Filesystem ===" +resize2fs /dev/pve/root + +echo "=== Disk Expansion Completed Successfully ==="