[Guru Meditation] Shrink Dynamically Allocated VDI Image

This is for discussing general topics about how to use VirtualBox.
Post Reply
operation420.net
Posts: 60
Joined: 28. May 2020, 02:17
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Linux, Windows
Location: The hood
Contact:

[Guru Meditation] Shrink Dynamically Allocated VDI Image

Post by operation420.net »

I have an archived link on "How to shrink a dynamically-expanding guest virtualbox image" I used before I am pulling up for reference.

That link and the archived link mentioned by the reference to sdelete for Windows Guests uses the VBoxManage modifyhd my.vdi –compact command (one uses -compact and the other says compact without - in front, but the comments mention -compact with - in front).

The first link I had is now dead, hence why I am using archive.org. When I clicked the link to https://www.maketecheasier.com/shrink-y ... ualbox-vm/ from the first link it pulled up the archived version, I right clicked the URL in the archive.org header and selected the option to open the link to open the live copy.

On the live copy, instead of using VBoxManage it uses a bunch of diskpart commands.


Which is the best way to shrink the image without data loss, or are they both as good?

Also the second link says to run a defrag in the guest OS. I have SSDs but, by default, VirtualBox mounts the VDI as an HDD in the guest. Is it OK to run defrag? I imagine running defrag inside the guest OS would just rearrange the data in the VDI file?

EDIT: Now my VM has been stuck in "Guru Medication" since I tried to open it
Attachments
VirtualBox Guru Meditation after -compacting VDI
VirtualBox Guru Meditation after -compacting VDI
VBox_Guru_Meditation__Screen Shot 2021-08-15 at 6.14.21 PM.png (75.9 KiB) Viewed 2566 times
viewtopic.php?t=8208
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: [Guru Meditation] Shrink Dynamically Allocated VDI Image

Post by scottgus1 »

We can't speak to the veracity or reliability of third-party tutorials.

The manual, https://www.virtualbox.org/manual/ch08. ... difymedium, see the '--compact' section, lays out a procedure for zeroing the unneeded sectors with an in-the-VM-OS program, then running the command:

VBoxManage modifymedium "drive\path\to\diskfile.vdi" --compact

Another option, for OS's that can run a Windows program natively or through Wine, is Mpack's CloneVDI.

Either method only produces .vdi output, and the vboxmanage command can only accept .vdi as input. Compacting through vboxmanage probably won't work on fixed-size disks, only dynamic disks. Vboxmanage edits the original disk file, I believe, so a backup is wise. CloneVDI always makes a clone of the disk file with option to keep the old UUID so the clone can be a drop-in replacement while the original remains unchanged. I always use CloneVDI.

Re the guru meditation, please try to run the VM again, then zip and post an unobfuscated vbox.log, using the forum's Upload Attachment tab.
Post Reply