Exporting VM with small disk usage creates huge OVA file

This is for discussing general topics about how to use VirtualBox.
Post Reply
Dmoss
Posts: 3
Joined: 16. Mar 2021, 22:43

Exporting VM with small disk usage creates huge OVA file

Post by Dmoss »

Hi,
Running VirtualBox 6.1.16 with Ubuntu Studio host and Ubuntu Server guest.
My old guest containing several projects (53 GB disk usage on / ext4 partition) have been cleaned to get only one useful project (23 GB disk usage).
Then, I shut down my VM, and export it. Created OVA file is 80 GB ! :oops:

So my question is: how can I manage to export my VM without huge unused ext4 disk space exported ?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Exporting VM with small disk usage creates huge OVA file

Post by scottgus1 »

Dmoss wrote:My old guest containing several projects (53 GB disk usage on / ext4 partition) have been cleaned to get only one useful project (23 GB disk usage).
You may have 23GB in the VM but the disk file can be bigger. How big is the VM's disk file on the host drive?
Dmoss
Posts: 3
Joined: 16. Mar 2021, 22:43

Re: Exporting VM with small disk usage creates huge OVA file

Post by Dmoss »

scottgus1 wrote:You may have 23GB in the VM but the disk file can be bigger. How big is the VM's disk file on the host drive?
Yes, the disk files are bigger, but containing useless data for VM:

Code: Select all

-rw------- 1 dmoss dmoss   14G avril 26  2020 2020_04_26_WebODM-disk001.vdi
-rw------- 1 dmoss dmoss  118G mars  15 06:58 Snapshots/{2a19a488-a299-47ee-b9f2-51f7edb39c7b}.vdi
-rw------- 1 dmoss dmoss  4,1G mars  16 23:03 Snapshots/{dda7b4f1-a298-45a7-aab5-1c3cfef7bc0d}.vdi
When cloning a physical hard drive with CloneZilla (or another specialized SW), only allocated disk space is saved.
I understand VirtualBox is unable to get into filesystem and save only allocated blocks. It's a shame, but how to workaround ?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Exporting VM with small disk usage creates huge OVA file

Post by scottgus1 »

Dmoss wrote:My old guest containing several projects (53 GB disk usage on / ext4 partition) have been cleaned to get only one useful project (23 GB disk usage).
Dmoss wrote:-rw------- 1 dmoss dmoss  118G mars  15 06:58 Snapshots/{2a19a488-a299-47ee-b9f2-51f7edb39c7b}.vdi
-rw------- 1 dmoss dmoss  4,1G mars  16 23:03 Snapshots/{dda7b4f1-a298-45a7-aab5-1c3cfef7bc0d}.vdi
If the cleanup happened between the two quoted snapshots then the dead data may still be in the drive. I am not familiar with how a snapshotted VM handles dead data in an export, but I suspect the data is not known to be dead and is preserved.

You may want to clone the VM's disk with Mpack's CloneVDI, with the Compact option, then get a fresh VM using the clone, then export that.
Dmoss
Posts: 3
Joined: 16. Mar 2021, 22:43

Re: Exporting VM with small disk usage creates huge OVA file

Post by Dmoss »

scottgus1 wrote:You may want to clone the VM's disk with Mpack's CloneVDI, with the Compact option, then get a fresh VM using the clone, then export that.
Thanks, I didn't know about it. I'll try it later (with Wine).

At the moment, I'm following another way:
1/ create a new virtual disk and attach t it to my VM
2/ boot my VM on live CD
3/ clone old disk to new one (thanks to clonezilla)
4/ reboot my VM to new disk to check it's ok, poweroff and export
I'll give news... cloning in progress...
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Exporting VM with small disk usage creates huge OVA file

Post by scottgus1 »

That sounds like a good idea too. It's the same concept: clone the final state of the VM to another drive.
Post Reply