8m--dq
Last Updated: February 25, 2016
·
27.54K
· ipoerner
Af0ab274ae0b28cfa0e2a7fd830ee5ed

Purge deleted hard disks from Virtual Box

When you remove a virtual hard disk drive from within Virtual Box, the file itself is not removed. Even worse, deleting the file manually and then trying to add a new virtual disk with the same file name in the same path will just yield an error. Virtual Box complains about the file name already being associated with a specific UUID.

All your virtual hard disk drives are stored in the global Virtual Box configuration. You can retrieve a full list using the following command:

vboxmanage list hdds

This will give you the file names and UUIDs to each virtual disk. In order to remove an entry from the list and make the file name available again, simply execute the following command:

vboxmanage closemedium disk <uuid> --delete

After that, both the file and the UUID entry in the configuration should be be purged from the list and you can create a new virtual hard disk drive with the same file name again.

Say Thanks
Respond

2 Responses
Add your response

22540
None

This was very helpful, thanks.

over 1 year ago ·
22898
0 x9j4ktc7ktbmyucta hikalaeqatpfntjndbkanpbclliwt 1rdqolggqylyxhbyyzr6xnkunlzn

I had the opposite problem of having lots of old VDI images that were no longer registered in virtualbox that I wanted to delete from my host.

I had been using snapshots and linked clones for a couple of years (on a 2TB drive) and had lots of old unused images who's state was not obvious .

My technique was to generate two text files. One containing the list of registered hdd images (as in the main article above), and the other containing the list of images on the host HDD and do a DIFF to compare them (after they were sorted). Then manually delete each as indicated by the difference report:-

  1. Open a command prompt.

a. CD \program files\oracle\virtualbox

b. md temp

c. cd temp

d. ..\vboxmanage list hdds | find "Location" | sort > allregisteredhdds.txt

e. Use a good text editor to manually delete the left column of "Location " to leave the start of each line reading, for example "E:\"

f. dir E:\VM*.vdi /s /b | sort > all_vdi.txt

  1. Right mouse click and select KDIFF allvdi.txt allregistered_hdds.txt

Repeat step 1.f to find VMDK, etc.

Note, all my images were under E:\VM.

over 1 year ago ·
Filed Under