Page 1 of 1

Reducing unused .vmdk storage size

Posted: 4. Sep 2019, 21:18
by miths3
Hello there

I'm running VirtualBox Version 5.2.32 r132073 (Qt5.9.5) on Ubuntu 18.04. It is running very smoothly on 8GB of RAM (in comparison with 4GB RAM).

I have created a .vmdk dynamically allocated 1 partition storage for Windows 8 guest and would need to free ~15GB of unused storage. Under "VirtualBox Manager" > "Global Tools" for Win8.vmdk guest it shows 40GB virtual storage and 22.64GB actual storage (21GB free). So when I'm trying to reduce the .vmdk storage from 40GB to 20GB a red "!' sign appears near the numerical value of the storage volume with a message
Cannot reduce medium size from 40GB to 20GB as storage shrinking is currently not implemented.
So would like to inquire whether there is a way to reduce the unused storage size without reinstalling the Windows 8 guest?

Thanks

P.S. I never performed Disk Defrag on this Windows guest. Generally I perform only regular disk/registry cleaning on this guest. My actual hardware storage is SSD and I heard that it is not recommended to perform defragmenting on SSD. Maybe I should perform Disk Defrag on this guest?

Re: Reducing unused .vmdk storage size

Posted: 5. Sep 2019, 16:52
by socratis
Rule #1: You cannot shrink the theoretical size of a virtual disk. That's why the operation is not permitted.
miths3 wrote:21GB free ... reduce the .vmdk storage from 40GB to 20GB
So, do you really want to leave your guest with 1 GB of HD free? Are you sure you want to do that? Have you considered the consequences? My Firefox cache uses that much alone!
miths3 wrote:So would like to inquire whether there is a way to reduce the unused storage size without reinstalling the Windows 8 guest?
Why? What do you have to gain? There's a difference between what your virtual drive is 1) actually occupying on the host, 2) what's it's theoretical maximum size, 3) what's currently occupying in the guest.

Are you maybe thinking about the actual size of the VMDK on your host? Because that's a different thing altogether. What you need to do is to "compact" it. Unfortunately, you can only compact VDI files, not VMDK ones. For more info see ch. 8.24 VBoxManage modifymedium of the User Manual, and specifically the "--compact" option.

Another option would be to clone the VMDK to a VDI. That will compact it as well at the same time. See ch. 8.25 VBoxManage clonemedium of the User Manual.

Finally a third option, if you've installed Wine on your host, would be to use the CloneVDI tool.

Re: Reducing unused .vmdk storage size

Posted: 6. Sep 2019, 22:51
by miths3
During the creation of this guest I set the storage size to 40GB (probably) and I thought it would occupy the same volume of storage on the host so I wanted to free at least 10GB for the host as I don't use them on the guest.

But now in the "VirtualBox VMs" host folder I see the actual storage volume for Win8.vmdk file is 24.3GB which is rather congruent with this Windows 8 guest and my storage usage.

And while running this Windows 8 guest it shows 21GB free for the guest. So these free 21GB displayed by the guest for the guest are virtual?

Do you mean that while setting up the initial guest storage volume it is not the actual, but the virtual storage volume being set?
So these 40GB I set up initially were virtual?

Re: Reducing unused .vmdk storage size

Posted: 7. Sep 2019, 09:59
by socratis
miths3 wrote:During the creation of this guest I set the storage size to 40GB (probably) and I thought it would occupy the same volume of storage on the host
That depends if you created a Fixed size disk or a Dynamic size disk. Post the output of the command:
  • VBoxManage showmediuminfo "<Full path to your VMDK>"
miths3 wrote:so I wanted to free at least 10GB for the host as I don't use them on the guest.
Unfortunately the idea of shrinking a virtual drive's logical size is not yet implemented, due to the inherit danger of data loss. There are ways to "shrink" the maximum size occupied by the VMDK. Take a look at the thread "Can I compact VDI this way?" for the standard procedure.

However, you chose a VMDK (not sure why you didn't pick the default), which cannot be compacted with VirtualBox. Read the linked thread (all of it) for more info and alternative ways to "shrink" your virtual hard drive.
miths3 wrote:the actual storage volume for Win8.vmdk file is 24.3GB
That means that you have created a Dynamic size disk. I think it's time that you read 1.8. Creating your first virtual machine, bullet #5 for some crash course on the hard disk options. All your questions will be answered... ;)

Re: Reducing unused .vmdk storage size

Posted: 7. Sep 2019, 10:53
by miths3
Thanks, I'm on the way to the links.

The output (relevant to the post) of the command
VBoxManage showmediuminfo "<Full path to your VMDK>"
is:
...
Parent UUID:    base
State:          created
Type:           normal (base)
Storage format: VMDK
Format variant: dynamic default
Capacity:       40960 MBytes
Size on disk:   23189 MBytes
...

Re: Reducing unused .vmdk storage size

Posted: 7. Sep 2019, 11:06
by socratis
Thanks, it shows exactly what I suspected/expected...

BTW, I do not recall asking for the "chopped" version that you think is relevant. Please do not do this again. When I'm asking for information I want the whole non-redacted version!

Re: Reducing unused .vmdk storage size

Posted: 15. Apr 2020, 10:15
by miths3
I added ~8-10 GB of data to the guest and now it occupies 39.6-9GB on the host, though in the guest interface it shows 14.9GB free.
I think I wouldn't have enough host space to clone it and in order to compact the guest space to be reduced it should be filled with zeros etc.
Generally it wouldn't be a big deal to reinstall this guest anew into VDI.

The output of the command is the following:
UUID: ea84b19b-3811-49b1-9e41-fe1195c52c94
Parent UUID: base
State: created
Type: normal (base)
Location: /home/user10/VirtualBox VMs/Win8.1(7mod)/Win8.1(7mod).vmdk
Storage format: VMDK
Format variant: dynamic default
Capacity: 40960 MBytes
Size on disk: 38074 MBytes
Encryption: disabled
In use by VMs: Win8.1(7mod) (UUID: 84844d9d-f3ee-419f-9248-121c2ec29c59)

But thanks for the info.