View Single Post
  #1  
Old 02-26-2020, 03:40
chants chants is online now
VIP
 
Join Date: Jul 2016
Posts: 738
Rept. Given: 37
Rept. Rcvd 48 Times in 30 Posts
Thanks Given: 671
Thanks Rcvd at 1,064 Times in 482 Posts
chants Reputation: 48
Creating boot WinPE ISO from USB drive with min. disk space+factory reset prtn. info

I have found it interesting that lots of utilities which will create bootable ISOs from a USB literally mirror the whole drive even if a small amount is actually used. Creating ISOs that are not bootable will efficiently just mirror the file system. The trouble is that ISO was designed for DVD booting.

Emulating USB drives to directly capture an ISO is also not really easily possible. There are some utilities, but even those have to treat the space as an unknown blob. The utilities often are not even detected by some software utilities as being valid USB drives due to some quirks with how the driver class is defined in the registry. So with all the various utilities that create USB drives it is hard to fake. There are even utilities to do this by emulating DVD writable drives and they work pretty good. Though after you create the image, if it does not use the full drive, you will want to mount that image and create another image.

Here are some interesting use cases:
Windows 7 SP1/10 latest Recovery Drive
Factory Reset partition drive
Some tools like MSDART will create an ISO for you and not require extra effort. There is also a process to take a bootable WIM file and make an ISO manually though there are some steps and work involved mostly to get the MBR and UEFI boot files into place.

So what is involved?

Well despite that I cannot find any utility that properly does this there are some things to know:
1) there are utilities that can extract a boot sector from a USB drive often as if it were just a floppy drive.
2) since most of the time, the boot routes are known be they from MBR or UEFI, we can simply use these standard routes to define how to do this.

Only requirement is the Windows Assessment and Deployment Kit's Oscdimg utility which is freely available as a download from Microsoft.

Here is an example with a single command creating a dual MBR and UEFI bootable ISO (from a USB containing the Windows 10 1909 x64 recovery drive made in control panel):
Quote:
"D:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\Oscdimg.exe" -bootdata:2#p0,e,bC:\Windows\Boot\DVD\PCAT\etfsboot.com#pEF,e,bC:\Windows\Boot\DVD\EFI\en-US\efisys.bin -u2 -m -h -lRECOVERY F:\ D:\Win10Recovery1909x64.iso
And here is one for MBR only (similarly can make UEFI only):
Quote:
"D:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\Oscdimg.exe" -bC:\Windows\Boot\DVD\PCAT\etfsboot.com -u2 -m -h -lHDDRECOVERY H:\ D:\Output.iso
Where H: is the drive with the files on the USB drive or a mounted ISO. -l specifies the label which should ideally match that of the source drive or image.

MBR boot uses
Quote:
C:\Windows\Boot\DVD\PCAT\etfsboot.com
which uses the BCD in the \boot directory while UEFI boot uses
Quote:
C:\Windows\Boot\DVD\EFI\en-US\efisys.bin
and uses a BCD in EFI\Microsoft\Boot. The boot\boot.sdi is a virtual hard drive mount driver for the .WIM file.

If you have done a lot of changes with your drives in a laptop, and still have the factory recovery partition, and you would still like to make proper factory recover disks or boot off of it here are some things to note:
1) the label of the drive, GUID type on UEFI or ID on MBR, and the hidden settings are important for it to be seen.
2) utilities which create recovery disks will want this special partition likely on the same drive you boot off of so mirror it over if you have to and likely they will work.
3) often the first sector MBR of the factory default system is the normal MBR like we are used to. But the second sector has a special MBR which DVD boots the factory recovery partition. I have not been able to fix this on a laptop I have with several tricks to ever get the factory reset button to work again. But if I set it to the active partition, it DVD boots that drive and works. The key here is the BCD must load off the factory reset partition. You cannot have your normal active drive BCD try to load it no matter how clever the BCD entries you add are - it will at best boot a Windows Recovery disk, not a factory reset environment.
4) with UEFI if you switched your main OS to an SSD, there is little hope you will convince the system to UEFI boot the recovery partition even from the UEFI menu. There are a lot of tricks though: you can create a recovery USB drive just by copying all of the files in this partition to a USB drive which you make MBR/UEFI bootable using the technique above.
5) if the recovery disk utility works, then simply make the USB drive and make the ISO from procedure described. This can be saved and put back on the USB drive for recovery at any time which is probably faster than recovery from HDD and has the benefit of more easily clearing the whole disk.
6) almost all changes that are needed can be done with the diskpart utility built into Windows for changing GUIDs or IDs or hidden setting or even the active drive, and mounting drive letters. A visual tool like EASEUS Partition Manager can be nice as well and can a lot of advanced repartition tricks when needed.

A final note, if you wish to chain load with a BCD, it can only really be done with a boot sector BCD entry, and this can allow Windows boot loader to boot to Linux but you will need to precisely set this to a .COM/.BIN file with the boot sector code. It seems likely it could be done with UEFI and not just MBR but I have not tried it. You cannot chain load boot managers though from one UEFI drive to another. Once the BCD on a drive is loaded, you are stuck with it. Depending on your BIOS, you can still write the volumes you want to boot on another drive in, and can hope the BIOS will boot it. I have an old laptop which used the small SSD as a cache drive and when I made it primary for a larger SSD, it would refuse to UEFI boot off it and by creating a UEFI partition on both drives with nearly identical BCDs, at last I could fool the laptop to secure booting but there are special boot cases where it has trouble finding partitions.

Some interesting information for those who ever need it. I felt I would document it here since most of it is little found on the web or at least in one place.

Last edited by chants; 02-26-2020 at 03:49.
Reply With Quote
The Following 3 Users Say Thank You to chants For This Useful Post:
niculaita (02-26-2020), RiRye (02-28-2020), uranus64 (02-26-2020)