Compacting Medium VDI

Discussions related to using VirtualBox on Linux hosts.
Post Reply
loopyludo
Posts: 6
Joined: 16. Sep 2016, 11:11

Compacting Medium VDI

Post by loopyludo »

Hi,

I have a Windows guest Win 7 x64 in a VDI, it has gotten to a size that I would like to compact it as my linux host Ubuntu 16.04 LTS only has a small SSD.
I have removed any large files in the guest, defragged and ran sdelete. However when I try to compact the VDI I get the following error.0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Failed to compact medium
VBoxManage: error: Code VBOX_E_FILE_ERROR (0x80BB0004) - File not accessible or erroneous file contents (extended info not available)
VBoxManage: error: Context: "RTEXITCODE handleModifyMedium(HandlerArg*)" at line 692 of file VBoxManageDisk.cpp

The command I am running is vboxmanage modifymedium OD.VDI --compact

Please can anyone give me some advice.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting Medium VDI

Post by mpack »

That looks like a host error related to the file. Nothing to do with compaction per se.

I also don't recognize the error wording. Please be aware that we do not support forked versions of VirtualBox here. Someone who forks the project has responsibility to do their own support.
loopyludo
Posts: 6
Joined: 16. Sep 2016, 11:11

Re: Compacting Medium VDI

Post by loopyludo »

Hi mpack, many thanks for the reply, I am using the version of VirtualBox that I downloaded from the official site (Version 5.1.4 r110228 (Qt5.5.1)) I have since upgrade to the latest version (Version 5.1.6 r110634 (Qt5.5.1))

I am able to start the VM with no issues at all, I can also mount the VDI in Ubunu and access the file system. The disk image was previously a VHD which I converted to VDI using vboxmanage, I was getting the same error trying to compact the VHD I just assumed it was because it was a VHD and not VDI.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Compacting Medium VDI

Post by Perryg »

File not accessible
Means that the file can not be found.
vboxmanage modifymedium OD.VDI --compact
vboxmanage modifymedium <absolute path>OD.VDI --compact

Unless you are in the folder that has the *.VDI file you need to give the absolute path to and include the file and extension.
loopyludo
Posts: 6
Joined: 16. Sep 2016, 11:11

Re: Compacting Medium VDI

Post by loopyludo »

Thanks Perry, yes I was in the directory I have also tried with the absolute path, in addition I have tried with the specific UUID of the image in question. I have just realised though that the storage format still say VHD.

UUID: 4bca9107-814e-4387-8802-353b1da81c0c
Parent UUID: base
State: created
Type: normal (base)
Location: /home/loopyludo/VHD/OD.VDI
Storage format: VHD
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting Medium VDI

Post by mpack »

Well, that might explain the "erroneous contents", though I thought VirtualBox ignored the extension and worked out the format in other ways. You should rename the file so that the extension correctly identifies the format.

Before you can do that you would need to unregister it from the VM - and hopefully you have not used snapshots, as that would make the entire discussion moot.
loopyludo
Posts: 6
Joined: 16. Sep 2016, 11:11

Re: Compacting Medium VDI

Post by loopyludo »

Thanks mpack, I have just tried that, I made sure that the image was no longer listed, renamed the file to .VHD and attempted to compact, unfortunately I am getting the same error. Why would vboxmanage allow me to perform other operations on the image without any issues.
loopyludo@OD-HP146012:~/VHD$ VBoxManage showmediuminfo /home/loopyludo/VHD/OD.VHD
UUID: 4bca9107-814e-4387-8802-353b1da81c0c
Parent UUID: base
State: created
Type: normal (base)
Location: /home/loopyludo/VHD/OD.VHD
Storage format: VHD
Format variant: dynamic default
Capacity: 122104 MBytes
Size on disk: 65754 MBytes

Thanks for your patience and efforts
Martin
Volunteer
Posts: 2561
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: Compacting Medium VDI

Post by Martin »

VHD compaction is not supported. You need to convert it to VDI first (correctly ;)).
loopyludo
Posts: 6
Joined: 16. Sep 2016, 11:11

Re: Compacting Medium VDI

Post by loopyludo »

Hi Martin,

Ok thanks, I thought it was, how should I convert to VDI correctly this time.

Last time I used vboxmanage clonemedium OD.VHD OD.VDI
Martin
Volunteer
Posts: 2561
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: Compacting Medium VDI

Post by Martin »

You need to specify the target format with the "--format VDI" parameter for the clonemedium command.

VBoxManage clonemedium [disk|dvd|floppy] <uuid|inputfile> <uuid|outputfile>

[--format VDI|VMDK|VHD|RAW|<other>]
[--variant Standard,Fixed,Split2G,Stream,ESX]
[--existing]
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting Medium VDI

Post by mpack »

Just a tip: if you already ran sdelete (in the guest) then cloning to VDI will do the same as compact, so there's no need for a further compaction step.
loopyludo
Posts: 6
Joined: 16. Sep 2016, 11:11

Re: Compacting Medium VDI

Post by loopyludo »

Many thanks indeed for all your help, I could have sworn that I had used the --format option, I obviously didn't as I have just done it again and this time I have a VDI that is a much smaller size, no need to compact.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting Medium VDI

Post by mpack »

Thanks for reporting back.
Post Reply