virtualbox takes up a lot of space

Discussions related to using VirtualBox on Windows hosts.
Post Reply
leobosack
Posts: 1
Joined: 3. Dec 2021, 09:37

virtualbox takes up a lot of space

Post by leobosack »

virtualbox 6.1.26
the space inside the virtual machine is occupied by only 6.5 GB along with the swap file, but the vbox hard disk image.vdi takes up 19 gb of space on a real machine, is that how it should be? when installing a virtual machine, a dynamic hard disk of 20 GB was selected
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: virtualbox takes up a lot of space

Post by mpack »

Space occupied on the host depends on how many sectors contain data - i.e. how many have ever been written to by the guest OS. Nothing else. For example, it has nothing to do with how much data in files is currently reported by the guest filesystem. Compacting a drive can reduce the VDI host size again, but that would be pointless if the current size is the natural size it wants to be, i.e. it would just puff back out again.

Also, people often neglect to look at other partitions on the same virtual drive. E.g. if it's a Linux drive then it will often contain a swap partition (not a swap file), and that partition will have a size related to how much RAM you gave the VM. That partition doesn't contain any files at all, but it will be full of data.
arQon
Posts: 228
Joined: 1. Jan 2017, 09:16
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Ubuntu 16.04 x64, W7

Re: virtualbox takes up a lot of space

Post by arQon »

@OP: In case that was a little more involved than you were ready for, the short answer to

> is that how it should be?

is "realistically, yes".

As mpack says, you can TRY to reduce it periodically, but you'll just be wasting time (and SSD wear, if that applies), and it'll end up back there very quickly. As he also points out though, if you've got an 8GB swap partition etc in there too, compacting it will be an even more futile exercise than it already is otherwise.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: virtualbox takes up a lot of space

Post by mpack »

IME the only time compaction is warranted is (a) immediately before shrinking or deleting a partition, (b) after some kind of "oops" that puffed the VDI to max (picked at creation) size, for example - doing a low level disk check (which you should never do, as physical damage needs to be fixed on the host).

Otherwise you just have to be aware that VMs need lots of disk space, and plan accordingly. There are some things you can definitely do to minimize the hoggage, for example by avoiding all use of snapshots. If you created a 40GB drive and then add 10 snapshots then that theoretically could add up to 440GB disk space used, all of which has to be kept online. Without snapshots the same theoretical max is 40GB.
Post Reply