This script automatically expands the root LVM disk in a Debian/Ubuntu virtual machine after increasing the disk size in your hypervisor or control panel.
expand-lvm-disk resizes the last partition on /dev/sda, updates the partition table, resizes the LVM physical volume, extends the root logical volume, and grows the filesystem (ext4 or xfs). It also reduces reserved blocks on ext4 filesystems to 1% to maximize usable disk space.
- Debian 10/11/12 or Ubuntu 18.04 or later.
- Root filesystem on LVM in the last partition of
/dev/sda. - Root privileges.
- Increase the size of your VM disk in your hypervisor/control panel.
- Upload the script to your VM.
- Make it executable:
chmod +x expand-lvm-disk
- Run the script as root:
sudo ./expand-lvm-disk
- Verify the new disk space:
df -h
- Only works with
/dev/sdawhere the root filesystem resides on LVM in the last partition. - Does not support complex partition layouts, multiple disks, encrypted volumes, or separate non-LVM root filesystems.
- Always create a backup before modifying disk partitions.
Use this script at your own risk. The author assumes no responsibility for data loss or system issues resulting from its use.