In my line of work, automation is important, since time is the only thing I don't have. Many years ago I created the WIM2VHD script and that was ok, so when R2 came out I needed to update it to support UEFI. That was easier said then done. The problem is that the UEFI boot process requires fat32, GPT and a bunch of partitions and when using PowerShell to create them the OS will immediately start protecting them after creation which makes it impossible to copy files to the boot partition since it is 'protected', but since I'm a very creative person I found the solution in diskpart. (read about it further down)
Converting Virtual Machine disk formats There are many Virtual Disk formats, VDI, VMDK, VHD, VHDX, IMG, RAW, HDD, and many more. Unfortunately VHD and VHDX formats are amongst the least popular ones, but if you're running a Hyper-V server these are the only formats you can work with. Convert vhd to iso free download - 2Tware Convert VHD, Free ISO to USB, Free ISO Converter, and many more programs. If your ISO is for a version of Windows, creating a SYSPREP'd VHD seems like a valid approach. My go-to tool for this in PowerShell is Convert-WindowsImage. Don't forget to use -VhdFormat VHD - Convert-WindowsImage creates a VHDX by default, but Azure requires the VHD format.
Mounting the ISO
I actually have to scripts in this case, one is to mount the ISO that will return the drive letter, kind of handy to have since I need to know the path to the wim file
The script to mount the ISO
The script to mount the ISO (Text)
————————————————-
# Mount ISO and get driveletter
Param(
[parameter(mandatory=$true,HelpMessage='Please, provide a path to ISO.')]
[ValidateNotNullOrEmpty()]
$ISO
)
Mount-DiskImage -ImagePath $ISO
Write-host (get-date -Format u)' – Mounting =' $ISO
$ISOImage = Get-DiskImage -ImagePath $ISO | Get-Volume
$ISODrive = [string]$ISOImage.DriveLetter+':'
Write-host (get-date -Format u)' – Driveletter is now =' $ISODrive
———————————————–
Getting the correct Index number in the WIM
After the ISO is mounted you can use the Get-WindowsImage commandlet to see what Indexes you have in the WIM file.
The Command Get-WindowsImage – Path d:sourcesinstall.wim will give me this list.
Converting the WIM file to the VHDX file
Besides converting the WIM to a VHDX file it also creates the UEFI style disk layout or the BIOS style disk layout. It also give you the opportunity to add the SXS folder to the drive (makes it a bit easier to add .Net framework without internet access or media access) and it will also ask you to add a Tools folder, if you do it will end up in c:Tools, extremely handy, I usually put things in there that I need, NP++, Sysinternals, 7-Zip, and such.
If you open the script you will one thing that is a bit strange (actually two), when creating the UEFI style disk partition we create the first partition with the WRONG GUID number and that is the way we need to do it, otherwise windows will start protecting the drive, so we create the partition with the GUID for data drive, later on we create a text file and we let diskpart run against that text file that will then change the GUID number to the correct one. scary…
Vhd File To Iso
Sample command to create a BIOS based VHDX
.Create-VHDX.ps1 -SourceFile d:sourcesinstall.wim -DestinationFile C:TestRWS2012R2BIOS.vhdx -Disklayout BIOS -Index 2 -PathtoSXSFolder d:sourcessxs -PathtoExtraFolder C:HYDV4Tools –Verbose
Sample command to create a UEFI based VHDX
.Create-VHDX.ps1 -SourceFile d:sourcesinstall.wim -DestinationFile C:TestRWS2012R2BIOS.vhdx -Disklayout UEFI -Index 2 -PathtoSXSFolder d:sourcessxs -PathtoExtraFolder C:HYDV4Tools –Verbose
When running it looks like this
I have tested the script on WS2012R2/W8.1 with Hyper-V but it should work on WS2012/W8 as well, just that I don't have any of those old systems running at home anymore…
Categories: BIOS, Deployment, Hyper-V, PowerShell, UEFI, Windows 8.1, Windows Server 2012 R2
My 160GB hard disk is running out of free space. Seriously low… It's amazing that I've managed to fill it up with so much stuff and it's all work stuff too. Now normally I rebuild my laptop every 4 months or so (yes I really do) but this time, I don't necessarily have the luxury of spending a couple of days because I'm up to my armpits on a project. Bionicle the game download.
So my normal setup is to have my one physical disk partitioned into two: one for the native operating system and the other for my data. I've always favoured split partitions, since configuration means that if I ever need to do a rebuild, I don't have to spend overnight backing up all my work data before the drive gets obliterated. Even though it only takes about 45-60minutes to reinstall Windows 7, it does take a while to install Microsoft Office, Visual Studio, SQL Server and a plethora of other programs and tools. It's probably a couple of days before I'm comfortably back into a situation where everything is back to how I want it to be.
Thing is, I don't have a couple of days and ultimately it's not going to solve my space issue. So I have a cunning plan with Windows 7 because I've discovered that it's now got the inbuilt capability that allows it to mount and boot from Virtual Hard Disks (VHDs). Effectively a portable, logical disk that runs natively on the hardware – not in a virtual machine.
Basically, a VHD is a large contiguous file structure that can be recognised as a hard disk, yet it's a virtual one sitting on your physical hard disk. I can backup my existing physical disk partitions to a VHD but it has to sit on a larger disk than the original, because there is an amount of hidden space used by the operating system to host the file. VHD's are a bit clever in that they can be setup as 'dynamic' and expand as necessary when data is added to it – there is no compression involved, but the free space is squeezed out in an attempt to minimise the overall footprint of the VHD – a 160GB partition with 50% free space will result in a VHD file with a 80GB footprint. Alternatively, VHDs can be set to 'fixed' and remain that size regardless of its mounted state – a 160GB VHD remains 160GB. If you want faster performance then select 'fixed', if you are scrimping on space then select 'dynamic' but beware that someday you'll need that full expanded space available if you fill it up!
Peep sights for browning blr. So, after crooning after a range of Solid State Disks (SSDs) which are blisteringly fast, very expensive but ultimately too small in capacity, I decided to try a 500GB Seagate Momentus XT Solid State Hybrid Drive. Best of both worlds really, optimised for speed, not so expensive and big capacity. Rather ironic, that EMC is one of the largest disk suppliers yet we don't put high performance disks in our consultancy laptops!
THIS IS MY JOURNEY FROM DISK TO VHD.
IF YOU FOLLOW ANY OF THESE STEPS, THEN YOU DO IT AT YOUR OWN RISK!
Creating your VHD
First thing to get your hands on is Disk2VHD. This is a neat little SysInternals tool from Microsoft (just recently had a revamp) which will create you a VHD file for use in Microsoft Virtual PC or for an Hyper-V virtual machine. Unlike some other tools out there, Disk2VHD can backup a disk/volume that is currently operational. YES, that means that you can transpose that disk/volume that you've currently booted from!
- Download and install
- Run 'Disk to VHD converter' as administrator.
- The following dialog will pop up, telling you what you can convert and how much space you need to complete the operation.
- Specify a destination file name for your VHD.
- Tick the partitions that you want to include into the VHD.
- Click 'Create' and the tool will take a snapshot and proceed to transfer data.
- Depending on the sizes of the partitions you clicked, wait….
https://ringdownloaddeck-set-2-0-0-simple-presentation-creator.peatix.com. Couple of things to note:
- If you are transferring relatively big partitions (>20GB) then be prepared to wait a while! When I Disk2VHD'ed my laptop, it estimated a 115GB VHD file so I left the tool running overnight!
- Disk2VHD can backup your currently operational drive onto a disk in that archive – I could have cloned the C: and E: partitions to a file on the E: partition. BUT, for performance reasons, this is not optimal. Either plug in a spare USB hard disk or connect to a network drive.
- Don't think that you have to keep all your partitions on the same VHD. If you want to share a partition amongst different instances, then just backup the minimum to each VHD.
- Only the booting VHD is guaranteed to be mounted on restart; additional VHDs need to be mounted manually or by script since Windows 7 will not remember on reboot.
With my 160GB laptop hard disk backed up to VHD on a network drive, I can now swap my old physical hard disk for my new shiny 500GB Seagate Momentus XT Solid State Hybrid Drive. I decided to continue with my usual split of the drive, by creating a first partition with 80GB for my native booting operating system and a second partition with the remaining available space for my data. This way, if I ever end up needing to rebuild my laptop, I can leave the 'data partition' alone and just blow away the 'operating system partition'.
Mounting your VHD
In Windows 7, mounting a VHD could not be simpler. The VHD is better off located on a locally attached drive so if you used a network drive as the destination for Disk2VHD, you're better off copying it back to either the native physical disk or to USB attached storage. Windows 7 won't stop you attaching to a remote VHD but it's much slower – I guess that it's because dragging large chunks of a file across the network is a drain on performance.
So, from the 'Start' taskbar, search for 'Disk Management' or 'Create and format hard disk partitions'. This will pull up the following control panel with details of your current system. Be careful with any of these options!
Now before I go further… pay heed to the warning from DISK2VHD:
Since I've swapped physical disks and reinstalled Windows, I'm not in danger of that rule. Phew.
Mounting a VHD is very straightforward. From the menu bar, select Action | Attach VHD.
Convert Iso To Vhd Windows 10
Your VHD will then appear as another row in the disk management matrix and all logical partitions will be identified and assigned a new drive letter for your current session. Once there are drive letters, you'll get access to the drive through Windows Explorer and be able to access folders and files as you would any other drive. Of course, that also means that any tightened security that was applied (particularly if NTFS formatted) might be a bit of a problem since you'll have to get permission (elevating to administrator normally helps) to just navigate the file system.
Once mounted, the Disk Management console now looks like below. Be careful, but right click the separate drives and take a look at various tasks – these allow you to change aspects of the the individual drives to customise your system.
Booting your VHD
The last step. Got a backed-up VHD of my original system and I've mounted it to check that it's all there, however this is not good enough for actually running anything because it's not the boot device. It's a law of computing nature – all the system files and registry settings have to be on the booted partition. Enter the world of GUIDs and BCDEDIT. Pay heed to my disclaimer above and read all this section before you proceed!
Gone are the days of boot.ini, autoexec.bat and config.sys (remember them?). Windows now keeps the boot settings within Boot Configuration Data (BCD) stores and BCDEDIT allows you to configure these settings via command line. Since I've reinstalled Windows onto my physical drive, I'll have a good BCD store already configured, otherwise Windows would not have booted up!
From the command line (run as Administrator) execute the following code to copy the existing/current BCD to a cloned BCD, giving it a new name of your choice:
bcdedit /copy {current} /d 'My new VHD'
That command will return a message containing a GUID that identifies the key of the new BCD created. Make a note of your GUID, copy it to notepad or something, but don't lose it, it will be needed in the next couple of steps. Next, change the new BCD to point to the new VHD. Most of it is self explanatory, but note that the drive parameter is the currently assigned drive letter – the tool just wants to be sure of locating the file:
bcdedit /set {guid} device vhd=[drive:]folder-pathvhd-filename.vhd
bcdedit /set {guid} osdevice vhd=[drive:]folder-pathvhd-filename.vhd
bcdedit /set {guid} detecthal on
Two extra commands of note:
bcdedit /v — this will display all the BCD configuration for your perusal.
Convert Iso To Vhd
bcdedit /delete {guid} /cleanup — cleans out the BCD data for the GUID key supplied
Just to give you an example, my personal configuration used the following commands:
bcdedit /copy {current} /d 'Windows 7 EMC VHD'
bcdedit /set {f83d7c67-2b5c-11e0-8cda-e442eeb247bc} device vhd=[e:]vhdwin7-emc.vhd
bcdedit /set {f83d7c67-2b5c-11e0-8cda-e442eeb247bc} osdevice vhd=[e:]vhdwin7-emc.vhd
bcdedit /set {f83d7c67-2b5c-11e0-8cda-e442eeb247bc} detecthal on
Superduper 3 2 3 download free. bcdedit /v
Now, reboot. Fingers crossed that if you followed all these steps, you'll be marvelling at the extra boot option before Windows spins up. I now get to choose between my native Windows 7 partition or my new 'Windows 7 EMC VHD' which is running from the VHD file. If you need to tweak the system start-up settings, then open the 'Startup and Recovery' – the new instance from the VHD will show up because of the updated BCD records.
In Summary
Disk To Vhd
Does it seem any faster? Probably not, at least not noticeably but that has not been my concern, space is. Maybe my new Seagate Momentus XT Solid State Hybrid Drive has helped because of it's newer electronics and bigger I/O cache, I'm not fussed. My laptop can breathe now, plus this was all done on a lazy weekend rather than spending a whole week of blowing away my existing Windows instance and reloading all that software and digging out all the licence keys that I've accumulated over time and that I actually need to do my job. By the way… this could be done faster than a weekend since much of the time was creating and copying the VHD up and down from my NAS and that was done overnight.
Hang on though, have I not just moved the problem into a VHD? Well no. I can turn up to work the next day and still be productive, but I'll systematically remove those really old applications I no longer use and move my local archive folders either to one of my native data partitions or to NAS so that any future Windows instance can see them (native or VHD).
This has also proved to be a convenient means of backing up my work. Basically once this is done once, I just reboot into my native Windows instance find the VHD file and copy it to my NAS (with a timestamp in the filename). If I manage to corrupt anything, swap laptop, or run up that VHD in Virtual PC, I just copy it back and change the filename to that in the BCD record (so it always remains as 'win7-emc.vhd' on my laptop). Gives me great flexibility… although VHDs also have the ability to have support differencing disks too, which might help to reduce the constant large footprint (why I have a big NAS!).
A mention about 'booting VHDs from USB Hard Drives'. There's been some mention of this on the forums and blogs that I came across while researching this topic. Seems to be some sort of holy grail for which I think it's a stupid idea. Sure, it's useful to stash VHDs to separate disks, but USB HDDs have one flaw for me… they are attached to the end of a cable – have you tried sitting on the sofa with a USB HDD dangling off the side? Tried moving around the airport or the office with your precious HDD swinging about? DON'T DO IT. BUY A BIGGER DISK. The techniques I've described above are there for convenience. don't bother tying yourself down again. Disk is cheap!
Convert Iso To Vhd Image
Useful References
This is a cross post from my EMC blog, mainly for backup duplicity and to aggregate some of my past postings. My EMC blog used to be under the Conchango brand but was acquired by EMC so I've also retrospectively refreshed some of the old links and maybe a tweak a bit of content too. permalink to the original post here |