VMware Workstation

 View Only

 Shrink disk in Encrypted Linux Guest

gbohn's profile image
gbohn posted May 30, 2025 10:03 AM

I have an encrypted Fedora 41 Linux Guest running under a Windows 11 Host using Workstation 17.6.3.

I want to reclaim unused guest disk free space on the host. What is the recommended way to do this?

The Guest's disks are not pre-allocated and are using multiple host files.

At one time at least you needed to remove snapshots, decrypt the guest, zero out space from within the guest, shut down the guest, and then 'compact' the host file (from the host) with something like

   vmware-vdiskmanager.exe -k "<path to vmdk>"

Looking at https://knowledge.broadcom.com/external/article/315631/defragmenting-and-shrinking-vmware-works.html it seems to reference running a command from the guest environment like

   sudo vmware-toolbox-cmd disk shrink /

Would this work from within an encrypted guest? (So as to not have to resort to decrypting the guest).

Is there a better way? 

gbohn's profile image
gbohn

In an attempt to answer my own question I cloned a 'small' encrypted Fedora 41 guest and gave it a whirl on the clone.

On one hand it did seem to shrink the disk without causing any obvious major disk growth in the process (I was afraid the 'zeroing' part might cause host file growth since it was encrypted).

But I did get a strange error soon after completing the process. In the guest I saw

] sudo vmware-toolbox-cmd disk shrink /home
[sudo] password for xxxxxx:

Please disregard any warnings about disk space for the duration of shrink process.
Progress: 100 [===========>]

Disk shrinking complete.

]

Message from syslogd@xxxxxxxxxxx at May 30 12:15:42 ...
 kernel:watchdog: BUG: soft lockup - CPU#0 stuck for 127s! [kwin_wayland:2221]

The earlier program  message said to ignore disk space warnings (which did happen), but didn't mention anything like 'kernel:watchdog' errors...

It did take a while for the process to complete.

Can these also be ignored?

RaSystemlord's profile image
RaSystemlord

I don't know about the issue with encryption, but in this thread and elsewhere people are talking about "shrink" and command line options.

Are these Player things (or possibly Linux things, although I never used them in Linux)? Now that everybody has Pro version, I like to remind that it has "always" had Compact in GUI. That is the one that "reclaims unused guest disk free space on the host". Don't know exactly what the shrink does, but whatever it does, it is not needed for the above (typically shrink makes a permanent fix to your pre-allocated disk size (like in Windows), this is hardly the case of "reclaiming unused space on the host", because when using pre-allocated disk sizes, you told not to do that under any circumstance (making Oracle DBs faster, for instance)").

I just yesterday reclaimed 150 GBs of space on the second disk and 50 GBs on the first disk (running Win 11 from there). Compact works just fine and has "always" worked. The workflow is this:

a)

delete everything that you don't need on the VM. VM OS indicates "free space" for the deleted

b)

delete all Snapshots, if any. You CANNOT reclaim space for deleted files if you have any snapshot. That is how Snapshot functionality works - nothing is really deleted from the disk, just marked deleted - because when going back to a Snapshot, you need (some of) the deleted files.

c)

shutdown (not suspend, not put to sleep, nor hibernate) the VM. Double-check this is you are unaware what your OS really does.

d)

select the disk in Settings

e)

do Defragmentation to that (not sure if that is needed with SSD, but might make the Compact to work better, not sure if needed)

f)

do Compact and the space is reclaimed. Compact tells you "your disk does not have pre-allocated space" (when Compact is impossible, because you told the system, when installing, to keep the file in the pre-set value), "your disk is consisting from many files" (where Compact works just fine).

g)

do the same for all the disks

h)

forget command line options if this is what you want to do

gbohn's profile image
gbohn

> don't know about the issue with encryption, but in this thread and elsewhere people are talking about "shrink" and command line options.


Shrink and compact seem to both be used interchangeably at times. What I am trying to accomplish is to remove 'unused' space on the host for a Virtual machines .vmdk files.

I don't use 'pre-allocated' so the used Host space increases as you add more data and often even if you add and then remove data for the same net currently allocated size.  (Stuff presumably gets marked as used and Vmware apparently isn't aware that it is no longer in-use when it is released).

> I like to remind that it has "always" had Compact in GUI.

The Workstation 17.6.3 GUI only seems to have the 'clean up disks' option for a Windows Guest. I do not see this for Linux Guests. 

My concern about Encrypted Guests was that (at least at some point in the past) the Linux instructions had you do a manual  step of writing 'zeros' to all available space in the guest. (Followed by a Host step to actually compact the disk with a command line now that it had been prepared with zeroes).

In the past, I've had encrypted Linux Guests react to the 'write zeroes' step in the guest by tremendously growing the Hosts used drive space for the guest. (Which did not seem to happen for un-encrypted Linux Guests). I assumed this was because the 'zeroes' got written to the .vmdk's as an encrypted version.

I hadn't tried this in a very long time, so I wasn't sure if this was still an issue or not.

As indicated in my subsequent post, I was able to try the (new to me) method of performing the command

   sudo vmware-toolbox-cmd disk shrink /home

from the Linux Guest and it seemed to eventually work without 'blimping out' the Host space beyond what you would expect for an un-encrypted guest.

It just needed the amount of space for an individual part of the multi-part (in my case) .vmdk files as it worked through them.

I did get a warning about

  kernel:watchdog: BUG: soft lockup - CPU#0 stuck for 127s! [kwin_wayland:2221]

I assume this was because some type of Guest processing must have gotten stalled during the process. 

I'm not sure if that can safely be ignored or not. 

RaSystemlord's profile image
RaSystemlord

gbohn: Shrink in Windows and SQL Server (and Oracle if I remember right) means to get pre-allocated spaces smaller. Compact was the terminology for what you are trying to achieve with 17.5.2 and before.

I seem not to know what functionality has been taken away and what terminology changes have been messed up if you ask me, with 17.6.x versions. But obviously, your primary concern was about encrypted guests, which I'm not familiar with in this regards.