Sunday 5 February 2017

How to make a .VHD from a .imgPTN file (or how to copy all Windows files to a different drive)

Basically, I had a complete working Windows installation on a disk Volume and I just wanted to copy all files to another disk Volume...

Actually, I had created a new 16GB NTFS  .imgPTN file and installed WindowsToGo onto it.
The .imgPTN file booted to Windows nicely.

However, I wanted to convert the partition to a .VHD fixed-size (not dynamic) file so I could add it to my E2B drive and boot directly to it without having to 'switch' partitions - this would allow me to directly access all of the files on the E2B drive after I had booted from the VHD.

Since the WinToGo partition was located on a 500GB USB drive, I did not want to use a DisktoVHD conversion tool because I would end up with a 500GB .VHD file!

I could not find a way to simply copy the files from the USB drive to an empty VHD virtual drive. I kept running into permission issues, symbolic link issues, locked files and other access problems caused by Windows thinking the files were important OS files!

Even upgrading my Windows Home OS to Pro and using VSS didn't help.

After asking the good guys on reboot.pro, it was suggested I use Olof's strarc utility and it worked a treat!

Here is what I did:


1. Switch to the .imgPTN file using \_ISO\SWITCH_E2B.exe - my E2B USB drive was now drive D: (16GB) and had the full WinToGo installation on it as flat-files (\Windows, \Program Files, etc.).

2. Delete any unwanted files (e.g. \hyberfil.sys, pagefile.sys, etc.) .

3. Create and attach a fixed VHD using Windows Disk Management console (diskmgmt.msc) - this gave me a virtual 16GB Q: drive.

4. Download strarc and extract it.

5. From an Admin Windows cmd shell, we copy all files on D: to Q: using:

strarc.exe -cjd:d:\ | strarc -xd:q:\

Note: you can safely ignore any error messages about the \System Volume Information folder.
Be sure to use the vertical bar  | key as shown (Shift+<key-to-right-of-lshift-key>)

Olof recommends this so that some files are also excluded:
strarc -c -j -e:"\System Volume Information,\Temp\,\Temporary Internet Files\,\Cache\,.tmp,pagefile.sys,hiberfil.sys,\$NtUninstall" -d:d:\ | strarc -xd:q:\
To ignore messages about 8.3 filename compatibility (I didn't see any) , use -s:8.

I first formatted Q: so it was empty of all files.

6. Detach the Q: drive in the Disk Management console and copy the VHD file to \_ISO\MAINMENU on my E2B USB drive and boot it!


Note that this will only work using a .imgPTN which contains a Vista or later Windows OS, because E2B will automatically use bootmgr and it's own BCD to boot to the files inside the VHD. It is also only suitable for MBR-booting (not UEFI-booting).

Thanks again to reboot.pro and Olof (author of ImDisk)!

If some files are locked or held open by Windows, you can try using a Volume Shadow Copy Service  (VSS) utility such as ShadowSpawn to make a virtual copy and then run strarc using the new virtual drive as the source. You can also try U-Recover to create a shadow copy of a drive.

No comments:

Post a Comment