Shrink Proxmox VM Disc Size

Shrinking a disc size of a VM in Proxmox is a bit fraught as it is easy to make an error which destroys the data. It’s imperative to have a recent backup so you can start over should things go wrong.

The first thing to note is the type of unit for the data. Errors can arise from changing units unintentionally which can cause errors. When dealing with discs, partitions and filesystems the units can be bytes, multiples of bytes in thousands or multiples of bytes in blocks of 1024. For gigabytes the designators are B, GB, GiB. It is recommended to always specify the units and to be consistent in their use.

So here’s what you do:

  1. Identify the path to the logical volume containing the partition
    • e.g. /dev/mapper/local–nvm–530–disk–1
  2. Reduce the filesystem size to the desired size ensuring it’s big enough to hold all the data. Different filesystems have different ways of doing this. You can use a tool such as parted to do this or, for example with BTRFS you can just use btrfs filesystem resize
  3. Now choose the size of the partition the filesystem is going to live in ensuring it is at least as large as the filesystem e.g 72GiB, use parted <path> for this:
    • e.g parted /dev/mapper/local--nvme-vm--530--disk--1
      • use ‘p’ to list partitions
      • use resizepart <partition number> <size>
        • e.g. resizepart 3 72GiB
  4. Now reduce the disc size i.e the logical volume size.
    • If your underlying storage is LVM-Thin you now need to discard the blocks you don’t need. lvreduce does not do this step for you. Use blkdiscard -f -o <size> <path>. The -f (force) is needed because the filesystem is in use.
      • e.g blkdiscard -f -o 72GiB /dev/mapper/local–nvme-vm–530–disk–1
    • Then use lvreduce to reduce the size of the partition aka logical volume: lvreduce -L <size> <path>
      • e.g lvreduce -L 72GiB local-nvme/vm-530-disk-1
  5. It’s time to repair the GPT partition table by rebuilding the backup data structures at the end of the disk. Use gdisk <path> for this.
    • e.g gdisk /dev/mapper/local--nvme-vm--530--disk--1
      • Select expert mode ‘x’.
      • Select ‘e’ to replace the data structures.
      • Select ‘m’ to return to normal mode.
      • Select ‘p’ to list partition table to check.
      • Select ‘w’ to write the partition table.
      • Select ‘q’ to exit.
  6. Run partprobe to update the system’s knowledge of the partition table
  7. Run qm rescan to update Proxmox disc details.
  8. Use lvs to see that Proxmox disk details.
  9. Now reboot the VM. If you don’t reboot you may find Proxmox uses old data particularly for backups. If it fails to boot and drops to debug prompt use dmesg to see if a reason is given. If it fails to boot you’ll almost certainly have to recover the VM and start again.

This procedure was gleaned mostly from posts on the Proxmox community forum.