Here's the situation; you are trying to create a golden template to be used in some cloudy way. This template has your base OS (Windows of course), is up to date with all updates and security patches, and has your desired disk configuration. This disk configuration includes an OS volume (C:) and a couple of data volumes which are mounted to folders on the C drive.
Image may be NSFW.
Clik here to view.
However, after you clone your template and log on and investigate, you realize that you have a C, D, and E drive. Your mount-points were converted to drive letters.
Image may be NSFW.
Clik here to view.
But, let's take a look at what diskpart.exe has to say (this can also be verified in Disk Manager).
Image may be NSFW.
Clik here to view.
It appears that during deployment drive letters were added, and the mount-points were not removed. This is actually a result of running VM Guest Customization through vSphere, which basically runs SysPrep mini-setup. If you were to clone your template without customization (not recommended, or supported for cloning Windows by MSFT) the disk configuration you had intended would stick. So now what?
The solution is a simple one-liner to call diskpart.exe and pass it a command file. Let's take a look at the commands we're going to pass to diskpart.exe.
Image may be NSFW.
Clik here to view.
Diskpart.exe is an interactive command-line utility used to create, delete and modify the disk configuration of your system. Diskpart.exe will accept commands from a text file like the one above when invoked with the "/s" switch. In the command file above we are selecting the volume (Volume 3) and then removing the drive letter. This will leave our mount-point in tact.
One thing to note is that you must understand how the clone assigns drive letters. For instance, in my template the DVD-ROM was assigned drive letter D. That is because I added the two disks to my template after the DVD-ROM drive was already present. In my clone, the two additional disks are present and thus are assigned drive letters before the DVD-ROM device. It's a good idea to deploy a test clone to make sure you know what volumes and drive letters to specify in the command file.
With the file config_disks.txt created on the template we can kick off the clone of our template and add our diskpart.exe command to execute after deployment.
To insert a command after deployment the guest OS must be customized. In the screenshot below I've chosen to power on the virtual machine after creation, customize using a customization spec that I've previously defined and then to allow me to temporarily adjust the customization spec before deployment.
Image may be NSFW.
Clik here to view.
The Run Once section of the guest customization wizard is where I've inserted the command I want to run after deployment.
Image may be NSFW.
Clik here to view.
The command will execute diskpart.exe from the System32 folder (which is in the PATH, but specifying the full path never hurt anyone) and use commands from the c:\config_disks.txt to run. For logging purposes you could redirect the output to a file using the redirect operator (>) and defining a log file, just note that because the command runs as LOCALSYSTEM, access to the root directory will be restricted and you may not get a log file when expected. Guess how many runs it took me to remember that tidbit J
-enjoy