Conserve Virtual Hard Disk Space in a Windows 7 Guest OS

📅 November 20, 2016
wasted_windows_space1When running Windows 7 as a guest OS (with VirtualBox, for example), here is an apparently obvious tip that can be easy to overlook or forget about: Disable hibernation and paging in Windows 7.

This will conserve the amount of virtual hard disk space used by Windows 7 and result in a more space-friendly .vdi image on your real hard drive — especially important if using a solid state drive or NVMe storage.

Using a free disk usage analyzing utility called WinDirStat, here is how a virtual Windows 7 installation utilizes about 210 GB of virtual hard drive space:

a

WinDirStat showing hard drive usage on this large virtual Windows 7 installation in VirtualBox. The two blue blocks represent the paging and hibernation files.

Look at pagefile.sys and hiberfil.sys. These are Windows system files that are consuming about 56 GB of hard drive space (pagefile.sys = 31.8 GB, hiberfil.sys = 23.9 GB). This space is wasted and not necessary.

hiberfil.sys is designed for system hibernation. It allows faster system resumption, but this is unneeded for a virtual installation. We can disable this.

pagefile.sys is the paging system for virtual memory. If Windows runs out of system RAM, it will swap pages in and out of a reserved system file located on the hard drive. This might or might not be necessary in a virtual guest depending upon your needs. For my use, this is not necessary, and it results in wasted space.

By default, the paging file is automatically assigned the same size as installed system RAM. Since this particular Windows 7 installation was assigned 32 GB of RAM, Windows said, “All Riiiiight! Let’s use a 32 GB paging file that will waste space and require the user to purchase a larger hard drive!”

Disable Hibernation

When you think about it, there really is no point in waking up a guest OS from hibernation. When using SSD or NVMe, hibernation becomes even more pointless in a virtual environment, so let’s disable the Windows 7 hibernation completely.

Open a Windows terminal (command line program called cmd) as an administrator, and enter,

poweroff -h off

Reboot the Windows 7 guest OS. The hibernation file hiberfil.sys will be deleted, and any space it consumed will be freed. Keep in mind that this will not reduce the size of a dynamically-sized virtual hard disk image. It only frees up the available virtual hard disk space that Windows sees.

You might also need to configure the power settings as well by disabling the Hibernate feature. This part can be installation-dependent, so if hiberfil.sys is not deleted or reappears following a reboot, this is something to check.

Reduce or Disable the Page File

Open the Windows 7 Virtual Memory settings dialog (Right-click My Computer > Properties > Advanced System Settings > Performance Settings > Advanced tab > Change).

a

Windows 7 Virtual Memory dialog allows you to adjust how much hard drive space to allot for the paging system.

You can disable paging completely by choosing “No paging file,” but if you run out of virtual RAM, Windows might crash. Here, I have allocated a fixed 4 GB for the paging file “just in case.” Choose the Custom size option and set the minimum and maximum sizes to the same value. Click Set and reboot the guest OS. Remember, these changes are made to the Windows 7 guest OS running inside VirtualBox, not the host system.

a

WinDirStat showing changes made. The hibernation file is gone and the paging file only consumes 4 G of virtual hard disk space.

What a difference! This is the same Windows 7 guest OS, but with more hard drive space freed for use. Before, C: required 203.8 GB of drive space, but after disabling hibernation and reducing the paging file to 4 GB, C: consumes 160.4 GB. This saved 47.4 GB of hard drive space that was doing nothing for the virtual system except waste space on a real hard drive by requiring a larger VDI image. Not exactly certain why this example only shows a 47 GB difference and not the 56 GB difference as expected.

Regardless, this is something worth noting in order to free up virtual hard drive space when running virtual Windows 7 guest systems.

 

,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: