Handling VM disk space shortage
Why do we need to expand VM disks?
Section titled “Why do we need to expand VM disks?”As operations grow, VMs may exhaust their available storage due to logs, growing databases, or installing new services. While it is often preferable to store data on network or dedicated storage volumes and keep only important configuration data on the VM’s main disk, sometimes it is necessary to expand the VM’s disk to accommodate additional data.
Without sufficient space, you may face update failures, data loss, or critical application downtime.
Step 1: Resize disk size
Section titled “Step 1: Resize disk size”Proxmox supports two main methods for increasing the VM disk size:
- Using the Proxmox Web UI
Go to “VM → Hardware → [the disk you want to resize] → Disk Action → Resize.” Then enter how much to expand. - Using the qm command
Run the following in the Proxmox server terminal (outside the VM):
qm resize <VMID> <DISK> +<SIZE><VMID>: The numeric ID of the VM as shown in Proxmox.<DISK>: The disk identifier (e.g., scsi0, virtio0).<SIZE>: The amount of space to add (e.g.,10Gfor 10 GiB).
If your storage backend and guest OS support it, you can do this while the VM is running. Otherwise, you may need to shut down the VM for the resize to succeed. After resizing, confirm there are no error messages.
Step 2: Extend disk in VM
Section titled “Step 2: Extend disk in VM”1. Check the new disk size
Section titled “1. Check the new disk size”Log in to the VM (via SSH or console) and run:
lsblkThis shows all block devices, including the newly increased disk size.
2. Adjust the partition in the VM
Section titled “2. Adjust the partition in the VM”For traditional (non-LVM) partitions, you may just need to adjust with parted and then resize the filesystem. For LVM-based setups, you will expand the partition, then the physical volume, and finally the logical volume(s).
Below is a common example for LVM-based Ubuntu/Debian systems on disk /dev/sda:
# View current partition layoutsudo parted /dev/sda print
# Resize partition to use 100% of the newly available disk space# Replace <partition-number> with the correct partition indexsudo parted /dev/sda resizepart <partition-number> 100%
# Ask the OS to reread the partition tablesudo partprobe /dev/sda3. Resize the filesystem and LVM structures
Section titled “3. Resize the filesystem and LVM structures”Depending on the exact VM setup, use the commands that match your layout:
# If you have a standard EXT-based filesystem on a partition (not LVM):sudo resize2fs /dev/sdaX- Replace
/dev/sdaXwith the correct partition device (e.g.,/dev/sda3).
# For LVM-based setups:# 1. Resize the LVM physical volumesudo pvresize /dev/sdaX
# 2. Extend the logical volume to use all free spacesudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
# 3. Finally, expand the filesystem (e.g., EXT4)sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lvFor XFS filesystems, replace the resize2fs step with:
sudo xfs_growfs /mount/point(e.g., /mount/point might be / for the root filesystem).
4. Verify the expansion
Section titled “4. Verify the expansion”After these steps, verify the new size with df -h.
Quick summary
Section titled “Quick summary”- Proxmox Resize: Use the UI or the
qm resizecommand to expand the virtual disk. - Partition Resize: Inside the VM, use tools like
partedorfdiskto update the partition table to the new size. - Filesystem/LVM Resize: Apply
resize2fs,pvresize,lvextend, orxfs_growfsaccording to your filesystem.