Deploy WIMBoot Images

WIMBoot磁區規劃


以下是WMIBoot的磁區規劃,比較重要的是Images這個磁區,依照以下指令會建立10GB的空間來放置WIMBoot Images,如果需要更大的空間可以修改shrink minimum=10000的值,但相對來說會壓縮到前一個Windows磁區,以下是各個磁區的規畫建議

 

磁區規劃內容


System (EFI System Partition): Size: 100MB.

  • If the primary drive is less than 16GB, you can use a minimum size of 32MB.

  • If the primary drive is an Advanced Format 4K Native drive (4-KB-per-sector), the minimum size is 260 MB.


MSR (x86 and x64 only, not needed for ARM)

Windows.

Images. Set this partition with the following attributes:

  • Location: End of the disk

  • Type: de94bba4-06d1-4d40-a16a-bfd50179d6ac (PARTITION_MSFT_RECOVERY_GUID)

  • Attributes: 0x8000000000000001 (GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER & GPT_ATTRIBUTE_PLATFORM_REQUIRED)

  • File system: NTFS

  • Drive Letter: Set a temporary drive letter, for example, M.

  • Size: Must be big enough to hold install.wim, winre.wim, and custom.wim files plus at least 50 MB of free space.



diskpart指令分割磁區


以下指令會規畫C為系統磁區、M為映像檔磁區,如果是透過其他硬碟將install.wim和winre.wim佈署近來,會發生其他硬碟已經先佔用C磁碟標籤的問題,所以必須先將C磁碟標籤空出來,再做後續的磁區分割。

 

1. 如果有佔用C磁碟標籤的問題請先執行以下這幾行,select volume請依實際情況修改數值
rem == list all volume ==
list volume
rem == select external disk volume ==
select volume 1
rem == remove volume letter C ==
Remove
rem == assign letter N to external disk volume ==
assign letter=n

2. 將以下指令儲存在CreatePartitions-WIMBoot.txt
rem == Diskpart /s CreatePartitions-WIMBoot.txt ==
rem == These commands set up the hard drive partitions
rem for WIMBoot.
rem
rem Adjust the partition sizes to fill the drive
rem as necessary. ==
select disk 0
clean
convert gpt
rem == 1. System partition (ESP) ===================
create partition efi size=100
format quick fs=fat32 label="System"
rem == 2. Microsoft Reserved (MSR) partition =======
create partition msr size=128
rem == 3. Windows partition ========================
create partition primary
shrink minimum=10000
format quick fs=ntfs label="Windows"
assign letter=c
rem === 4. Images partition ========================
create partition primary
format quick fs=ntfs label="Images"
assign letter=m
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
gpt attributes=0x8000000000000001
list volume
Exit

3. 使用diskpart指令完成以上的磁區分割
diskpart /s N:\CreatePartitions-WIMBoot.txt

 

佈署WIMBoot


1. 在Images磁區M:建立Windows Images資料夾
md "M:\Windows Images\"

2. 從外接硬碟磁區N:複製install_wimboot.wim到M:\Windows Images\
copy N:\Images\install_wimboot.wim "M:\Windows Images\install.wim"

3. 新增暫存資料夾C:\Recycler\Scratch,提供給DISM執行檔案的暫存位置;套用Windows image到Windows磁區並加入/WIMBoot參數,必須要注意的是Images磁區必須要和系統磁區位於同個硬碟上,套用後也不能將install.wim做移動會造成無法開機。
md C:\Recycler\Scratch
DISM /Apply-Image /ImageFile:"M:\Windows Images\install.wim" /ApplyDir:C: /Index:1 /WIMBoot /ScratchDir:C:\Recycler\Scratch

4. 建立開機檔案
C:\Windows\System32\bcdboot C:\Windows

5. 建立M:\Recovery\WindowsRE資料夾,並將winre.wim複製到該資料夾
md M:\Recovery\WindowsRE
echo f | xcopy N:\Images\winre.wim M:\Recovery\WindowsRE\winre.wim /h

6. 註冊WindowsRE的位置
C:\Windows\System32\Reagentc /SetREImage /Path M:\Recovery\WindowsRE /Target C:\Windows

 

佈署WIMBoot Script


1. 將以下內容儲存在ApplyWIMBootImage.cmd
@echo off
echo == ApplyWIMBootImage.cmd ==

echo == These commands deploy a specified Windows
echo image file to the Windows partition, and configure
echo the system partition.

