Compacting a Linux Hyper-V, Virtual PC 2004 or 2007 Dynamic VHD/VHDX file

System Requirements:

  • Virtual PC 2004, SP1
  • Virtual PC 2007, SP1
  • Hyper-V

The Problem:

The Windows Integration components ISO contains a tool for performing a VHD pre-compact. Once completed, this tool allows you to shut down a VHD and compact it to reclaim disk space previously used by the VM which has actually marked as being free space by the VHD FAT/MFT.

More Info

As Linux operating systems do not formally include integration components for Virtual PC, there is no standard Microsoft way to pre-compact the VHD. The fundamental process behind pre-compaction is however simple: write 0’s all sectors of the hard drive that the FAT/MFT claim to be free (available) space.

Once you have done this, the Virtual PC/Hyper-V management UI will flush the contents of the VHD into a new VHD, skipping any 0’d sectors from the migration process, thus reducing the size of the VHD as seen by the hypervisors host partition.

The Fix

I’ve used two different methods to achieve Linux pre-compaction.

Note: This was written against the steps that need to be performed on Debian. Other distributions may require additional steps to install software.

Open Terminal and execute the following:

cd /
cat /dev/zero > zero.dat ; sync ; sleep 1 ; sync ; rm -f zero.dat

Although simpler and not requring any software installation, the compaction rate achieved using the method was a little hit and miss, often resulting in a large VHD file after the compaction process.

A higher success rate was achieved by installing a small app package called secure-delete. To install and use this issue the following commands from a shell.

apt-get install secure-delete
sfill -f -z /

While I have realised better results from this, the process takes far longer as the secure-delete packages sfill is in fact performing an “insecure” erase on the hard drive, not simple zeroing sectors. This means that it actually passes over the disk more than once, with the concluding pass being the zero pass. The cumulative effect of the multiple passes means that it takes far longer to complete. The last time that I ran with this method, a 16 GB Debian 6 VHD was reduced by 1.2 GB. Small change given the size of today’s hard drive, but a significant percentage of the 16GB disk none the less.

Please also note that there are other elements to the secure-delete package, including tools to wipe the SWAP partition (which may further reduce the size of the VHD if used) as well as tools to perform a full, secure disk erase (not just empty sector erasing). So do ensure that you use this package carefully.

Upgrading Windows Server 2012 to 2012 R2: Things to be mindful of

System Requirements:

  • Windows Server 2012
  • Windows Server 2012 R2

The Problem:

This article outlines a few tips to be mindful of when performing an in-place upgrade from Windows Server 2012 to Windows Server 2012 R2.

More Info

Without wishing to be verbose on this one, the simple answer is that there appears to be a bug / limitation / “feature” of the iSCSI Target component of Server 2012 during upgrade that will cause you some issues. It isn’t a client issue that you will encounter.

Operating System Features

The following core features will not be available after upgrading from 2012 to 2012 R2

  • Servermanagercmd.exe
  • Slmgr.vbs
  • System Image Backup
  • Windows Server Resource Manager


The network profiles for non-domain adapters will drop back to Public after the upgrade, altering the active firewall configuration.


After the upgrade install, the Windows Firewall will inherit most firewall configuration settings from the previous configuration, however the port configurations for the iSCSI Target services will be in a disabled state, preventing your iSCSI Initiators from connecting to the service.

The upgrade process will fully de-install your NIC’s, although in general most of the main configuration settings are retained and re-applied after the upgrade (IP, Net mask etc), the advanced adapter settings are not applied. In particular, and Jumbo Frame settings designed to support extended MTU’s on your SAN NIC’s will have been reset to the standard 1500 bytes. This will have a performance hit on SAN access and Hyper-V live migration performance. You should manually re-enable the Jumbo frame settings (9014 or 9000 bytes) but be aware that it will cause the NIC to drop and re-initialise when you hit apply.

Update 24/02/2015: It is worth noting that the 2012 (R1) iSCSI target file format uses the legacy VHD format while new iSCSI targets created under 2012 R2 defaults to VHDX which supports larger volumes and better error protection technologies. Perhaps most important is the fact that VHDX is required to support the use of 512e/4K hard drives i.e. non ‘legacy’ 512n hard drives. Here in 2015, if you buy a drive larger than 1TB, it will most likely be a 512e/4K drive. If you migrate from 2012 R1 to 2012 R2 or to a future Windows version onto 4K disks, you will likely see a slump in performance unless you take remedial action to deal with it during the migration. My recommendation is that while you are taking down your iSCSI services to perform the upgrade, perform a VHDX migration of the iSCSI Target LUN using an offline server and swap the VHD for the VHDX before you go back into production. If you don’t do it now, you will either have to do it sooner or later or forget completely and suffer data integrity and system performance issues at a later point in time.


A number of the SysInternals apps, for example BGInfo, that work fine under 2012 have small issues under 2012 R2. BGInfo has a recent update that makes it aware of 2012 R2 and IE 11 rather than reporting that the OS is Windows 6.2 running MSIE 9.0.11.

WSUS 3.0 SP3

Ensure that any legacy WSUS 3.0 servers are patched to SP2 with KB2828185 installed. After re-synchronising, changing the product configuration and synchronising a second time that you server can update from your existing WSUS infrastructure. Be prepared for any 2012 R2 Data Center servers to report in WSUS as Windows 2000 Data Centre however!

