Is it possible to reset a .vdi drive?

This is for discussing general topics about how to use VirtualBox.
Post Reply
NJMorf
Posts: 1
Joined: 24. Nov 2022, 21:09

Is it possible to reset a .vdi drive?

Post by NJMorf »

I'm using VirtualBox 6.1.40 r154048 on Windows 10.

I have a VM running TrueNAS Core which I use to test things for my home NAS. I've created multiple small VDI images of various nominal sizes, all as dynamically allocated files. After writing data in TrueNAS, the .vdi file sizes are obviously changed proportionately. Since there's no data in the drives that I need to keep, I want to recover the physical disk space by reducing the virtual disk files back to their original, newly-created file size (e.g. 2MB instead of 500).

In the past I've deleted and recreated the drives, but I'm hoping there's a quicker way to do it. I've tried making copies of the files after creation and then overwriting the changed versions, but VBox won't allow that. Is there a way to do this, or am I going to have to create new drives each time?

Thanks in advance.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Is it possible to reset a .vdi drive?

Post by scottgus1 »

If you're looking for a one-for-one replacement, as in a new "A.vdi" for a used "A.vdi" then Virtualbox will allow this. You only have to make sure the VM is completely shut down, and you can't use snapshots.

Make a new A.vdi in its 2MB size. When you have the .vdi set up the way the way you want it to be upon reset, shut down the VM, then make a backup copy of A.vdi, either as "A-copy.vdi" or some such in the original folder, or move the copy of A.vdi to a different folder.

After A.vdi has been used and you're ready to reset it, shut down the VM and copy the backed-up A.vdi back over the original. Make sure the restored copy has the same original name.
Post Reply