Sunday, July 8, 2018

How to Recover Hard Drive Space (Disk Cleanup, CCleaner)

Computer hard drives, by nature, gather garbage simply through normal, everyday use. I refer to this as "digital detritus". Computers tend to slow down as the garbage accumulates because there’s more data to sift through before the computer finds what it’s looking for. That’s why it’s important to clean your computer on a regular basis.

Recovering HDD Space on Your Computer

One of the simplest ways to start cutting down on the garbage that accumulates on your computer is to configure your web browser to automatically clear the history when you close it. I addressed how to do this in Internet Explorer 11 in a recent article, (See “Installing and Configuring Windows 10”, 20 May 18). You can also configure Firefox to do this; however, clearing your browsing history in Chrome is a manual process. Here are a couple of articles from Firefox and Google on how to do that:
Windows has a built-in tool called “Disk Cleanup” that I’ll talk about later; however, in my opinion, CCleaner is one of the better and easier applications for cleaning the garbage from your computer and it can be used on a regular basis. I’ve addressed CCleaner from Piriform in numerous articles, but never really in-depth. CCleaner does pretty well on its own, but I also run an add-on called CCEnhancer from SingularLabs to add more options to CCleaner.

Installing and using CCleaner is the same on all current Windows versions, so I’m using THOR, my Win7 Pro SP1 (x64) VM as a test mule. I downloaded CCleaner v5.44 from the home page. I opened Windows Explorer / File Manager and navigated to the folder where I stored it (C:\TEMP). I right-clicked on the executable file and then clicked on “Run as administrator”. I confirmed my choice with User Account Control and the installation began. Be sure to pay attention for the check boxes for the additional software – I unchecked the option to install Google Chrome and make it my default browser. After the installation completes, you can click on “Run CCleaner” to launch the app. You can see some of the cleanup options here:




I go through and check just about everything related to any web browsers that I have installed, like IE, Firefox, Chrome, etc. Piriform has a CCleaner Product Help Articles page that explains these options.

One of the nice features with CCleaner is the ability to search for and repair registry errors without the risk of us having to dig into the registry itself. After scanning for issues, you can have CCleaner repair them. You may have to scan / repair several times the first time that you run it. It may not be wise on my part, but I don’t bother to save a backup of the registry when I run the repairs. I’ve never had an issue with CCleaner messing up the registry, so I don’t worry too much about a backup.



The Tools tab allows you to cleanly uninstall programs and apps from your computer. A lot of programs contain an organic uninstaller, but they don’t always cleanly remove the program. CCleaner runs that uninstaller, but uses its own tools to complete the process. I have rarely run into issues where CCleaner did not fully remove a program.


I mentioned CCEnhancer from SingularLabs earlier. I install it to provide more cleanup options for CCleaner. I downloaded and installed CCEnhancer v4.5.2 the same as CCleaner. With CCEnhancer v4.5.2, you need to choose your language and accept the license agreement. Part of the install process, when you launch CCEnhancer, is to download the latest definitions. You’ll be prompted to launch CCleaner after the installation completes. You can see the additional options in these screen captures:




Exercise caution when selecting what to delete because it could cause issues. For example, if you delete the installers for a give program, you might run into issues uninstalling it further down the road.

Recovering HDD Space from Bloated VMs

With all the downloads and installations on my VMs in the last few articles, there was a noticeable increase in hard disk space utilization on the VMs, which translates to hard disk usage on my laptop. One way to take care of that is to move the VMs to an external HDD like I did a couple of weeks ago. (See “Working with Virtual Machines (Oracle VM VirtualBox)”, dated 17 Jun 18.)

Another way to recover HDD space when running Oracle VM VirtualBox is to compact the VM’s virtual HDD. The How-To Geek site has a good article on this topic (see below), so I’m not going to re-hash the topic in great detail or plagiarize their work, but instead, I’m going to follow their process and provide additional information as I go. According to the How-To Geek article, compacting your VDIs is a 5-step process, with an optional 6th step:

  • Step One: Ensure You’re Using a Dynamic Disk
  • Step Two: Write Zeros to the Disk in The Virtual Machine
  • Step Three: Find the VBoxManage Command
  • Step Four: Locate the Path to the Disk You Want To Compact
  • Step Five: Compact the Disk
  • Step Six: Consider Deleting Snapshots (optional)
Note: Make sure that all pending updates have been installed and that your computer has been rebooted a couple of times before starting this process or else you’ll have to do it all over again.

Step One: Ensure You’re Using a Dynamic Disk

I created all of my Oracle VM VirtualBox VMs with dynamic disks. When you create a VM with a fixed disk size, the virtual HDD will always be at least that size from day one. If you allocate 64 GB, that drive will be 64 GB even without an OS installed. Creating a VM with dynamic disks allow them to remain at the smallest size possible and grow as the VM grows. If you create a new VM with a 64 GB dynamic virtual HDD, it may only be a couple of megabytes to start. When you install the OS, it may grow to 25 GB or 30 GB. It will continue to grow as you install additional updates and software over time. You can manually add space to both fixed-size and dynamic drives to increase their size further.

One of the problems with VMs and storage allocation is that the virtual HDDs don’t automatically shrink to the minimum size necessary. Each time you download and install software, or even updates, to your VM, it uses HDD storage space, which causes the virtual HDD to grow. When the software or update installers are later removed, it frees HDD space within the VM, but the virtual HDD does not shrink.

