Using boot from VHD and differencing disks

MDT 2012 includes a task sequence for deploying an operating system into a VHD, setting up the computer for booting from that VHD.  See my previous blog posting about Deploy to VHD for more details on that.  As I mentioned in that blog, setting up a differencing disk to be created during the “Deploy to VHD” task sequence doesn’t make sense, as the parent VHD would be empty.  But it would be useful to be able to do it later, so that you have the already installed and configured OS in the main VHD, and then one or more differencing disks set up with that VHD as the parent.

So how do you actually do that?  The basic steps would be:

  • Boot into Windows PE.  (You can’t create a differencing disk off of a parent VHD if that VHD is currently open, as it would be when boot from the VHD.)
  • Use DISKPART to create a new differencing disk with the existing VHD as the parent.
  • Create a new BCD entry for the differencing disk.

To help with that process, I created a new script called Diff.wsf, attached below, that will perform all of those steps.  Set up a new custom task sequence in your MDT deployment share that has a single step in it that runs the script like so:


Then reboot into your MDT Lite Touch boot image (either from media or from PXE) and run this task sequence.  The command line parameters above tell it what to do:

  • /CREATE specifies to create a new differencing disk.
  • /CLEAN specifies to remove any existing differencing disks that might be present.
  • /STAGE says to copy the Diff.wsf and all related scripts locally onto the disk, in the same folder as the parent VHD file.

The task sequence completes while in Windows PE, and as soon as you click finish on the summary wizard page, the computer will reboot into the new differencing disk, causing all changes to be written into the diff file while the parent VHD remains unchanged (and effectively read-only).

After that initial differencing disk has been created, the locally-staged script can be run directly without even using a task sequence.  Assuming that the drive letter assigned to the physical disk containing the parent VHD (and the differencing disks) is D:, then the script will be located at D:\VHD\Scripts\Diff.wsf.  When you run it from there (initiated from within the currently-running OS), you can specify any of the parameters described above, or you can leave off the parameters and the script will prompt.

Note that the script can’t actually delete the differencing disk that is presently in use because, well, it’s currently in use.  But it can remove the BCD entry for it, and after a reboot it can then be deleted.  So the script will also take care of cleaning up any “orphaned” differencing disks it finds laying around.

A few final comments on scenarios for running Diff.wsf from within the currently-running OS:

  • If you specify /CLEAN without /CREATE, it will remove all the differencing disks and boot back into the main VHD file.  This is useful if you want to update (e.g. patch) the installed OS.
  • If you specify /CREATE without /CLEAN, you’ll get another differencing disk and another BCD entry – so if you really want to, you can boot between different differencing disks.

Comments (3)
  1. Anonymous says:

    I did something similar to this by building a boot WIM with all the scripting needed and putting that onto the D:VHD folder during deployment and also adding an entry in the BCD so I could boot into PE whenever I want.  At the end of my deployment TS the machine reboots into PE, creates a DIFF VHD using Diskpart, and then modifies the BCD to boot from the new DIFF VHD.  The result is that from any time from then on if you want to get the computer back to the way it was when it was first deployed, you just run another script to boot back into PE, delete the DIFF VHD, and modify the BCD accordingly.  This is a tremendous timesaver for testing when you must use a physical machine.  I've taken it a step further with another script to take a DIFF of the first DIFF and so I can essentially take snapshots and revert as well as go back to the "factory" configuration.

    I think I read about deploying VHD Win7 images on your blog, and this method offers all sorts of great opportunities.  With some work you can even get the VHD into Hyper-V, but that is another subject.

  2. Anonymous says:

    I would like to know, if you have the info where can I modify the VHD settings  for this tasks like Description, because when I boot I have 2 Win7 entries and I would liek to know where on MDT scripts or variables I could modify the VHD entry on bcdedit part. thanks

  3. Holger says:

    Hi Michael, I use your script but have some problems. I have created the Task-Sequence, and the script is starting as it should. But unfortunately it only creates the Diff-Disk but does not change the boot-Record. Instead I get an error in the smsts.log:
    failed to run the action: Create differencing Disk. Unknown error (Error: 0000270F; Source: Unknown)
    The funny thing is that when I open a command-line and start the script again manually, everything works as it should. Do you have a tip where to look any furthers? Even the Debug-file is not created.

Comments are closed.

Skip to main content