Add script.sh

This commit is contained in:
2025-11-19 17:40:34 +01:00
commit e1daeae190

71
script.sh Normal file
View File

@@ -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 ==="