“Finally!”, I might add. I spent almost all day trying to get this to work.
Shrinking a disk partition is a Windows feature that allows you to specify a smaller size for an existing partition, while preserving all your data. In the end, you get “shrinkage” of the good kind, so that you can use the newly available space to install an auxiliary operating system.
Disk shrinking is a simple operation as far as a regular techie is concerned. You simply launch the Disk Management console (diskmgmt.msc) as Administrator, right-click on the partition you want to shrink, select shrink from the menu, specify a size, and off you go. Unfortunately, in some cases, this is not easy at all. So much so that you may need a ‘shrink’ after what you’ve just gone through. That pun was absolutely intended, by the way. And arguably much exaggerated.
I ran into this issue while trying to shrink the primary partition of my beloved Lenovo W510 laptop that came preloaded with Windows 7 and other software blessed by the IT department. When I attempted the shrink operation, Windows would give me only a maximum of 40-something megabytes to shrink when I had around 240 gigabytes of free space. WTH?
It’s a game of Treasure Hunt, that’s what this is. The shrink tool dialog has the first clue that there is a “defrag” event in the Application log. The included help link further reveals that the entry has an Event ID of 259.
At this point, some of you may have guessed that, to shrink a partition, the OS needs to gather around the data that’s roamed out to the further parts of the disk block and move them towards the beginning in an effort to provide the biggest consecutive unused block that can be freed. (This is called “defragmentation”). In addition, you may have guessed that the defragmentation is failing because there is some unmovable data towards the end, that’s throwing off the whole thing…
Well, you would be dead on!
Unfortunately, knowing what’s wrong is only half of knowing how to fix it – if not less.
So we go to the next place for our clue. We launch Event Viewer (eventvwr.msc), expand the Windows Logs node in the left pane, and select the Application node. Luckily for us, the defrag event is one of the recent events and appears towards the top of the list so it’s easy to locate. It appears as an informational entry:
If you love riddles, then I urge you to de-riddle me that!.. Nah, just read on…
Now is the time I consult the wisdom of the Internet to see if anyone else has found a fix. Before long, I’m navigating through helpful web sites, teeming with ads, to get to the next clue. One website suggests getting rid of pagefile.sys and hiberfil.sys. That makes total sense! What better files than these ones to be “unmovable” – surely not the funny cats PowerPoint you received through a colleague in your previous company. These two files are hidden system files that live in the root of your Windows drive and are notoriously impossible to get rid of through normal means. No amount of Administrator power will give you the “permissions” you need to do that: you must know the magic combination. That I reveal below:
To get rid of hiberfil.sys, you can try disabling hibernation through the Power Options Control Panel (powercfg.cpl) for your currently selected power plan. For me, this didn’t work, perhaps because the power plan on my machine is controlled by IT. Instead, launch a command line window as administrator, and issue the following command: powercfg –h off. This will turn off hibernation.
To get rid of pagefile.sys, right-click Computer in the Start Menu, and select Advanced system settings on the left, or simply take a shortcut by launching sysdm.cpl. Select the Advanced tab. Under Performance, select Settings. Next, select the Advanced tab. Under virtual memory, click the Change button. Uncheck Automatically manage paging file size for all drives. Make sure that the partition you’re trying to shrink has No paging file set. Do not forget to press the Set button before you press OK. This is because you must convince Windows that you really know what you’re doing. By the way, if you don’t know what disabling a page-file will do, you probably shouldn’t be doing it. Just don’t forget to re-enable it when all is said and done. This will require you to restart your OS by the way.
Now we can try the shrink again.
It may work for you, but it didn’t work for me. It’s time to go back to our second Treasure Hunt clue. Even though the name of the unmovable file was for all practical purposes gibberish, the directory name gives us our next clue. A little online sleuth work reveals that this location is used by Windows’ System Restore functionality. If we disable that, it may get rid of the offending files.
To disable System Restore, go back to the System Properties (sysdm.cpl), and select the System Protection tab. Click Turn off system protection and click OK. This will prompt you whether you want to delete your system restore points which you will desperately accept. If it errors out for you half way, don’t worry, you can always come back later and click the Delete button to get the job done the second time.
Now we can try the shrink again.
There’s hope! Now, Windows says there’s a whopping 4 GB available. Still not enough. Like Ahmet Ertegun tells Ray Charles: “If you think pennies, Mr. Charles, you get pennies. If you think dollars, you get dollars.”. We should be getting 240 GB!!
Now we know how to play the game. We will go back to the Event Viewer, look at the latest defrag event, figure out what to disable. Rinse & Repeat.
In my case, I had to:
- Uninstall Microsoft Forefront Client
- Disable & exit the Forefront application in the system tray
- Turn-off Windows Search feature (From Control Panel > Programs)
- Stop SMS Agent Host service (CcmExec) in Windows Task Manager’s Services tab
- Stop Cryptographic Service (CryptSvc)
And finally, success! Approx. 240 GB is mine for the taking.
I hope this was as much fun for you to read as it wasn’t for me to figure out.
IMPORTANT: If you have BitLocker enabled, you must retrieve your BitLocker recovery key before you reboot, or you may not be able to boot.
‘Till next time,
PS. You might think that booting Windows in Safe Mode would have avoided all this, but you would be wrong. Shrinking doesn’t work in Safe Mode.