Windows – WinPE (Windows ADK)

Loading

WinPE 或是 Windows PE 都是指 Windows Preinstallation Environment , 他就像是 Windows 版本的 LiveCD (可以透過 USB 或是 PXE 等方式) 來啟動一個精簡的 Windows 系統,目前版本為 10.0.17134.1 ( April 2018 update version) Built from Windows 10 (1803) code base ,版本歷史可以參考 https://en.wikipedia.org/wiki/Windows_Preinstallation_Environment

這 WinPE 要去哪裡下載,可以在 https://docs.microsoft.com/zh-tw/windows-hardware/get-started/adk-install#winADK 找適合的版本.

Windows 10 ADK (Assessment and Deployment Kit) 版本 1803 內容包含了:

  • Windows Assessment Toolkit 以及 Windows Performance Toolkit to assess the quality and performance of systems or components.
  • Deployment tools such as WinPE, Sysprep, and other tools that you can use to customize and deploy Windows 10 images.

測試環境為 Windows 10 x86_64 (虛擬機)

working files

第一步需要先透過指令 copype 建立一個 WinPE 工作環境 (平台可以選擇 x86 , amd64 , arm , arm64, 路徑 c:\WinPE 自訂),在程式集 Windows kits 點選 Deployment and Imaging Tools Environment .

C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools>copype amd64 c:\WinPE
...
C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Pre
installation Environment\amd64\Media\zh-tw\bootmgr.efi.mui
155 File(s) copied
        1 file(s) copied.
        1 file(s) copied.
        1 file(s) copied.
Success

我們來看看目錄 c:\WinPE 多了什麼檔案.

C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools>dir c:\WinPE
 Volume in drive C has no label.
 Volume Serial Number is 9286-6452

 Directory of c:\WinPE

09/19/2018  06:49 PM    <DIR>          .
09/19/2018  06:49 PM    <DIR>          ..
09/19/2018  05:21 PM    <DIR>          fwfiles
09/19/2018  05:21 PM    <DIR>          media
09/19/2018  05:21 PM    <DIR>          mount
09/19/2018  06:49 PM       298,008,576 WinPE_x86.iso
               1 File(s)    298,008,576 bytes
               5 Dir(s)  47,055,261,696 bytes free
  • fwfiles 資料夾
    • efisys.bin
      Efisys.bin is the binary floppy disk layout of the EFI boot code.
    • etfsboot.com
  • media 內含 media\sources 下的檔案 boot.wim 就是 winPE 最基礎的檔案.
  • mount 為空資料夾,主要是將 WinPE 映像檔掛載時用的.

建立 WinPE

建立 WinPE 需要透過 指令 MakeWinPEMedia,目標可以為 USB Flash Drive (需指定裝置位置) 或是 iso 檔案 (可用於 CD / DVD 或是 PXE Boot 來使用)

C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools>MakeWinPEMedia
Creates bootable WinPE USB flash drive or ISO file.

MakeWinPEMedia {/ufd | /iso} [/f] <workingDirectory> <destination>

 /ufd              Specifies a USB Flash Drive as the media type.
                   NOTE: THE USB FLASH DRIVE WILL BE FORMATTED.
 /iso              Specifies an ISO file (for CD or DVD) as the media type.
 /f                Suppresses prompting to confirm formatting the UFD
                   or overwriting existing ISO file.
 workingDirectory  Specifies the working directory created using copype.cmd
                   The contents of the <workingDirectory>\media folder
                   will be copied to the UFD or ISO.
 destination       Specifies the UFD volume or .ISO path and file name.

 Examples:
   MakeWinPEMedia /UFD C:\WinPE_amd64 G:
   MakeWinPEMedia /UFD /F C:\WinPE_amd64 H:
   MakeWinPEMedia /ISO C:\WinPE_x86 C:\WinPE_x86\WinPE_x86.iso
  1. 建立 WinPE USB Flash Drive
    UFD : USB Flash Drive ,並指定裝置位置 E:

    C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools>MakeWinPEMedia /UFD c:\WinPE E:
    
  2. 建立 WinPE iso 檔
    C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools>MakeWinPEMedia /iso C:\WinPE c:\WinPE\WinPE_x86.iso
    Creating c:\WinPE\WinPE_x86.iso...
    
    100% complete
    
    Success
    

    iso 檔如果要應用到 PXE 請參考

