Back when I was using BSD Unix and Linux a lot, sym links were incredibly handy creatures. It was with great joy that I recently discovered NTFS Junctions (aka Reparse Points), which are directory-only sym links for NTFS file systems. Junctions are supported in NTFS on Windows 2000, Windows XP, and Windows 2003 Server. Out-of-the-box, Junctions are not easy to use, but two little utilities make life much easier:

  • Junction – A sysinternals command-line utility for creating, viewing, and deleting junctions.
  • Junction Icon Overlay – Windows Explorer Overlay that displays a junction icon on sym linked folders.

Now you might be wondering, what the heck are sym links/junctions/reparse points and why should I care? Let’s take my current setup as an example. I’ve got a pile of virtual machines for running the latest Visual Studio 2005 and SQL Server 2005 bits, along with installs for Indigo, Avalon, and WinFX. My laptop hard drive, while a spacious 60 GB, fills up rather quickly with all those VHD files. Now I could put all the VHDs on my 300 GB Maxtor external drive, but what happens when I need to use one on the road. (The Maxtor external drive requires an external power supply. So you can’t fire it up when you’re commuting on the bus.) I could copy it over to the internal drive, but then I have to tidy up my delete/re-create the virtual machine in the VPC 2004 console. Instead I junction the virtual machine directory on my external drive to “My Documents\My Virtual Machines”. Here is my external drive:

Here is My Documents\My Virtual Machines:

The little links on the folders come from the Junction Icon Overlay.

When I want to create a new virtual machine on the external drive, for example Windows XP Pro – Whidbey RC1:

  1. Create an empty directory called R:\My Virtual Hard Disks\Windows XP Pro – Whidbey RC1.
  2. Open a command prompt in C:\Documents and Settings\JamesK\My Documents\My Virtual Machines\.
  3. Run the command: junction “Windows XP Pro – Whidbey RC1” “R:\My Virtual Hard Disks\Windows XP Pro – Whidbey RC1”.
  4. Create the new virtual machine using the Virtual Disk Wizard and Virtual Machine Wizard as per normal using the path “C:\Documents and Settings\JamesK\My Documents\My Virtual Machines\Windows XP Pro – Whidbey RC1”.

This has a number of advantages over just creating the virtual machine on the external drive:

  • If I ever want to make that virtual machine portable, I simply delete the junction (junction -d “Windows XP Pro – Whidbey RC1”) and copy the directory over to the same place. VPC 2004 will never be the wiser.
  • If I decide to archive an old virtual machine on the internal drive because a new beta drop just hit the streets, I copy it to the external drive and create a junction.
  • If I fire up VPC 2004 without the external drive, only virtual machines on the internal hard drive appear. If I add the external hard drive and restart the VPC 2004 console, the virtual machine images on the external drive appear once again. (Very cool feature. I wonder if the VPC 2004 dev team knows about it.) 🙂
  • You don’t have to re-target your differencing VHDs when you move your base VHDs. Just create a junction from the original location to the new location of the base VHDs.

There are lots of other uses of junctions. Scott Hanselman’s favourite seems to be avoiding “the evil that is the Company-Wide Subst” when creating a standard development build tree. (Very good use, I must say.) You could also use them to archive old C:\Program Files without having to uninstall/re-install the programs – simply move the directory to your external drive and create a junction from C:\Program Files to the new location. Use your imagination and you’ll be amazed at the uses you can put these little critters to. You’ll also wonder how you ever lived without them.