@echo off ::====================================================================== :: This script is used to create a customized Winpe wim for deployment of Windows Server 2012, 2012R2, 2016. :: Disclaimer: Any modifications to this script are done at your own risk, and might cause issues in the WinPE .wim. :: This might lead to Windows installation failures through xClarity Administrator. ::====================================================================== :: Pre-Requisites: :: 1) A host installed with the latest Windows 2012 R2 OS installed. :: 2) A host must be installed with Microsoft ADK 10 (v1607). :: 3) Download the genimage.cmd file. Used to generate the .wim. :: 4) Download the starnet.cmd. Used by xClarity to bootstrap the Windows installer. :: :: Device Driver Injection into WinPE: :: - Out-of-box drivers can be injected into the WinPE environment in one of two ways: :: 1) Load as "inbox" drivers. Copy the drivers to the host then to the C:\drivers directory prior to running genimage.cmd. This method :: will also install the drivers as part of the base OS. It also removes the need to import the drivers via the xClarity :: Provisioning > Manage OS Images > Import Driver Files since the drivers are installed to the Base OS. :: 2) Load at runtime using Windows 'drvload'. After genimage.cmd runs, and the image is mounted, copy drivers in inf format :: to the mounted image. This method will not install the drivers to the base OS, it will only apply to WinPE. :: a) Create the directory structure: CustomerDrvs\\ . Where OSRELEASE is: 2012 | 2012R2 | 2016 :: b) Extract the out-of-box raw inf drivers to a directory inside the path CustomerDrvs\\\. :: Do this for all OOB drivers you want included. :: c) Once the image is mounted copy CustomerDrvs to the mount directory: C:\WinPE_64\mount\CustomerDrvs :: d) Unmount the image. :: :: Typical customized Winpe wim flow for xClarity OS Deploy: :: 1) Install Windows 2012 R2 with ADK 10 v1607. :: 2) Copy genimage.cmd and startnet.cmd to Host into a directory like C:\customwim :: 3) As an administrator: Run Windows ADK command "Deployment and Imaging Tools Environment". This will open a command prompt. :: 4) cd C:\customwim :: 5) Make any modification you see fit to Windows that you want picked up in the .wim. MS articles can be helpful here: :: a) Intro: https://msdn.microsoft.com/en-us/windows/hardware/commercialize/manufacture/desktop/winpe-intro :: b) Details: https://msdn.microsoft.com/en-us/windows/hardware/commercialize/manufacture/desktop/winpe-mount-and-customize :: 6) Ensure no previously mounted images are on the system: dism /get-mountedwiminfo , if there are then discard: dism /unmount-wim /MountDir:C:\ /Discard :: 7) Run: genimage.cmd amd64 -> Note this will take a few minutes typically. :: 8) Mount the image to modify it: DISM /Mount-Image /ImageFile:C:\WinPE_64\media\Boot\WinPE_64.wim /index:1 /MountDir:C:\WinPE_64\mount :: a) Again, checkout the articles above to see what you can modify at this point. :: 9) Load the drivers: :: a) Inbox: Copy drivers to C:\drivers. :: b) Runtime: Copy the CustomerDrvs directory to C:\WinPE_64\mount\CustomerDrvs :: 10) Unmount the image: DISM /Unmount-Image /MountDir:C:\WinPE_64\mount /commit :: 11) The output of the WinPE customization can found at: C:\WinPE_64\media\Boot\WinPE_64.wim :: 12) Import it as a Windows boot file on xClarity > Provisioning > Manage OS Images > Boot Files :: ====================================================================== :: ::Get the arch from first param (should always be 'amd64') set ARCH=%1% set ADK=10 if [%ARCH%] EQU [x86] set SUFFIX=32 if [%ARCH%] EQU [amd64] set SUFFIX=64 if [%SUFFIX%] EQU [] goto :errorbadargs ::Configuration section ::the drive to use for holding the image set defdrive=%SystemDrive% ::Get the name of winpe set WINPENAME= set BCDONLY= set BOOTPATH=Boot if [%1] EQU [] goto :errorbadargs if [%2] EQU [] ( echo Generate winpe to default path %defdrive%\WinPE_%SUFFIX%\media ) else set WINPENAME=%2% if [%2] NEQ [] echo Generate winpe to path %defdrive%\WinPE_%SUFFIX%\media\winboot\%WINPENAME% if [%3] EQU [bcdonly] set BCDONLY=1 if [%WINPENAME%] NEQ [] set BOOTPATH=winboot\%WINPENAME%\Boot ::Set the location where Windows PE from ADK install is located set adkpedir=%defdrive%\Program Files (x86)\Windows Kits\%ADK%\Assessment and Deployment Kit\Windows Preinstallation Environment set oscdimg=%defdrive%\Program Files (x86)\Windows Kits\%ADK%\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg set WinPERoot=%adkpedir% set OSCDImgRoot=%oscdimg% set Path=C:\Program Files (x86)\Windows Kits\%ADK%\Assessment and Deployment Kit\Deployment Tools\amd64\DISM;%Path% ::Clean the WinPE directory and copy it from ADK if exist %defdrive%\WinPE_%SUFFIX% rd %defdrive%\WinPE_%SUFFIX% /s /q set retpath=%cd% cd /d "%adkpedir%" call copype.cmd %ARCH% %defdrive%\WinPE_%SUFFIX% cd /d %retpath% bcdedit /createstore %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /create {ramdiskoptions} /d "Ramdisk options" bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /set {ramdiskoptions} ramdisksdidevice boot bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /set {ramdiskoptions} ramdisksdipath \%BOOTPATH%\boot.sdi for /f "Tokens=3" %%i in ('bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /create /d "xCAT WinNB_%SUFFIX%" /application osloader') do set GUID=%%i bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /set %GUID% systemroot \Windows bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /set %GUID% detecthal Yes bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /set %GUID% winpe Yes bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /set %GUID% osdevice ramdisk=[boot]\%BOOTPATH%\WinPE_%SUFFIX%.wim,{ramdiskoptions} bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /set %GUID% device ramdisk=[boot]\%BOOTPATH%\WinPE_%SUFFIX%.wim,{ramdiskoptions} bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /create {bootmgr} /d "xCAT WinNB_%SUFFIX%" bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% /set {bootmgr} timeout 1 bcdedit /store %defdrive%\WinPE_%SUFFiX%\media\Boot\BCD.%SUFFIX% /set {bootmgr} displayorder %GUID% bcdedit /store %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% if [%ARCH%] EQU [x86] copy %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% %defdrive%\WinPE_%SUFFIX%\media\Boot\B32 if [%ARCH%] EQU [amd64] copy %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD.%SUFFIX% %defdrive%\WinPE_%SUFFIX%\media\Boot\BCD ::Skip the creating of winpe if [%BCDONLY%] EQU [1] goto :reorgpath dism /mount-image /imagefile:%defdrive%\WinPE_%SUFFIX%\media\Sources\boot.wim /index:1 /mountdir:%defdrive%\WinPE_%SUFFIX%\mount cd /d %retpath% copy startnet.cmd %defdrive%\WinPE_%SUFFIX%\mount\Windows\system32 rem copy "%defdrive%\Program Files\Windows AIK\Tools\%ARCH%\imagex.exe" %defdrive%\WinPE_%SUFFIX%\mount\Windows\system32 dism /Image:%defdrive%\WinPE_%SUFFIX%\mount /add-package /packagepath:"%adkpedir%\amd64\WinPE_OCs\WinPE-WMI.cab" dism /Image:%defdrive%\WinPE_%SUFFIX%\mount /add-package /packagepath:"%adkpedir%\amd64\WinPE_OCs\WinPE-Scripting.cab" dism /Image:%defdrive%\WinPE_%SUFFIX%\mount /add-package /packagepath:"%adkpedir%\amd64\WinPE_OCs\WinPE-RNDIS.cab" dism /Image:%defdrive%\WinPE_%SUFFIX%\mount /add-package /packagepath:"%adkpedir%\amd64\WinPE_OCs\WinPE-NetFX.cab" dism /Image:%defdrive%\WinPE_%SUFFIX%\mount /add-package /packagepath:"%adkpedir%\amd64\WinPE_OCs\WinPE-PowerShell.cab" dism /Image:%defdrive%\WinPE_%SUFFIX%\mount /add-package /packagepath:"%adkpedir%\amd64\WinPE_OCs\WinPE-DismCmdlets.cab" dism /Image:%defdrive%\WinPE_%SUFFIX%\mount /add-package /packagepath:"%adkpedir%\amd64\WinPE_OCs\WinPE-StorageWMI.cab" dism /Image:%defdrive%\WinPE_%SUFFIX%\mount /add-package /packagepath:"%adkpedir%\amd64\WinPE_OCs\WinPE-WDS-Tools.cab" copy %defdrive%\WinPE_%SUFFIX%\mount\Windows\Boot\PXE\pxeboot.n12 %defdrive%\WinPE_%SUFFIX%\media\Boot\pxeboot.0 copy %defdrive%\WinPE_%SUFFIX%\mount\Windows\Boot\PXE\wdsmgfw.efi %defdrive%\WinPE_%SUFFIX%\media\Boot\wdsmgfw.efi copy %defdrive%\WinPE_%SUFFIX%\mount\Windows\Boot\EFI\bootmgfw.efi %defdrive%\WinPE_%SUFFIX%\media\Boot\bootmgfw.efi copy %defdrive%\WinPE_%SUFFIX%\mount\Windows\Boot\EFI\bootmgr.efi %defdrive%\WinPE_%SUFFIX%\media\Boot\bootmgr.efi copy %defdrive%\WinPE_%SUFFIX%\mount\Windows\Boot\PXE\bootmgr.exe %defdrive%\WinPE_%SUFFIX%\media\ mkdir %defdrive%\WinPE_%SUFFIX%\media\dvd copy "%oscdimg%\etfsboot.com" %defdrive%\WinPE_%SUFFIX%\media\dvd copy "%oscdimg%\efisys_noprompt.bin" %defdrive%\WinPE_%SUFFIX%\media\dvd ::Inject any drivers from C:\drivers into the wim in order to treat them as inbox. rem for /r %defdrive%\drivers %%d in (*.inf) do dism /image:%defdrive%\WinPE_%SUFFIX%\mount /add-driver /driver:%%d if exist %defdrive%\drivers dism /image:%defdrive%\WinPE_%SUFFIX%\mount /add-driver /driver:%defdrive%\drivers /recurse /forceunsigned dism /Unmount-Wim /commit /mountdir:%defdrive%\WinPE_%SUFFIX%\mount move %defdrive%\WinPE_%SUFFIX%\media\Sources\boot.wim %defdrive%\WinPE_%SUFFIX%\media\Boot\WinPE_%SUFFIX%.wim ::Move the c:\WinPE_64\media to c:\WinPE_64\media\winboot\ if is specified (second param) :reorgpath if [%WINPENAME%] NEQ [] rename %defdrive%\WinPE_%SUFFIX%\media origmedia if [%WINPENAME%] NEQ [] md %defdrive%\WinPE_%SUFFIX%\media\winboot if [%WINPENAME%] NEQ [] move %defdrive%\WinPE_%SUFFIX%\origmedia %defdrive%\WinPE_%SUFFIX%\media\winboot if [%WINPENAME%] NEQ [] rename %defdrive%\WinPE_%SUFFIX%\media\winboot\origmedia %WINPENAME% echo Finished generating WinPE and BCD files. goto :eof :errorbadargs echo Specify the architecture on the command line echo Usage: genimage.cmd arch [winpe name] [bcdonly] echo e.g. genimage.cmd amd64 mywinpe echo e.g. genimage.cmd amd64 bcdonly goto :eof :eof