客製化 (Patch) WinPE

在 c:\WinPE\media\sources 資料夾下檔案 boot.wim 就是最基礎 winPE Windows images.

如果需要做修改 WinPE 內容需要透過指令 DISM (Deployment Image Servicing and Management) – 指令需要有 administrator 權限,可以透過 command prompt (run as adminstrator).把 Windows images 映像檔 boot.wim 掛載起來.

如果以前有使用過舊版的掛載指令, PEimg, Intlcfg, ImageX 等..現在全部都由 DISM 來取代了.

  • 掛載
    C:\Windows\system32>Dism /Mount-Image /ImageFile:"C:\WinPE\media\sources\boot.wim" /index:1 /MountDir:"C:\WinPE\mount"
    Deployment Image Servicing and Management tool
    Version: 6.3.9600.16384
    
    Mounting image
    [==========================100.0%==========================]
    The operation completed successfully.
    
    C:\Windows\system32>dir c:\WinPE\mount
     Volume in drive C has no label.
     Volume Serial Number is 9286-6452
    
     Directory of c:\WinPE\mount
    
    04/12/2018  06:13 AM    <DIR>          .
    04/12/2018  06:13 AM    <DIR>          ..
    04/12/2018  06:13 AM    <DIR>          Program Files
    04/12/2018  06:13 AM    <DIR>          Program Files (x86)
    04/12/2018  06:13 AM    <DIR>          Users
    04/12/2018  06:14 AM    <DIR>          Windows
                   0 File(s)              0 bytes
                   6 Dir(s)  46,977,515,520 bytes free
    

    在微軟官網 – https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-mount-and-customize 說明了幾種修改 WinPE 內容總類.

    • Add an update (DISM /add-driver)
      需要驅動程式 .inf 檔.

      C:\Windows\system32>Dism /Add-Driver /Image:"C:\WinPE\mount" /Driver:"C:\SampleDriver\driver.inf"
      
    • Add packages/languages/optional components/.cab files (DISM /add-package)
      需要 .cab 檔.下面範例為新增 PowerShell 到 Windows PE 裡面.
      至於有哪一些 WinPE Optional Components 可以使用,詳細請參考 https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-add-packages–optional-components-reference

      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFX.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFX_en-us.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-Scripting_en-us.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-PowerShell.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-PowerShell_en-us.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-StorageWMI.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-StorageWMI_en-us.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-DismCmdlets.cab"
      C:\Windows\system32>Dism /Add-Package /Image:"C:\WinPE\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-DismCmdlets_en-us.cab"
      

      開機到 Windows PE 之後執行下面指令就可以使用 Windows PowerShell

      X:\Windows\system32\WindowsPowerShell\v1.0\powershell
      

      除了 PowerShell 外還有哪一些 WinPE Optional Components 可以選擇,請參考官網說明 – https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-add-packages–optional-components-reference

    • Add files and folders
      如果只是單純要加檔案到 WinPE 裡面,只需將檔案放置 WinPE 掛載點,這裡範例為 C:\WinPE\mount
    • Add a startup script
      WinPE 開機後會依據 Startnet.cmd 檔案內容依序執行工作 (該檔案內容可以自訂).
      預設內容如下.

      C:\Windows\system32>cat C:\WinPE\mount\Windows\System32\Startnet.cmd
      wpeinit
      

      除了 Startnet.cmd 可以自訂工作行程,還可以利用 Winpeshl.ini (存放路徑為 %SYSTEMROOT%\System32 當有設定時系統會忽略 Startnet.cmd ) ,或是透過 unattend.xml (Answer file) 來進行自動安裝 – https://benjr.tw/345

  • 卸載
    修改,新增好之後依樣是透過 Dism 卸載.

    C:\Windows\system32>Dism /Unmount-Image /MountDir:"C:\WinPE\mount" /commit
    Deployment Image Servicing and Management tool
    Version: 6.3.9600.16384
    
    Saving image
    [==========================100.0%==========================]
    Unmounting image
    [==========================100.0%==========================]
    The operation completed successfully.
    
  • 建立 WinPE
    最後還需要再次透過 指令 MakeWinPEMedia 建立新的 WinPE 開機磁碟.

    C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools>MakeWinPEMedia /UFD c:\WinPE E:
    

    或是建立 iso 檔

    C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools>MakeWinPEMedia /iso C:\WinPE c:\WinPE\WinPE_x86.iso
    

