How do I shrink my Proxmox VM disk?
Hi everyone,
I just spent my entire Friday trying to shrink the disk of my Proxmox VM, and I’ve hit a wall. I managed to break the VM twice but thankfully was able to restore it each time. I do have backups of the important data, but I’d still prefer to shrink the disk since it currently holds about 5TB of data, which would take forever to restore if something went wrong.
Here’s the issue:
The sum of all thin volume sizes (7.32 TiB) exceeds both the size of the thin pool media/media and the size of the entire volume group (<6.99 TiB).
My goal is to resize the disk of my VM so that it fits within the volume group. However, I’m struggling to understand the various units being used (TiB vs. TB), and after spending 8 hours on this, I feel completely stuck.
Thin-LVM configuration:
Disk view on the Proxmox host:
Disk view from inside the VM:
How can I shrink this disk to make it fit within the volume group? I’ve tried following several guides (and even consulted ChatGPT), but it sent me so deep into a rabbit hole that I can’t seem to find my way out. At this point, I think I need advice from someone with experience.
Thanks in advance for your help!
Comments
Something something convert to qcow then resize lmresize something something
Thats all i remember 😅
1 TiB = 2⁴⁰ = 1024GiB
1 TB = 10¹² = 1000GB
7.3 TiB ≈ 8TB
I don't use proxmox/lvm but general rule is to first resize the filesystem within the virtual disk and then touch the disk.
Since it's very easy to mess things up, resize filesystem and then export it to a new disk.
What's the filesystem inside the vm?
Thanks for the tip. Filesystem inside the VM is ext4.
LinuxFreek.com
Great, go with something like gparted to check the inner filesystem and shrink it as low as possible (5.3tb) then lvreduce on the host to resize the vm-..-disk-0 to something like 6-7TB (or whatever) and then again with gparted to expand the inner filesystem to fill the remaining space. Double check if this procedure aligns with proxmox best practices because I dont use it.
I see that lvreduce also has --resizefs option to shrink also the underlying filesystem, but I think it's riskier.
Like @itsdeadjim wrote, first shrink the filesystem within the VM. Also the partition it is on!
Don't use --resizefs with lvreduce from the outside.
It usually is a good idea to run fstrim inside the vm beforehand and do the fs and partition shrinking from a rescue cd/gparted.
Check if it boots up after those shrinking steps, only then reduce the actual device with lvreduce while the VM is stopped.
You probably also want to adjust the config file of proxmox to reflect the size change properly.
Leave gaps/breathing room esp. if unsure with the units ;-)
Thanks for the pointers @Falzo and @itsdeadjim . Seems like I was really close during my initial approach, but the key for me was to verify the disk and fix any issues using gdisk after resizing it (as shown below).
For future reference (and because people who write "I fixed it" and don't post the solution go to hell): The goal of the steps below is to resize the ext4 partition
/dev/sda2
and its disk/dev/sda
to 6.9T, so that they fit within the thin-LVM pool sized at 6.95T (as shown in the opening post).⚠️ Disclaimer: I have no idea what I'm doing, so follow these steps at your own risk.
Steps:
1. Trim Unused Space
Inside the VM, run:
This will save time during the disk operations.
2. Boot into GParted Live ISO
Boot the VM using the GParted Live ISO.
3. Resize the Partition
Use the GParted GUI to shrink the partition
/dev/sda2
to the smallest size possible, leaving a little headroom.Example:
4. Shutdown the VM
After resizing, the partition
/dev/sda2
will now be smaller, but the disk itself (/dev/sda
) will still be the original size. Let's fix that. Shut down the VM.Example:
5. Resize the Disk on the Proxmox Host
On the Proxmox host (hypervisor), resize the VM disk to fit within the thin-LVM pool:
Replace
/dev/media/vm-101-disk-0
with your VM's disk path.Why 6.9T? My thin-LVM is 6.95T, so I left a bit of headroom to avoid overcommitting the pool.
Example:
6. Rescan the Disk in Proxmox
Run the following to make Proxmox aware of the new disk size:
Example output:
7. Attempt to Boot the VM
If you're lucky, the VM will boot without issues. However, you'll most likely encounter an error like:
If this happens, boot the VM into the GParted Live ISO again. The GParted GUI will show all storage as unallocated, but don’t panic (famous last words).
Example:
8. Fix Partition Errors with
gdisk
Open a terminal in GParted and run:
v
to verify the disk.You’ll likely see warnings or errors. Follow the on-screen instructions to fix them.
x
), then presse
, and so on, until all errors were resolved.Once everything is fixed, type
w
to write the changes to the disk and press Enter.Example:
9. Resize the Partition Back to Match the Disk
Open the GParted GUI again. This time, you can expand the partition to fill the resized disk.
Example:
10. Verify the Disk Layout
Check that the disk size and partition size match your desired configuration:
Example:
11. Check the Filesystem for Errors
Run a filesystem check to ensure no errors:
12. Reboot the VM
Finally, reboot the VM. It should boot without any issues, and the disk and partition should now be sized as desired.
Example:
That wasn't so hard after all… lol. I hope it helps
LinuxFreek.com
☑️
No hostname left!
I actually keep a wiki on GitHub with server tasks I've done to remember how to accomplish them again, in case I forget. Awesome that you keep this documented
Ympker's VPN LTD Comparison, Uptime.is, Ympker's GitHub.
This warrants a blog post for future reference.
The all seeing eye sees everything...
+1 for this.
Might need it in the future
Thanks for the feedback, I appreciate it. I could probably spin up a demo VM and go through over all the steps again in a video or something for a blog (?).
Haha recognizable. I use my 'note to self' blog for cases like this
LinuxFreek.com