Removing the Windows.old uninstall cache without installing Desktop Experience

Unfortunately you can no longer copy/paste the two cleanmgr.exe files out of WinSxS like you used to be able to do with 2008 (the store is compressed). I found that a few loops of the following will eventually remove the Windows.old upgrade cache from the root of the OS drive.

:: This is very slow as it is disk intensive: run out of hours!!
takeown /F C:\windows.old /R /D Y
takeown /F c:\Windows.old\* /R /A /D Y
takeown /F C:\windows.old /R /D Y
takeown /F c:\Windows.old\* /R /A /D Y
cacls C:\windows.old /T /G Administrators:F
rd /s /q C:\windows.old

p.s. run each line manually, the above is not setup as a batch script and will ask for yes / no input. Several runs may be required.


Your desktop wallpaper will be reset to the default grey Windows Server logo, re-create as necessary

Don’t forget to activate against your KMS or enter your key.

Dell iDRAC 7 is now completely inaccessible to any of the 2012 R2 servers because IE11 is not yet supported. To run it, disable Protected mode and add the IP address of the DRAC server to the Compatibility Mode view

“StartServiceCtrlDispatcher failed (error 6)” is returned from attempting to start SQL Server Agent and “System.NullReferenceException: Object reference not set to an instance of an object.” is returned when attempting to start SQL Server Agent in SQL Server Management Studio

System Requirements:

  • Microsoft SQL Server 2008

The Problem:

It’s another instance of a new SQL Server installation on a newly installed Windows Server system that refuses to do what it is supposed to do. It seems to me that this is the rule rather than the exception, but I digress.

If you pull up a command prompt and attempt to manually start the SQL Server Agent process e.g.


You will receive

StartServiceCtrlDispatcher failed (error 6)

Similarly, if you attempt to start the SQL Server Agent inside SQL Server Management Studio you will receive the ubiquitous

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.

Server stack trace:
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.FindObjectExplorerFrame()
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.GetObjectExplorer(Boolean activateWindow)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ShowError(Exception e)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.Service.Start()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

In addition if you check the SQL Server Logs, the current log for SQL Server Agent will be blank or will have nothing logged recently (this is important)

More Info

If you are seeing up to date events in the SQL Server Agent log, then this fix likely does not apply to your situation. If you have a blank or a stationary log file then chances are it does.

Basically, the SQL Server Agent is refusing to start because it cannot write TO the log file. Obviously it is extremely hard to have the process termination log or output that fact otherwise Microsoft would have done it already… sigh.

The Fix

It is probably either or both of:

  1. Check the error log file path for accuracy
    Reg_SZ: ErrorLogFile
  2. Check the file / folder permissions for the path stated above, the SQLAGENT.OUT file and the SQLAGENT.# files. You can either reset them so that the SQL Server Agent’s process account has Full Control access or (depending on your logging policy) delete the files and SQL Server Agent will re-create the logs at startup

How to cleanly and automatically disconnect all VPN connections to Windows 2000, XP, 2003, 2008, Vista and 2008 R2 (for example on server shutdown): RRAS VPN Shutdown Tool

System Requirements:

  • Windows 2000
  • Windows XP
  • Windows Server 2003, 2003 R2
  • Windows Vista
  • Windows 7
  • Windows Server 2008, 2008 R2

The Problem:

Every now and then when a server gets rebooted you see slight bug appear in Windows Vista, 7, 2008 and 2008 R2 is it is VPN’d into said rebooting server. RASDial (the VPN client on said OS’s) thinks that the connection is still established. If you try and disconnect it (or once it realises) the connection status will change to “disconnecting” and it will stay like that.

In this state you can not connect, disconnect or delete the connection and the only way to fix it is to log off or restart.

If you disconnect all connections from the server before you do it i.e. cleanly, it doesn’t happen.

More Info

This is a particular problem if you have Task Manager, Scheduler or AT dialling VPN connections for you, it is less prevalent if the user dials the connection.

The Fix

Current Version:





Source Availability:


In the absence of there being an existing command line utility on the server to do this for you, I created the server utility equivalent of rasdial.exe /disconnect. When run, this utility will find any open inbound VPN connections and kill them off; cleanly.

The suggestion here is that you run it as part of your RRAS servers shutdown script so that all connections are knocked off before the RRAS service stops.

This is a two pronged utility.

It is compatible with “Microsoft Routing and Remote Access Server” on:

  • Windows 2000 Server
  • Windows Server 2003 (R2)
  • Windows Server 2008
  • Windows Server 2008 R2

As a bonus it also works with the “Accept incoming connections” dial-in system on:

  • Windows 2000 Professional
  • Windows 2000 Server
  • Windows XP
  • Windows Server 2003, R2
  • Windows Vista
  • Windows Server 2008
  • Windows 7
  • Windows Server 2008 R2


Note: Please be aware that the utility will also knock off any dial-up connections that happen to be connecting through the server; as it was designed to be run during shutdown I haven’t discriminated between VPN and dial-up connections.

It is written in C++ and compiled against MSVCRT6 so should work right out of the box on all platforms — assuming Windows 2000 is patched to SP4.


This is code written by me, I offer no warranties (expressed or implied) on its use. Test before you put it into production.

If it is useful to you please consider donating!


Download: RRAS VPN Shutdown Tool (47 KB)