遇過的錯誤訊息

  • 指令 Dism 錯誤
    之前在 Windows 2012 R2 x86_64 平台安裝 Windows 10 ADK ,可以安裝,但是使用 Dism /Add-Package 會出現以下的錯誤訊息.

    Error: 50
    
    To service this Windows image requires the latest version of the DISM. See http://go.microsoft.com/fwlink/?LinkId=293395 to find the latest version of DISM,and http://go.microsoft.com/fwlink/?LinkId=293394 to learn how to install the latest version of DISM from the ADK on your computer.
    
    The DISM log file can be found at C:\Windows\Logs\DISM\dism.log
    

    檢視文章的說明檔案, Windows Server 2012 R2 只支援到 Windows PE 5.0 (x86 or x64) ,如果要使用 Windows 10 ADK 還是需要在 Windows 10 系統下操作.

  • 新增套件錯誤
    Deployment Image Servicing and Management tool
    Version: 10.0.16299.15
    
    Image Version: 10.0.17134.1
    
    Processing 1 of 1 - Adding package WinPE-WMI-Package~31bf3856ad364e35~amd64~~10.0.17134.1
    [==========================100.0%==========================]
    
    Error: 0x800f081e
    
    The specified package is not applicable to this image.
    
    The DISM log file can be found at C:\Windows\Logs\DISM\dism.log
    

    ARM 平台新增套件時錯用了 x86 套件.

  • 無法 mount / umount
    有時候會遇到 umount / mount 的時候,顯示錯誤訊息而無法繼續下去.

    C:\Windows\system32>Dism /Unmount-Image /MountDir:"C:\PE\mount" /commit
    
    Deployment Image Servicing and Management tool
    Version: 10.0.16299.15
    
    Saving image
    [==========================100.0%==========================]
    Unmounting image
    [==========================100.0%==========================]
    
    Error: 0xc1420117
    
    The directory could not be completely unmounted.  This is usually due to applications that still have files opened within the mount directory.  Close these files and unmount again to complete the unmount process.
    
    The DISM log file can be found at C:\Windows\Logs\DISM\dism.log
    
    C:\Windows\system32>Dism /Mount-Image /ImageFile:"C:\PE\media\sources\boot.wim" /index:1 /MountDir:"C:\PE\mount"
    
    Deployment Image Servicing and Management tool
    Version: 10.0.16299.15
    
    
    Error: 0xc1420127
    
    The specified image in the specified wim is already mounted for read/write access.
    
    The DISM log file can be found at C:\Windows\Logs\DISM\dism.log
    
    C:\Windows\system32>Dism /Mount-Image /ImageFile:"C:\PE\media\sources\boot.wim" /index:1 /MountDir:"C:\PE\mount"
    
    Deployment Image Servicing and Management tool
    Version: 10.0.16299.15
    
    
    Error: 0xc1420127
    
    The specified image in the specified wim is already mounted for read/write access.
    
    The DISM log file can be found at C:\Windows\Logs\DISM\dism.log
    

    這時候可以使用下面的指令,把 c 槽下所有的掛載點全部移除.

    C:\Windows\system32>dism /Cleanup-Mountpoints
    
    Deployment Image Servicing and Management tool
    Version: 10.0.16299.15
    
    Cleaning up image
    Unmounting image at C:\PE\mount
    [==========================100.0%==========================]
    Unmounting image at C:\$Recycle.Bin\S-1-5-21-2714281036-1574557606-3780765203-1000\$RH1WSDZ\mount
    [==========================100.0%==========================]
    Stale mount entry pointing to C:\WinPE\mount removed
    Stale mount entry pointing to C:\WinPE\mount removed
    Scanning drive C for stale files
    The operation completed successfully.
    
沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料