[Solved] Compacting VDI disks

Discussions about using Linux guests in VirtualBox.
Post Reply
martyg
Posts: 3
Joined: 25. Aug 2015, 21:34

[Solved] Compacting VDI disks

Post by martyg »

There are a lot of examples describing how to shrink a VBox disk. I've had good success - until recently. The root volume in my Oracle Linux 6.6 guest is 13GB (ext4). However, the actual file size for that volume is over 19GB - and I can't seem to make it any smaller. Here's what I've tried (and I've used both dd and zerofree):

Inside the OL6 guest:

Ran zerofill w/DD and deleted the generated file:

$ sudo dd if=/dev/zero of=/zerofile bs=1M;sudo rm /zerofile
dd: writing `/zerofile': No space left on device11722+0 records in11721+0 records out12291149824 bytes (12 GB) copied, 23.4805 s, 523 MB/s

Reviewed disk use in the guest- 13GB used:

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_bigdatalite-lv_root 25G 13G 11G 56% /

Host OS - review size of disk, compact:

-rw------- 1 mgubar g900 19240321024 Aug 25 11:44 BDL42_BDD11-disk1.vdi

$ vboxmanage modifyhd -compact BDL42_BDD11-disk1.vdi 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

$ ls -ltr
-rw------- 1 mgubar g900 19221446656 Aug 25 11:55 BDL42_BDD11-disk1.vdi

Why won't it reduce the file size by another 6GB?

Thanks for your help!
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 VDI disks

Post by mpack »

A common reason for not being able to compact the drive is that the methods you are using - i.e. zerofree, can only access one filesystem. If the drive contains unmounted partitions, swap partitions, or unpartitioned areas, then zerofree can't touch them.

It doesn't help that the methods you use are crusty with age. Have you tried using CloneVDI? (I note that you have posted in "Linux Guests" and don't mention what your host is).
martyg
Posts: 3
Joined: 25. Aug 2015, 21:34

Re: Compacting VDI disks

Post by martyg »

Thanks for the reply mpack.

The host is running Oracle Linux 6.6. And, I did try CloneVDI (nice utility) - which didn't do much (shrunk by ~200MB)

The OL6.6 guest's disk looks like:
2 volumes:
542MB ext4 mounted at /boot.
32GB LVM2 physical volume.

There are no other partitions.
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 VDI disks

Post by mpack »

Well, in that case there must be real data that can't be discarded. My guess would be that you have a 4GB to 5GB swap partition. I'm not a Linux expert, but AFAIK the swap partition size is usually some multiple of the RAM size, not a fraction of the disk size, which may mean that it's larger than you assume. Plus of course it can't be cleaned by zerofree. And CloneVDI doesn't look in there either - it doesn't contain a supported filesystem.
martyg
Posts: 3
Joined: 25. Aug 2015, 21:34

Re: Compacting VDI disks

Post by martyg »

You were right about swap! And, I found this post that was really helpful. It describes how to compact disks when LVMs are used:

http://www.fidian.com/programming/shrin ... isk-images

Thanks for your insights!
Post Reply