Page 1 of 1

shrinking HD using vboxmanage modifyhd sometimes does not work

Posted: 28. Feb 2017, 11:33
by bison
Hi, My Linux Host is Ubuntu. I increase my dynamic virtual box hard disk from 500,000 M to 500,200 M by implementing the command below:

Code: Select all

vboxmanage modifyhd [input].vdi --resize 500200
the above command works fine. But, when I tried to shrink the hard disk back to 500,000 M, it shows the error message as below:

Code: Select all

Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Resize hard disk operation for this format is not implemented yet!
The command for above I have executed is

Code: Select all

vboxmanage modifyhd [input].vdi --resize 500000 --compact --type=normal
.

I repeated the above command again and it works! When I wanted to further shrinked it, it shows the same error message again. I wonder what had actually happened that sometimes it works but sometimes does not work. The showhdinfo information after the only one time successful shrinking is as below:

UUID: 01f5b20e-ae04-4c84-b898-24d31472cdc4
Parent UUID: base
State: created
Type: normal (base)
Location: /home/louis[path][input].vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 500000 MBytes
Size on disk: 122632 MBytes

Please see attachment for the screenshot.

Thank you.

Re: shrinking HD using vboxmanage modifyhd sometimes does not work

Posted: 28. Feb 2017, 11:54
by socratis
From the User Manual about the "--resize" option, Ch. 8.23 VBoxManage modifymedium:
This currently works only for VDI and VHD formats, and only for the dynamically allocated variants, and can only be used to expand (not shrink) the capacity.
So, chances are it never worked. It shouldn't work for data safety reasons. If it did work, it's definitely a bug. But as I said, I doubt that it ever did.

Re: shrinking HD using vboxmanage modifyhd sometimes does not work

Posted: 1. Mar 2017, 05:26
by bison
Thanks for reply. Could you suggest a way to shrink the size? I am going to make a clone with fixed total size but this will eat up a lot of storage space with the current dynamic capacity. Thanks in advance.

Re: shrinking HD using vboxmanage modifyhd sometimes does not work

Posted: 1. Mar 2017, 06:08
by socratis
You can't shrink the drive per se, but what you could do is the following:
    • You didn't tell me your guest, you obfuscated it. Now, theoretically I should be obfuscating my answer as well, based on my signature alone. The thing is, I don't have a solid answer to obfuscate, because...
      ...my answer depends on the obfuscated information! In all fairness you obfuscated that before I even replied, so...
The general idea is to follow ch. 8.23. VBoxManage modifymedium, in the "--compact" section:
  1. If your guest supports defragmantation, you defragment it beforehand.
  2. You zero out the unused sectors with the appropriate tool, as described in the chapter that I gave you the link to.
  3. You compact your VDI with the "--compact" option.
  4. You launch the VM with a LiveCD tool like GParted, except if your client is OSX (it better not be), and you shrink the partition to something that your guest can fit in, plus some room for breathing.
  5. You leave the empty partition ... empty and you're done.
Now the logical size of your virtual HD is smaller and that empty partition will never be used again (unless you decide differently). So, in paper it may look big, but in reality it isn't. It's like having a 1 TB hard drive, but only using 10 MB. You'll only need 10 MB to carry that information in full.

Oh, and if you clone it, do NOT use fixed size, use dynamic, otherwise you'll be creating a HD that's as big as its physical size (the one that looks big on paper). There's absolutely no reason to have a fixed VDI, I wonder why they still keep that option around...