2

On a Linux host (Linux Mint 18), how can I compact a VHD file ?

So far my search always returns solutions with Hyper-V or situations with a Linux guest on a Windows host, but have the inverse: a Windows guest running with VirtualBox on a Linux host.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
P_W999
  • 281
  • 1
  • 10
  • AFAIK Hyper-V does not exist for linux hosts. Are you sure you are using Hyper-V? The VHD format is used by other hypervisors as well, for example VirtualBox and Xen. – Gerald Schneider Dec 20 '17 at 08:26
  • I'm not using Hyper-V but Virtualbox. I tagged it with Hyper-V as the VHD(x) format is most often used in Hyper-V context. – P_W999 Dec 20 '17 at 09:35
  • https://superuser.com/questions/599905/errors-when-compacting-virtualbox-vhd-image – Gerald Schneider Dec 20 '17 at 09:39
  • I don't know what you have been searching, but "virtualbox compact vhd" has a lot of search results, most of them looking promising. – Gerald Schneider Dec 20 '17 at 09:40
  • Figured it out myself by now :) . I did not search for virtualbox as I assumed it was uncapable of compacting VHDs directly so I looked for alternative tools to do this.. – P_W999 Dec 20 '17 at 10:53

1 Answers1

1

I kind of feel stupid because I found an answer while trying to circumvent the usage of VHD files on Linux. Cloning the disk to the VDI format (after runing sdelete on the Windows guest) also shrinks it to the smallest size:

vboxmanage clonemedium INPUT.VHD OUTPUT.VDI --format VDI --variant standard

It also works from VHD to VHD

vboxmanage clonemedium INPUT.VHD OUTPUT.VDI --format VDI --variant standard

This solutions is not as efficient as "compacting" because you need extra storage to store a second copy of the virtual disk and after the process has finished you need to swap the files.

P_W999
  • 281
  • 1
  • 10