Make a Windows 10 WTG key inside a Hyper-V VM


So I was playing a few weeks back and thought I’d share on some of my fun.   Like many IT Pros I downloaded the Windows 10 CTP media to test out and try Windows 10.   In my case I spun it up inside a Virtual machine to see a side by side comparison on my production Windows 8.1 laptop.

During this process my boss’ hard drive went caput on his laptop.   Fortunately for him he was recently migrated to a honking cool Surface Pro 3 laptop.

Fortunately for ME there was minimal data loss and this gave me a chance to play with something else.   Windows To Go.

You see, apparently if you want to run an operating system you need SOME kind of data storage.   Since we didn’t have a spare drive for his particular model of laptop (or in my case all of the “spares” were holding backup copies of his data) I wanted to fire up Windows 10 to see what it looked like on his laptop.

So the answer was easy.  “I’ll just pop in my Kingston USB and make a Windows To Go version of Windows 10.”

The important rules have not changed.   Windows to Go still requires Windows Enterprise media, of which my CTP media is !

Ah but a small problem.   Although I can access the file structure on the key I am unable to create partitions.   Or for that matter running the built in Windows to Go Wizard.

Looking about online there are options however to bypass this issue.   It involves a Direct Passthru to the physical disk in Hyper-V and a little coolness in Windows PowerShell to generate the content on the key.   Now in TRUTH I COULD bypass the VM and just run the script and build it directly on the PC but Where’s the FUN in THAT?! Smile

So challenge one.  Connect the USB to the Host environment.  

In this scenario I have a Kingston DT Ultimate attached to my PC.   You’ll need to bring it offline in Disk Management First

image

Now that the disk is offline, I can enter my Virtual Machine Configuration and attach the disk in “Pass Thru” Mode.

image

image

With the USB Disk in Pass thru mode I can now access it directly within the Virtual Machine. 

Now of course we could have just done all this with PowerShell with the following Cmdlets.

# Identify the USB key which is Greater than 20GB in size

$disk=(GET-DISk) | where { $_.Bustype -eq ‘USB’ -and $_.Size -ge 20GB -and -not $_.isboot }

# Bring the key offline on the Hyper-V Host (Windows 8.1 laptop)

$disk | Set-Disk –isoffline:$True

# Attach said disk to the Virtual machine named “EOT-WIN10-CTP”

$disk | Add-VmHardDiskDrive –vmname EOT-WIN10-CTP

For this next amazing magic trick we’re going to be running a Windows PowerShell script to partition the key.    This comes courtesy of a Step by Step  article on Technet for creating the Windows To Go key directly without using the Wizard.   The script however is based upon the presumption that the attached disk in question in USB.  But Within the Virtual Machine it will appear as an ordinary disk.

To adapt to this scenario take the Microsoft script and edit the line reading

$Disk = Get-Disk | Where-Object {$_.Path -match “USBSTOR” -and $_.Size -gt 20Gb -and -not $_.IsBoot }

and replace it as

$Disk = Get-Disk | Where-Object {$_.Size -gt 20Gb –and $_.Size –le 64GB –and -not $_.IsBoot }

From this point forward the script will work as designed WITHIN the Virtual machine and partition the key ready for the Windows To Go structure.

Be FULLY FOREWARNED! If you are running this in a Virtual Machine which has disks OTHER than the Bootable C: drive and your Windows To Go key which are bigger than 20gb and smaller than 64gb you WILL ABSOLUTELY LOSE THEM.   So PLEASE just run this inside a virtual machine you could consider a “throwaway” and not something critical to production like the Exchange or the BES server. 

For the purposes of fun and truly “throw away” I am running all of this inside a Virtualized Windows 10 CTP.   So if I goof up, it’s just a test machine.  You should do the same Smile

Going forward as per the instructions from Technet we can run DISM to apply the image.   In the case of this Virtual machine, I have the Windows 10 CTP mounted in the DVD drive and will be leveraging it’s WIM file to image this key.   The original document called for leveraging DISM.EXE

dism /apply-image /imagefile:D:\Sources\Install.wim /index:1 /applydir

But instead I’m going to use the PowerShell which does EXACTLY the same thing

Expand-WindowsImage –imagepath D:\Sources\Install.wim –index 1 –ApplyPath W:\

From this point (After some waiting time of the image dropping onto the key of course) we can run this command to make the key bootable

W:\Windows\System32\bcdboot W:\Windows /f ALL /s S:

Normally at this point you would apply the san_policy.xml file using this command in DISM. 

Dism.exe /Image:W:\ /Apply-Unattend:W:\san_policy.xml

Instead we’re going to jump ahead and just use the PowerShell Cmdlet instead (Does somebody out there smell a SINGLE PowerShell script we could use to do all of this now?)

Use-WindowsUnattend –unattendpath .\san_policy.xml –path W:\

Then of course the most critical piece, dropping in an Unattend.xml file to automate the startup of the WTG environment

Copy-item .\Unattend.xml –destination W:\Windows\System32\Sysprep

Then let’s disconnect that Disk from the virtual Machine

Get-VM EOT-WIN10-CTP | Get-VmHarddiskDrive | Where { $_.DiskNumber } | Remove-VMHarddiskDrive

Now just RIP that USB key off the side of your machine and enjoy your new Windows to Go!

Follow

Get every new post delivered to your Inbox.

Join 3,063 other followers