@jimbo45,
After your Little suggestion and a little more fiddling,
I was able to create a reliable CMD file that is doing it exactly the Microsoft way, in both BIOS and UEFI.
Flat.cmd:
Code:
::###########################################################################
::# Title : Flat.cmd #
::# Created By: https://www.tenforums.com/members/malok.html #
::# Created On: 15-Jun-2022 #
::###########################################################################
@Echo Off
Set "Params=%1"
If "%Params%"=="" Goto :Help
Diskpart /s %~dp0\%3.txt
Dism /Apply-Image /ImageFile:%1 /Index:%2 /ApplyDir:W:\
W:\Windows\System32\bcdboot W:\Windows /s S: /f %3
Md R:\Recovery\WindowsRE
Xcopy /h W:\Windows\System32\Recovery\Winre.wim R:\Recovery\WindowsRE\
W:\Windows\System32\Reagentc /Setreimage /Path R:\Recovery\WindowsRE /Target W:\Windows
W:\Windows\System32\Reagentc /Info /Target W:\Windows
Goto :Eof
:Help
Echo.
Echo ======================== Warning =========================
Echo.
Echo This CMD file is used to Ininitalize / Clean hardisk 0.
Echo Automatically apply a Windows image and Create Boot files.
Echo EFI and MBR txt files should be reviewed and edited if needed.
Echo.
Echo flat {source} {Index#} {bios/uefi}
Echo.
Echo flat e:\Sources\Install.wim 6 uefi
Echo.
UEFI.txt:
Code:
rem == CreatePartitions-UEFI.txt ==
rem == These commands are used with DiskPart to
rem create four partitions
rem for a UEFI/GPT-based PC.
rem Adjust the partition sizes to fill the drive
rem as necessary. ==
select disk 0
clean
convert gpt
rem == 1. System partition =========================
create partition efi size=100
rem ** NOTE: For Advanced Format 4Kn drives,
rem change this value to size = 260 **
format quick fs=fat32 label="System"
assign letter="S"
rem == 2. Microsoft Reserved (MSR) partition =======
create partition msr size=16
rem == 3. Windows partition ========================
rem == a. Create the Windows partition ==========
create partition primary
rem == b. Create space for the recovery tools ===
rem ** Update this size to match the size of
rem the recovery tools (winre.wim)
rem plus some free space.
shrink minimum=500
rem == c. Prepare the Windows partition =========
format quick fs=ntfs label="Windows"
assign letter="W"
rem === 4. Recovery partition ======================
create partition primary
format quick fs=ntfs label="Recovery"
assign letter="R"
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
gpt attributes=0x8000000000000001
list volume
exit
BIOS.txt:
Code:
rem == CreatePartitions-BIOS.txt ==
rem == These commands are used with DiskPart to
rem create three partitions
rem for a BIOS/MBR-based computer.
rem Adjust the partition sizes to fill the drive
rem as necessary. ==
select disk 0
clean
rem == 1. System partition ======================
create partition primary size=100
format quick fs=ntfs label="System"
assign letter="S"
active
rem == 2. Windows partition =====================
rem == a. Create the Windows partition =======
create partition primary
rem == b. Create space for the recovery tools
rem ** Update this size to match the size of
rem the recovery tools (winre.wim)
rem plus some free space.
shrink minimum=650
rem == c. Prepare the Windows partition ======
format quick fs=ntfs label="Windows"
assign letter="W"
rem == 3. Recovery tools partition ==============
create partition primary
format quick fs=ntfs label="Recovery"
assign letter="R"
set id=27
list volume
exit
WARNING
This CMD file Will DELETE ALL PARTITIONS on Drive 0 Without questions. Of course you can edit the configuration txt file to apply to any disk you want, you need Drive letters R, S and W to be free to run the command.
The UEFI File should be modified accordingly if you are using 4Kn Disks.
Transcript of an iteration:
Code:
E:\Flat>flat d:\sources\install.wim 6 uefi
Microsoft DiskPart version 10.0.19041.964
Copyright (C) Microsoft Corporation.
On computer: MINWINPC
Disk 0 is now the selected disk.
DiskPart succeeded in cleaning the disk.
DiskPart successfully converted the selected disk to GPT format.
DiskPart succeeded in creating the specified partition.
100 percent completed
DiskPart successfully formatted the volume.
DiskPart successfully assigned the drive letter or mount point.
DiskPart succeeded in creating the specified partition.
DiskPart succeeded in creating the specified partition.
DiskPart successfully shrunk the volume by: 500 MB
100 percent completed
DiskPart successfully formatted the volume.
DiskPart successfully assigned the drive letter or mount point.
DiskPart succeeded in creating the specified partition.
100 percent completed
DiskPart successfully formatted the volume.
DiskPart successfully assigned the drive letter or mount point.
DiskPart successfully set the partition ID.
DiskPart successfully assigned the attributes to the selected GPT partition.
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 D CCCOMA_X64F UDF CD-ROM 5611 MB Healthy
Volume 1 W Windows NTFS Partition 49 GB Healthy
Volume 2 S SYSTEM FAT32 Partition 100 MB Healthy Hidden
* Volume 3 R Recovery NTFS Partition 500 MB Healthy Hidden
Volume 4 E CCCOMA_X64F NTFS Removable 14 GB Healthy
Volume 5 F UEFI_NTFS FAT Removable 1024 KB Healthy
Leaving DiskPart...
Deployment Image Servicing and Management tool
Version: 10.0.19041.844
Applying image
[==========================100.0%==========================]
The operation completed successfully.
Boot files successfully created.
W:\Windows\System32\Recovery\Winre.wim
1 File(s) copied
Directory set to: \\?\GLOBALROOT\device\harddisk0\partition4\Recovery\WindowsRE
REAGENTC.EXE: Operation Successful.
Windows Recovery Environment (Windows RE) and system reset configuration
Information:
Windows RE status: Disabled
Windows RE location:
Boot Configuration Data (BCD) identifier: 00000000-0000-0000-0000-000000000000
Recovery image location:
Recovery image index: 0
Custom image location:
Custom image index: 0
REAGENTC.EXE: Operation Successful.
E:\Flat>
The last output about Windows RE being disabled seems a little confusing. But everything is good upon booting the restored system.