A dialog based tool that shrinks a Proxmox VE virtual machine disk or LXC container volume completely offline from the host. It replaces the manual GParted procedure: no live ISO, no clicking, no partition editor inside the guest. The whole shrink runs on the PVE node against the stopped guest, which makes it deterministic and repeatable.
It auto discovers the volume, the storage backend and the layout, computes the smallest safe size from the actual data in use, and refuses to make a volume smaller than the data plus a headroom you choose.
You pick a VM or a container, the disk or volume, and how much to reclaim. The tool then runs the offline sequence that fits the layout:
- Check the filesystem first (
e2fsckfor ext,ntfsresize --infofor NTFS). Errors are only repaired after you confirm, a dirty or hibernated NTFS is refused. - Shrink the filesystem where needed (
resize2fsfor ext2/3/4,ntfsresizefor NTFS). - For a partitioned disk, shrink the chosen partition with
sgdisk, preserving its start sector, type, name, unique GUID and GPT attribute flags, soroot=//etc/fstab, the Windows boot chain and a Windows Recovery partition keep working. Partitions that sit after it are moved down into the freed space, keeping their order and identity, swap is recreated with its original UUID. - Shrink the backing device:
zfs set volsize(zvol),qemu-img resize --shrink(qcow2 or raw image),rbd resize --allow-shrink(Ceph/RBD), orlvreduce(LVM). For a ZFS subvol container the dataset refquota is lowered and no filesystem is touched. - For a partitioned disk, move the GPT backup header to the new end (
sgdisk -e) and verify the table (sgdisk -v). - Sync the new size back into the guest config (
qm rescanfor a VM, the container config for a CT).
Volumes that hold a filesystem or an LVM physical volume directly on the device, with no partition table, are handled too, the partition and GPT steps are then skipped. This is the normal case for containers.
Guests: QEMU VMs (qm) and LXC containers (pct), listed together.
VM storage backends: ZFS zvol, qcow2 image, raw LV, Ceph/RBD (with KRBD enabled on the
storage, so the image maps to /dev/rbd).
Container storage backends: dir/raw image, LVM-thin, ZFS subvol.
Filesystems: ext2/3/4 and NTFS shrink in place. A ZFS subvol is shrunk by its refquota, so its content is never touched.
Layouts:
- Any GPT layout: you pick which partition to shrink, and any partitions after it are moved down into the freed space while keeping their order, numbering and identity. This covers Windows (C: with a Recovery partition after it) and Linux with extra partitions after root.
- Reclaim only the free space after the last partition, without touching any filesystem, partition or LVM. This is offered as the safe default whenever such free space exists.
- Whole disk or container volume with a filesystem directly on it, no partition table.
Guest LVM (an LVM physical volume inside a VM disk) has three modes:
- Reclaim only the free space after the LVM partition, LVM untouched.
- Compact: reclaim the volume group's free space with
pvmoveandpvresizewithout shrinking any filesystem. Because no filesystem is touched this works with XFS and with mixed volume groups, and handles volume groups that hold several logical volumes. - Shrink a filesystem to go below the used size, when a shrinkable ext logical volume exists.
- XFS cannot be shrunk. A plain XFS partition is refused. XFS inside an LVM volume group can still be reduced by the group's free space using the compact mode above, since the XFS filesystem itself is never touched.
- BitLocker (or any encrypted) volumes are detected and never touched. Shrink it in Windows first, or turn BitLocker off there, then re-run this tool. Applies to any encrypted volume.
- MBR (msdos) partition tables are refused (convert to GPT). A whole disk with no partition table is fine.
- NTFS must be cleanly shut down, a hibernated volume or Fast Startup is refused.
- Ceph/RBD is supported only with KRBD enabled (so the image maps to
/dev/rbd). A librbd-only volume has no local device and is refused with a hint to enable KRBD.
Run it as root on a Proxmox VE node. It uses tools that ship with PVE: qm, pct, pvesm,
sgdisk, e2fsck, resize2fs, qemu-nbd, qemu-img, blkid, lsblk, partx, zfs,
dialog, numfmt. LVM needs lvm2. NTFS needs ntfs-3g; the tool offers to install it when
needed. A Ceph/RBD disk needs rbd
(ceph-common), which is already present on any PVE node that serves RBD storage.
pve-disk-shrink.sh interactive: pick the guest, the volume and the target size
pve-disk-shrink.sh --dry-run show the full plan and computed sizes, change nothing
pve-disk-shrink.sh --debug verbose trace into the logfile
Interactive flow:
- Pick the VM or container.
- Pick the disk or volume. VM efidisk, tpmstate, cloudinit and CD drives are never listed. For
a VM the boot disk is marked
[boot]. - For a partitioned VM disk, pick the partition to shrink, partitions after it are moved down. This step is skipped for a whole-disk filesystem or a container volume.
- If the guest is running you are asked to stop it.
- If it has snapshots you are warned that all of them will be deleted permanently, and asked to confirm. Snapshots block a shrink and cannot be kept.
- If it has
protectionset, you are offered to disable it for the shrink. It is re-enabled automatically at the end, including on cancel or error. - Choose how to shrink. Depending on the layout this is a target size (data plus 10, 20, 30, 40 or 50 percent, or a manual size) and, for LVM or when free space follows the last partition, a choice between reclaiming only that free space, compacting, or shrinking a filesystem.
- Review the summary and confirm. Nothing is written before this confirmation.
- The guest must be stopped, the volume is worked on offline. You pick the volume explicitly (efidisk, tpmstate, cloudinit and CD drives are never listed).
- The target can never be smaller than the data in use plus your chosen headroom, nor larger than or equal to the current size.
- Sizes are parsed in the C locale, so a localized host cannot mis-parse them.
- The GPT is verified with
sgdisk -vafter the shrink, a failed check stops the run and tells you not to start the guest. - Every destructive step needs explicit confirmation, and a cleanup routine always detaches nbd
devices, partition mappings and activated volume groups on exit.
--dry-runchanges nothing.
This tool creates no backup. Make sure a current backup of the guest exists before you use it.
The original partition layout (sgdisk -p) is written to the log before any change, so it can
be read back and recreated by hand.
If a run stops with a GPT verification error, do not start the guest: rebuild the backup header
with sgdisk -e <device>, then verify with sgdisk -v <device>.
If a guest drops to an emergency shell for a manual filesystem check, run fsck -y /dev/<device>
and exit to boot on.
The first boot after a shrink can be slower and may print RCU or lazy-inode warnings while ext4 finishes in the background, this is expected.
Everything is logged to /var/log/pve-disk-shrink/pve-disk-shrink.log.
