Partilhar via


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:

image

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.

Diff.zip

Comments

  • Anonymous
    January 01, 2003
    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.

  • Anonymous
    January 01, 2003
    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

  • Anonymous
    April 25, 2014
    The comment has been removed