This is part two of my journey into managing my laptop’s disk resources. Part one, was about moving my working environment to a new disk with minimum of fuss [You can read that post here:How to turn a physical disk into a bootable VHD”].

Disk management is one of those things that is never on interest until it’s really too late – when you are running low on space on your computer. With a bit of planning you can figure out a way to make best use of existing hardware or buy some more, but there is always something you never think of which makes you want to tinker more. I upgraded a 160GB hard drive for a superb 500GB Seagate Momentus XT Solid State Hybrid Drive to help alleviate my disk space woes and on discovering the excellent level of support that Windows 7 provides for virtual hard disks (VHDs), it made good sense to use this to minimise the downtime of moving disks.

Running low on space (again) So despite increasing my disk storage, moving to a system of running and backing up to VHDs I’m still desperately low of space on my Windows 7 system partition. I guess that when I finished juggling all my disks and files about, I naturally thought “job done” and that I would not have to revisit this particular issue for a while later. Windows of course, knew the real truth and decided to remind me how dangerously close to the edge I was getting by continuously popping up “low disk space” notifications.

Only 59MB free after Disk CleanupNot only do my running applications continuously compete for resources but it’s even pervading where application data is stored – for example; I recently wrote about trying to work around where Windows Phone 7 backups are stored, because my system drive could not cope. I could only manage a week of constantly running the  “Disk Cleanup” tool and scanning my system drive for any obvious candidates of deletion, but it’s pretty dire when despite these efforts you only end up with 59MB! Clearly, I need another strategy.

Now, all this turmoil is occurring on the system partition of the bootable VHD that I created in my previous post [You can read that post here:How to turn a physical disk into a bootable VHD”]. The techniques I’m about to show you has origins with physical disks too, however having baked my own VHD file it’s more relevant to VHD management.

When Windows 7 is running from a bootable VHD it has mounted the guts of a disk image file that is sitting on a physical partition on the machine. My VHD is big enough at 156GB and it holds two virtual partitions (one is the system, the other data). Normally, it’s just a case of resizing partitions, but how does that work with VHDs? Thankfully Windows 7 does not treat VHDs any differently to physical disks and therefore this can be managed using the inbuilt disk management tools.

So, from the “Start” taskbar, search for “Disk Management” or “Create and format hard disk partitions”. This will pull up the following control panel with details of your current system. Be careful with any of these options!

Disk Management view of the VHD

Partition Options in Disk ManagementSo, with my booted system partition languishing with only 169MB, I thought that I could shrink the larger DATA partition and reallocate this to the WIN7 partition. Shrinking can be performed on any partition, basically so long as it has some free space (there are a couple more rules but the computer checks these for you later).

The Disk Management console is pretty neat, in that if any of the options are not available, it will just disable the context menu options. Here, “Shrink Volume” is available on the DATA partition of my VHD, thus by clicking it, the console will spend a number of minutes analysing the partition.

Shrinking options on my VHD partitionThe pre-shrink checker reported to me that my drive is sufficiently bare to reduce my partition by 29GB. Note that this can depend upon where your data is stored on the disk itself, that is, shrinking considers data in roughly one contiguous group, so if there are system files scattered throughout your partition, this reduces the potential for the shrink operation hence why it’s not recommending all 34GB of free space.

I just want to free up some space, not all, so I’m liberating 12GB from my DATA partition that I’ll use on my system partition. Kicking off the shrink process involved leaving he laptop uninterrupted for 3 hours, best let it do it’s shrinking business alone.

On re-examining the Disk Management console, I’ve now got a 11.72GB unallocated partition on my VHD. It’s at this point I’ve realised a fundamental flaw in my plan. Although I’ve released this space, my VHD represents one piece of disk media and the unallocated space is in the wrong position! Quite simply, when you have split partitions on a physical disk they sit back-to-back and the same applies to virtual hard disks (VHDs) too. The console view demonstrates this very simply that my system partition (WIN7) can’t be extended because the DATA partition is in the way (shown by the red arrow stopping abruptly whereas the green arrow can reach across). This is why the “Extend Volume” option is only available to my DATA partition and not my WIN7 partition.

Post shrink - created unallocated space

With good intentions, this has not really helped solve anything though, except trim some dead space off my partition but the VHD remains unchanged as a whole. Remember that a VHD is a virtual representation of a physical hard disk; it still takes up disk space on the physical medium, albeit as one massive file rather than natively scattered over the drive. My VHD has not decreased in size unless I actually want to trim it, from which I have a couple of options…

Normally I’ll use GParted Live to manage my native disks/partitions since this boots from CD and because it is not running the native OS directly, it can shift and reorder any files that it sees fit (well, within reason!). I would thoroughly recommend GParted Live as it’s never let me down (famous last words) but I don’t think that I’m able to do the same here though because GParted Live uses a Linux Live Kernel which does not know how to mount VHDs as a live partition (wail).

Unsurprisingly, there is a tool called VHD Resizer, which is despite it’s age has established itself as a simple but robust tool to change a VHD file. There is the option to resize the VHD or change it’s type to/from fixed or dynamic sizing. It performs a sector by sector copy operation from one VHD to a new VHD and although I have not used this tool in this instance, it would appear to release or grow the tail end of the VHD – best in this case to resize my VHD just a bit bigger than 40.05GB + 103.44GB so that most of the unallocated space is chopped off. The one disadvantage of VHD Resizer is that it cannot be run from a Windows instance that is running – I would have to log onto my native Windows installation and run VHD Resizer against the inactive VHD file.

The last option I considered and for which I am the most gutted about since it does not work would be to do what I did before when creating the VHD in the first place and use the Disk2VHD tool! Hoping that Disk2VHD could reliably clone the selected partitions to separate and expanded VHDs, the clue was in the name, it’s not VHD2VHD. Unfortunately, the tool detects only native drives and converts those into new VHDs rather being duped into thinking that the host VHD is a native drive.

[You can read more about how I originally used Disk2VHD in the post here:How to turn a physical disk into a bootable VHD”].

Time for a rethink of how I’m going to get more space for my system partition – which is the real threat for grinding to a complete halt. I have a couple of ideas and I’ll report back once I’ve seen if they’ll do the job. At least you’ve seen how easy it is to shrink or expand those VHD partitions using the inbuilt Disk Management tool.

This is a cross post from my EMC blog, mainly for backup duplicity and to aggregate some of my past postings. My EMC blog used to be under the Conchango brand but was acquired by EMC so I’ve also retrospectively refreshed some of the old links and maybe a tweak a bit of content too.
permalink to the original post here