rem Usage: ApplyWIMBootImage InstallWim WinREWim
rem Example: ApplyWIMBootImage N:\Images\Install-WIMBoot.wim N:\Images\WinRE-WIMBoot.wim

if "%2" equ "" (
echo == Error: Specify a Windows image and a Windows RE image file.
echo Example: ApplyWIMBootImage N:\Images\Install-WIMBoot.wim N:\Images\WinRE-WIMBoot.wim
exit /b 0
)
@echo on

rem == Add the Windows image to the Images partition ==
md "M:\Windows Images\"
copy %1 "M:\Windows Images\install.wim"

rem == Create a scratch directory for DISM operations
md "C:\Recycler\Scratch"

rem == Apply the Windows image to the Windows partition ==
dism /Apply-Image /ImageFile:"M:\Windows Images\install.wim" /ApplyDir:C: /Index:1 /WIMBoot /ScratchDir:C:\Recycler\Scratch

rem == Create boot files on the System partition ==
C:\Windows\System32\bcdboot C:\Windows

rem == Add the Windows RE image to the Images partition ==
md M:\Recovery\WindowsRE
copy %2 M:\Recovery\WindowsRE\winre.wim

rem == Register the location of the recovery tools ==
C:\Windows\System32\Reagentc /SetREImage /Path M:\Recovery\WindowsRE /Target C:\Windows

2. 使用指令方式ApplyWIMBootImage.cmd [Windows image位置] [WinRE位置]
ApplyWIMBootImage.cmd N:\Images\install_wimboot.wim N:\Images\winre.wim

 

擷取custom.wim到factory floor(選用)


custom.wim和install.wim的關係如同差異備份或Hyper-V還原點的概念,install.wim包含所有的系統檔案,而在install.wim佈署後所做的變更,這些變更包含安裝更新、應用程式、語言包等等,就會透過DISM /Capture-CustomImage指令,將這些變更封裝成另一個custom.wim,所以custom.wim無法單獨運行必須依附在install.wim,但相對來說如果不需要這些變更,也可以只單獨佈署install.wim到client端。

 

custom.wim注意事項


1. custom.wim無法獨立運作,因為custom.wim無法替換掉install.wim檔案

2. custom.wim和install.wim必須在同個資料夾,不可以在擷取後將custom.wim移出

3. 擷取後不可以移除或重新擷取custom.wim,如果需要修改custom.wim請重新操作佈署建置

 

custom.wim擷取步驟


1. 進入到OOBE的畫面請不要選擇語言、輸入法和時區,直接按鍵盤的 CTRL+SHIFT+F3 會自動重開機進入稽核模式(audit mode)

2. 在稽核模式(audit mode)安裝更新、應用程式、語言包等等,另外需要注意的是在稽核模式(audit mode)無法透過Windows Update安裝更新,只能手動下載安裝或是透過 Windows Update PowerShell Module ,變更得越多會造成custom.wim越大,如果超過Images磁區的大小會造成擷取失敗

3. 再次執行封裝,封裝完畢會自動關機
C:\Windows\System32\Sysprep\Sysprep /OOBE /shutdown /generalize

4. 再次開機進入Windows PE 5.1

6. 擷取custom.wim到factory floor
DISM /Capture-CustomImage /CaptureDir:C: /ScratchDir:C:\Recycler\Scratch

7. 移除scratch資料夾
rd C:\Recycler /s /q

 

保護WIMBoot資料夾


透過變更資料夾權限為唯獨來保護WIMBoot資料夾
icacls "M:\Windows Images" /inheritance:r /T
icacls "M:\Windows Images" /grant:r SYSTEM:(R) /T
icacls "M:\Windows Images" /grant:r *S-1-5-32-544:(R) /T

如果要讓資料夾可以進行讀寫,擁有"完全控制"的權限請執行以下指令
icacls "M:\Windows Images" /grant:r SYSTEM:(F) /T
icacls "M:\Windows Images" /grant:r *S-1-5-32-544:(F) /T

確認資料夾的權限
icacls "M:\Windows Images"

 

如何確認電腦是否從WIM開機


方法一:磁碟管理


可以在磁區上看到 [ Wim Boot ]


方法二:透過指令


fsutil wim enumwims c:

如果是WIM Boot會看到以下的資訊

留言

這個網誌中的熱門文章

Create WIMBoot Images

Android 5.1 無痛升級和Root教學