I’m going to just lay out some general ideas. This post isn’t about giving you commands that you can replicate. It’s about giving you the clue to understanding what Proxmox & Linux is doing.
Shrinking is something that we all will have a need to do one way or the other simply because we always over provision space in a Windows VM. The issue with shrinking the space for an environment such as Proxmox is not well discussed. Notice I didn’t say well documented? The reason I used the word discussed is because when you go looking for support you are often never given the little tidbit that would make it clear for you what is required. I’ve read the Proxmox forums and searched google far and wide and all I found were people posing incomplete questions about how to accomplish this that described some rather convoluted scenarios where someone needed to do something odd, and I even encountered pages where they describe nothing and expected you to be able to shrink your VM’s allocated space from that.
When you set up your Windows VM you specified in Proxmox where it was to be done (which volume) and how much space. These two things are key to understanding how to reduce the size.
In Proxmox you have set up various storages with various underlying technologies, such as LVM, ZFS, EXT4, etc. And when Proxmox allocated the space it did so in one of these. Many new people don’t understand the importance of making the distinction.
When I went looking to reduce the size of the VM I had LVM, ZFS, and Ext4. I looked at the VMs and noted that they were on LVM. I also had some on ZFS. In fact, I wanted to reduce the size of some of the VMs because I needed several to fit on an SSD and still have 1/2 the space free. The SSDs were formatted as ZFS.
The problem was that with their full sizes I filled the SSD up to 93% which brings with it a slew of other issues, such as wear leveling.
I found that the first step was to go into Windows and open disk management and choose the Action menu, choose All Tasks and then choose Shrink volume. This is relatively simple. Use the amount that the tool recommends.
When you do this you end up with a volume in Proxmox that’s does NOT appear to be shrunk. That’s because you only told Windows to set the extra space as unallocated. The reason is Microsoft is assuming that you may want to create a new partition and put files in it. Since we are trying to reclaim that space for Proxmox we don’t want to do that.
That leads to the second step. Use the tool in the Linux environment to reduce that space allocated to the VM. Since the space is seen by Windows as unallocated we can tell Linux to use the tools to reduce it. If your VM is stored on an lvm-thin you can use the command called lvreduce. If it is on ZFS you use the equivalent ZFS tool (for example):
zfs set volsize=120G rpool/data/vm-100-disk-1
Or move the volume from ZFS to an LVM and then reduce it with the lvreduce and then move it back. The key for LVM is that when you put a VM on the LVM it becomes an LVM volume not a file. If your VM is on ZFS it becomes a raw file. That means different tools for different file systems. If you move from an LVM to ZFS and shell out to watch htop you can see that Proxmox is converting the VM.
When you are using lvreduce to reduce the size you need to account for the fact that lvreduce will just reduce the volume regardless of how much is actually allocated for the Windows partitions. That means that unless you are careful and know the exact size of the allocated space in Windows you could end up cutting off some of the Windows allocated space thus destroying your VM. I chose to have 5gb of unallocated space in the VM just in case. So, if Windows allocated space for use by the file system was 470GB I used lvreduce to reduce it to 475GB. Just be careful that you don’t destroy your VM. You might also want to ensure that you have it backed up before doing this.
When done you should use the command line on the PVE node to tell Proxmox to rescan the VMs. You do that with sudo qm rescan. At that point it will properly show the new size in the Proxmox web UI.
NOTE: One thing that I noted was that when doing this on a Windows 7 VM at the end Microsoft said the hardware had changed too much and that I’d have to activate it again. So beware of doing this unless you have a way to activate it again.