Compacting Guest OS

Discussions about using Windows guests in VirtualBox.
Post Reply
ttellahzab
Posts: 16
Joined: 26. Jul 2013, 13:06

Compacting Guest OS

Post by ttellahzab »

Hello all,

Can anyone advise if it is possible to compact guest vdi/vhd files that also include snapshots without merging snapshots into one disk?

Regards,
Barry
ttellahzab
Posts: 16
Joined: 26. Jul 2013, 13:06

Re: Compacting Guest OS

Post by ttellahzab »

Can anyone help?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting Guest OS

Post by mpack »

No, there is no useful way to manage storage requirements if you use snapshots. Compaction will do nothing useful.
ttellahzab
Posts: 16
Joined: 26. Jul 2013, 13:06

Re: Compacting Guest OS

Post by ttellahzab »

Hello mpack,

Thank you for your response.

It is a shame that snapshots are not handled but can understand the complexity of such a requirement.

Snapshots allow for a more organised installation structure meaning one can go back to any one state which is very useful. If at any time in the future compaction of snapshots such as this can be handled then that would be great.

Regards,
Barry
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting Guest OS

Post by mpack »

Actually complexity isn't really the issue, usefulness is. A snapshot is, by definition, just the most recently changable parts of the disk. If you "compact" a heavily changeable difference disk then (a) it probably won't change very much, and (b) will mostly all be added back very quickly anyway, for the same reason they were added the first time.

Basically, if you care about disk space then you shouldn't be using snapshots (or other difference schemes), since they waste a great deal of it. The ability to instantly revert to N past states has a cost attached. Personally I prefer to use simple backups. That means I give up the "instantly revert" part, but I can still restore past states, in fact I can do it more surely than if I used snapshots - but most importantly the backups don't need to be on the same disk as the current state. And, things like "Compact" do something useful.
Virtual Boxxy
Posts: 15
Joined: 13. Mar 2016, 15:05

Re: Compacting Guest OS

Post by Virtual Boxxy »

I have tried an old program submitted by a user on these forums called VICompactor. It is an open source Java program, and from what I've been able to tell, it does what you want. VICompactor works directly on the guest NTFS file system, so as long as you really delete files (not recycle bin) on the guest before saving the snapshot, VICompactor will compact that space without having to bother with sdelete.exe etc.

Some of the snapshot data, however, is RAM data (the .SAV savestate files), and I believe VICompactor only compacts NTFS data in VDI files (and possibly Linux Ext3 data). Still, my VDI snapshot files shrunk significantly.
However, you can effectively use disk compression on the SAV files since they will be loaded into RAM every time you start the snapshot.

Edit: this (disk-compressing .SAV files was good) is not true and probably has not been for a long time; VirtualBox already compresses the .SAV files, at least on dynamic images. You can of course use disk compression on the .VDI snapshot files on the host, it often has a huge effect, often cutting windows machines in half, or even less.

What I have been doing lately, apart from using VICompactor, is to make a separate minimal virtual hard drive for the swap partition and then zeroing the pagefile on (guest) Windows exit (it is a policy setting to do it automatically). The swap partition is obviously the part of the disk that changes the most. With this method, the swap partition .VDI for every snapshot will only take ~2MB on the host. For those who want to say to disable the guest pagefile completely, that is often a good idea, but doesn't work well in some situations like when running a lot of virtual machines simultaneously.

This only works for offline snapshots, obviously, and a drawback is slower boot and shutdown. If you have a lot of virtual machines with a lot of snapshots it can be an enormous space saver though.

And VICompactor is great.
joelt-gal
Posts: 2
Joined: 5. Dec 2022, 11:46

Re: Compacting Guest OS

Post by joelt-gal »

I was thinking of a solution for saving drive space because of the pagefile in Windows systems. I made a similar trick for using separate virtual disk for the page file, because 4GB on the system is a big waste in the system drive when i want to install a program and that space is only for missing. Other way of using this method is for reduce the amount of the backup file size. I release the pagefile-disk from the guest os and than I make the backup (exporting).

I think computer can do the same if a special type of virtualdisk would be. It would work normally when the guest is running, and after it can lost all the information in it and shrink to the minimal size as it was mentioned before (with a windows policy). I'm not goot for making that zeroing at windwos(guest) exit. I would like this solution also If I know how should I do it. Can you write some details about it?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Compacting Guest OS

Post by mpack »

Speaking personally: back in the day that might have been worthwhile, but AFAIK modern 64bit PCs tend to have plenty of RAM and do little swapping. Also the swap file is typically only a few GB which is often a tiny fraction of total disk space used. A final nail in the coffin is that this discussion of page files applies only to Windows guests, each guest OS would require its own solution. A lot of work for something that isn't really that big of a deal anymore.
joelt-gal
Posts: 2
Joined: 5. Dec 2022, 11:46

Re: Compacting Guest OS

Post by joelt-gal »

Tell the truth I wrote too fast. I found a solution in windows 7. In the windows registry there is an option for cleaning the pagefile at the shutdown, and that is what I am thinking on. So there are no any coplicated steps. The question is not question at this moment. Thanks for the reply!
Post Reply