Take, for example, my Win7 Pro SP1 (x64) VM (THOR). According to Windows Explorer / File Manager within the VM, the C: drive is 64 GB. But looking at the Windows Explorer / File Manager on my laptop, the VDI (virtual HDD) is only 27.3 GB. The kicker is that THOR is really only using about 23 GB of HDD space. That 4.3 GB variance was caused when the VDI grew to accommodate downloaded Windows Updates for which the installation files were later automatically deleted by Windows.




That 4.3 GB variance isn’t all that significant; however, LOKI, the Win8.1 VM, showed a HDD usage of 15.5 GB with a VDI of 46 GB. That’s nearly 30 GB of wasted drive space on the host. This process shows how to clean and compact your dynamic VDI files to recover that wasted HDD space on your host. I included two tables at the bottom that shows the start usage and end usage.

Step Two: Write Zeros to the Disk in The Virtual Machine

The How-To Geek article explains how to use the native Windows applications to clean and defragment a HDD. The same process works for VMs. I read elsewhere that you can use 3rd party programs like CCleaner from Piriform to clean the HDD, but that you should use Window’s native defrag tool rather than a 3rd party program like Defraggler, also from Piriform.

To keep the process simple, I used the Windows apps. Disk Cleanup cleaned about 1.5 GB of digital detritus from the VM’s HDD. It only took about 5 minutes on the Win7 VM, but it took significantly longer to remove far more from the Win8.1 VM.

I then ran Window’s Disk Defragmenter, which took close to 30 minutes. HDDs become fragmented through normal operations. HDDs read and write data thousands of time per minute. Part of the read-write process is also deleting defunct or otherwise obsolete files. HDDs will normally write data in the first available block of space. If the entire file doesn’t fit, it will continue in the next available block. This will repeat until the entire file is written. As files are deleted or moved, blocks are left vacant. This is called fragmentation.

Defragmenting your HDD will normally speed it up some. Data will be shifted to allow vacant blocks to be filled and files will be stored contiguously on the HDD. This way, when Windows tries to open that Word document containing your latest resume, it doesn’t have to hunt all over for bits and bytes scatter all over. This is called defragmentation.

Finally, I ran SDelete as advised. SDelete is a tool from Microsoft that securely deletes “deleted” files from your HDD. When you delete a file in Windows, it doesn’t actually get deleted from the HDD. Windows marks it as deleted and changes the file name to make it invisible, but the file and data remain until they’re overwritten by new data. This is why SDelete overwrites all of the HDD free space with zeroes. By overwriting the free space with zeroes, all the “deleted” files are overwritten and actually deleted. Once overwritten, the data is unrecoverable by most digital forensics file recovery tools. It took about 15 minutes to run on the 64 GB virtual HDD.

I performed all three of these steps on each VM before moving on since the remaining steps are done from outside the VM using my laptop’s Command Line Interface (CLI).

Of note, CCleaner also offers the option to perform secure delete under Options > Settings, so I opted to use this process on my Win10 VM rather than using Windows Disk Cleaner.

Step Three: Find the VBoxManage Command

This was easy. I opened Windows Explorer and navigated to the folded where Oracle VM VirtualBox is installed: C:\Program Files\Oracle\VirtualBox. Once I found VBoxManage.exe, I launched a Command Line Interface (CLI) and navigated to that same directory.

Step Four: Locate the Path to the Disk You Want To Compact

I ran the following command in the CLI. It listed all four virtual HDDs for all four of my VMs.

VBoxManage.exe list hdds

The list displayed the name, location, and size of all Oracle VM VirtualBox virtual HDDs on your computer.

Step Five: Compact the Disk

I then ran the following command to compact each HDD:

VBoxManage.exe modifymedium disk "[path\filename]" –compact

(Replace [path\filename] with the path and filename for your VDI.)

This process takes a while, so now might be a good time to get a cup of coffee or play a game of Windows Solitaire.

By the time the three VDIs had been compressed, I recovered over 62 GB of space on my 320 GB external HDD. Imagine if that was space that was being wasted on your internal HDD of your host computer.







Before
After
Difference

OS
HDD Size
HDD Used
VDI Size
HDD Used
VDI Size
HDD Used
VDI Size
THOR
Win7 Pro SP1 (x64)
64 GB
23.0 GB
27.3 GB
20.3 GB
20.8 GB
2.7 GB
6.5 GB
LOKI
Win8.1 Pro (x64)
64 GB
15.5 GB
46.0 GB
12.3 GB
12.5 GB
3.2 GB
33.5 GB
TYR
Win10 Pro (x64)
64 GB
15.3 GB
34.6 GB
13.0 GB
13.4 GB
2.3 GB
21.2 GB


Ext. HDD Size
320 GB
VM usage before
108.0 GB
VM usage after
46.8 GB
Difference
61.2 GB

Step Six: Consider Deleting Snapshots (Optional)

A snapshot is a saved copy of a VM at a certain point in time. Most SysAdmins take a snapshot of their VMs prior to making any changes to it, sometimes even for something as simple as running Windows Updates. If something goes wrong with the updates or whatever, the snapshot can be used to return the VM to the state it was in prior to the issues. After the changes have been made, and a reasonable amount of time has passed without any issues, the snapshot(s) will normally be deleted. Some SysAdmins take periodic snapshots “just in case” so that they can revert a damaged VM rather than having to rebuild it from scratch. This can also prevent loss of data. Snapshots take up HDD space on the host comparable to that of the running VM. Retaining multiple snapshots is unnecessary and eats storage space, though. So, it’s a good idea to consider deleting any unnecessary snapshots.

Here’s my list of sources for this article:

Just a final note: when I reference a tool, application, or another web page, I like to hyperlink it each time I reference it just to be sure that credit is given where it's due.

As always, I'm open to questions and constructive comments. Your feedback is welcome.

No comments:

Post a Comment