Using MDT 2012 RC1 to deploy a VHD to a host machine

Over the past few weeks I have been playing around with MDT 2012 RC1, specifically the new Deploy to VHD feature.  Working in an educational institute, we have a need for VHDs for our students to practice using software that can’t be found on the regular desktop.  The ability to roll out a VHD to a host machine is very appealing and a welcomed addition to the MDT deployment toolkit.

I had a look through the documentation and saw that the new feature uses a new Task Sequence to deploy an OS to a VHD file and add it to the BCD Store so that you may boot into the VHD as you would any OS.

This wasn’t exactly what I was after.  I already have a fully working VHD that has all the software preloaded, I just want to roll out a VHD file to the host machine without it formatting the entire HD.  After some digging around on the Internet and a quick trip to the deployment forums over at Microsoft, I came to the conclusion that the Task Sequence was going to need some serious tweaking to get this to work.

So, what exactly am I trying to achieve here?

I need to deploy an OS and applications to a host machine, as well as copy across a fully working VHD and add it to the BCD Store.  Simple.

Walkthrough

Before delving right into the walkthrough, let’s look at some important background information…

We are going to be calling a script from the deployment share called ZTIVHDCreate.wsf, found in the Scripts directory in the root of the share.  This script has lots of variables that we can use when calling the script, these are show in the below screenshot and listed underneath:

**VHDInputVariable [ Input ]  – Name of Variable containing the target for the VHD file.

**VHDOutputVariable [ Input ]  – Name of variable to receive New Disk Index (Typically OSDDiskIndex for ZTIDiskPart.wsf).

VHDDisks  [Output ]  – Partition Index

VHDCreateFileName (Optional) – Name of VHD File to create (“RANDOM” or “” to auto generate name)

VHDCreateDiffVHD (Optional) – Name of VHD Differencing Disk ( “RANDOM” to auto generate name)

VHDCreateSource (Optional)  – Name of VHD File source to prepopulate the new VHD

VHDCreateSizeMax (Optional)  – Maximum Size (in MB) of the VHD file (Default: 90% of parent disk)

VHDCreateType  (Optional)  – Creation Type of the VHD Disk Either FIXED or EXPANDABLE (Default: EXPANDABLE)

** Required.

This walkthrough assumes that you have a working knowledge of MDT.  It also assumes that you have a VHD already created and ready for deployment.

Step 1: Set up test environment

For a test environment, it was suggested by Johan Arwidmark – a prolific deployment guy, to use a Virtual Image and to take a snapshot before deploying the VHD.  This will allow you to restore the snapshot if the VHD deployment doesn’t go as planned.  I used Virtual Box to create a Windows 7 image which I then installed guest additions and sorted out the networking.  At this stage, take a snapshot.

Step 2: Store the VHD on the deployment share and map to the share

Seeing as you will be accessing the VHD during deployment, it seems logical to store it on the deployment share itself.  I chose to create a directory called VHDs and dump it in there.  Now that we have the VHD somewhere we can access it, we need to map a drive to the share from our test environment.  Do this from an elevated command prompt using the net use command as the scripts we run later require admin privileges:

Net use V: \\Name of server\Name of share

Eg.  Net use V: \\DeploymentServer\Deploymentshare$

Now that we have the VHD stored in a central location and have a drive mapped to that location, we are ready to run the script.

Step 3: Call deployment script

As mentioned at the top of this walkthrough, we will be calling the ZTIVHDCreate.wsf script to deploy the VHD.  This script is worth a read through so that you understand what it is you are about to run.  When calling the scripts, we can use variables to give additional details to the deployment.  Some of these variables are optional, but some are requirements.  Those that are required are denoted by a double asterisk at the top of the guide.  The basic, stripped down command looks like this:

Cscript.exe ZTIVHDCreate.wsf /VHDInputVariable:VHDTargetDisk /VHDOutputVariable:OSDDiskIndex /DeploymentType:NEWCOMPUTER

You’ll notice the additional parameter, DeploymentType.  This is a required parameter but for some reason has been omitted from the script documentation.  This is what the command looked for me when I came to call it:

cscript.exe “\\DeploymentServer\DeploymentShare$\Scripts\ZTIVHDCreate.wsf” /DeploymentType:NEWCOMPUTER /VHDInputVariable:VHDTargetDisk /VHDOutputVariable:OSDDiskIndex /VHDCreateSizeMax:51200 /VHDCreateFileName:Win7 /VHDCreateSource:”\\DeploymentServer\DeploymentShare$\VHDs\VHDTest.vhd”

So with the addition of some extra parameters, we can give it a maximum file size – note that this is only for expandable VHDs, and give it a name.

It takes some time for the VHD to copy across depending on how large the file is.  Remember that if you run into any problems or if your VHD didn’t deploy as cleanly as you had expected, you can always restore the snapshot from Virtual Box Manager.

Step 4: Deploying a host OS and a VHD

So far we have deployed a working VHD to a host machine by manually calling on the ZTIVHDCreate.wsf script.  Now that we have had some success with that, it’s time to run it from within a Task Sequence along side the deployment of a host OS.

To do this we will use a standard client deployment TS, rather than either of the client/server VHD deployments.

This deployment is exactly the same as a regular OS deployment but with the addition of the VHD after the installation of the applications.

So, to get this working, we’re going to add the command line we created in the last step and add it as a step in the TS.  Firstly, we need to add a new command line item to the TS.

In the above screenshot you can see that I have added several command line items to the TS.  The second command line to be run is the command that we have previously created.  The first command line is the net use command that we ran from our test environment to map to the deployment share.  Depending on how your host OS was deployed, you may not need to use this command as you the deployment process may have used an admin account to map to the deployment share.  However, it was necessary for me as the deployment process is not done using my network admin account.

As you see from the screenshot below, the net use command is exactly the same as it was in step 2, but this time I have instructed the TS that I want the command run with a specific user account.  This is an account that is specifically used during deployment and is not my own, for security purposes.

Once you have added these two command line items to the TS, you should be able to deploy a fully functional VHD to a host at the same time as deploying the host OS!  Just one, optional, step remains…adding the VHD to the BCD Store.

Step 5:  Automating addition of VHD to BCD Store

I can take no credit for the script that automates this process.  I have shamelessly borrowed it from Dan Stolts.  You can find the full script at his blog.  Basically, all you need to do here is store the script somewhere on the deployment share, either in the scripts folder or in the same directory as the VHD itself.

Once stored on the share, we can add the third and final command line item to the TS.  The syntax of this command is as follows:

Path of script > path of LOCALLY stored VHD  >  Name of VHD to appear in the Boot menu.

Eg.

\\DeploymentServer\Deploymentshare$\VHDs\BCDEdit.bat C:\VHD\Win7.vhd Windows7

And that’s it!  Having followed these instructions, you should now have a dual boot machine that runs with a VHD that you already have kicking around.

This method may not be the most efficient and may be tweaked over the coming weeks as I continue to play around with it.  I welcome your comments if you think something has been glanced over or if you have a better way of achieving this.  It works for me and there currently isn’t any other guides for this on the net!  Good luck in your deployment!

This slideshow requires JavaScript.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s