#!/bin/bash
ROOT_PART=$(realpath "$(findmnt --nofsroot --noheadings --output SOURCE /)")
DISK_DEV=$(lsblk -no pkname "$ROOT_PART")
PART_NUM=$(echo "$ROOT_PART" | grep -o '[0-9]*$')

# 1. Resize partition to 100% of available space
parted -s "/dev/$DISK_DEV" resizepart "$PART_NUM" 100%

# 2. Inform the kernel about partition table changes
partprobe "/dev/$DISK_DEV"

# 3. Resize the ext4 filesystem
resize2fs "$ROOT_PART"
