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:
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:
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: