少し前に Media Creatin Tool で作成した Windows 10 を仮想マシンへプロダクトキーの入力をスキップしてインストールしようとしたときに、Windows 7 や Windows 8 のようにはいかず必ずキーを入力しなければ先に進めないことがわかり、これを解決する手段として DISM を使って手動で展開することにしました。(これは古いバージョンの Windows 10 の場合であり、現在はキー無しでインストール可能です。)
その作業をするにあたって以下のリンクを参考に作業を進めました。
サンプル: Windows PE と DiskPart を使って UEFI/GPT ベースのハード ドライブ パーティションを構成する
https://technet.microsoft.com/ja-jp/library/hh825686.aspxサンプル: 展開スクリプトを使用して Windows パーティション、システム パーティション、回復パーティションを適用する
https://technet.microsoft.com/ja-jp/library/hh825089.aspx【追記】日本語のページが消えてなくなりました。なんという改悪
上記のものは Windows 8.1 の情報です。
Windows 10 の場合、Windows RE ツールパーティションのサイズは 450MB 必要です。
【追記】Windows 10 バージョン1803 は 500MB 必要です。
【追記】Windows 10 バージョン1803 は 550MB 必要です。
さて、2番目のリンクの展開スクリプトですが、2017年1月3日現在そのままでは使えません。
rem These commands copy the selected image file to
rem predefined hard disk partitions on a UEFI-based computer.
rem Usage: ApplyImage WimFileName
rem Example: ApplyImage E:\Images\ThinImage.wim
rem === Copy the image to the recovery image partition =======================
copy %1 R:\install.wim
rem === Apply the image to the Windows partition =============================
dism /Apply-Image /ImageFile:R:\install.wim /Index:1 /ApplyDir:W:\
rem === Copy the Windows RE Tools to the Windows RE Tools partition ==========
md T:\Recovery\WindowsRE
copy W:\windows\system32\recovery\winre.wim T:\Recovery\WindowsRE\winre.wim
rem === Copy boot files from the Windows partition to the System partition ===
bcdboot W:\Windows
rem === In the System partition, set the location of the Windows partition ===
W:\Windows\System32\reagentc /setosimage /path R: /target W:\Windows /index 1
rem === In the System partition, set the location of the WinRE tools =========
W:\Windows\System32\reagentc /setreimage /path T:\Recovery\WindowsRE /target W:\Windows
reagentc の /path オプションに指定できるパスはルートディレクトリを指定することができません。つまり、install.wim を R: 直下に配置せずに適当なフォルダを作ってそこに置く必要があります。
また、Winre.wim は隠しファイルなので xcopy を使用してコピーします。ついでに BCD のロケールも日本語に設定するようにし、また、セットアップを使わずに DISM で Windows イメージを適応したときに、Windows の初回起動時にキーボード ドライバーが英語になっている問題も解決します。
rem These commands copy the selected image file to
rem predefined hard disk partitions on a UEFI-based computer.
rem Usage: ApplyImage WimFileName
rem Example: ApplyImage E:\Images\ThinImage.wim
rem === Copy the image to the recovery image partition =======================
md R:\RecoveryImage
copy %1 R:\RecoveryImage\install.wim
rem === Apply the image to the Windows partition =============================
dism /Apply-Image /ImageFile:R:\RecoveryImage\install.wim /Index:1 /ApplyDir:W:\
rem === Copy the Windows RE Tools to the Windows RE Tools partition ==========
md T:\Recovery\WindowsRE
xcopy /h W:\Windows\System32\Recovery\Winre.wim T:\Recovery\WindowsRE\
rem === Copy boot files from the Windows partition to the System partition ===
bcdboot W:\Windows /l ja-jp
dism /Image:W:\ /Set-LayeredDriver:6
rem === In the System partition, set the location of the Windows partition ===
W:\Windows\System32\reagentc /setosimage /path R:\RecoveryImage /target W:\Windows /index 1
rem === In the System partition, set the location of the WinRE tools =========
W:\Windows\System32\reagentc /setreimage /path T:\Recovery\WindowsRE /target W:\Windows
Windows PE 上から dism /Apply-Image を実行すると失敗する場合は、Windows PE が起動している RAM ディスクのサイズが小さく一時ファイルが置けないので、Windows PE のスクラッチスペースを変更します。
設定できるサイズは 32、64、128、256、512MB で、メモリに余裕があれば 512MB に設定することをお勧めします。
スクラッチスペースを変更しなくてもいい方法もありますが、その方法については後述します。
例:
Windows PEイメージの場所が「C:\WinPE\install.wim」、コマンドプロンプトのカレントディレクトリが「C:\WinPE」、Windows PEイメージをマウントする場所が「C:\WinPE\mount」の場合
dism /Mount-Image /ImageFile:install.wim /Index:1 /MountDir:mount
dism /Image:mount /Set-ScratchSpace:512
dism /Unmount-Image /MountDir:mount /Commit
スクラッチスペースを変更しない方法。スクラッチディレクトリを任意の場所を指定するオプションを使用します。
dism /Apply-Image /ImageFile:R:\RecoveryImage\install.wim /ScratchDir:R:\Temp /Index:1 /ApplyDir:W:\
rd /s /q R:\Temp
WIM を適用しようとしているボリュームにスクラッチディレクトリを設定することはできないので、上記の方法ではリカバリーイメージ用のボリュームに一時フォルダを作りましたが、リカバリーイメージ用のパーティションを作らない場合は工夫が必要です。
Windows 用のパーティションを縮小し、仮のパーティションを作りそこに一時フォルダを作り、作業が終わったら仮のパーティションを削除して Windows 用のパーティションを拡大するようにします。
echo select disk 0 > CreateTempPartition.txt
echo select partition 4 >> CreateTempPartition.txt
echo shrink minimum=10000 >> CreateTempPartition.txt
echo create partition primary >> CreateTempPartition.txt
echo format quick fs=ntfs >> CreateTempPartition.txt
echo assign letter=R >> CreateTempPartition.txt
echo exit >> CreateTempPartition.txt
diskpart /s CreateTempPartition.txt
<中略>
echo select disk 0 > DeleteTempPartition.txt
echo select partition 5 >> DeleteTempPartition.txt
echo remove letter=R >> DeleteTempPartition.txt
echo delete partition >> DeleteTempPartition.txt
echo select partition 4 >> DeleteTempPartition.txt
echo extend >> DeleteTempPartition.txt
echo exit >> DeleteTempPartition.txt
diskpart /s DeleteTempPartition.txt
<後略>