Universal Windows 11 Deployment & Bootloader Provisioning Toolkit (UEFI / MBR)


Ramesh Sharma

Well-known member
Member
Local time
1:32 PM
Posts
298
OS
Window 11 v24H2 Build 26100.2033
Hello Everyone,
Welcome,

Universal Windows 11 Deployment & Bootloader Provisioning Toolkit (UEFI / MBR)
Created and Developed in collaboration with Google Gemini AI

Overview:
This toolkit provides a complete, 100% native batch-driven framework for deploying Windows 11 images directly from WinPE or Live Windows environments. It supports both modern UEFI (GPT) and Legacy BIOS (MBR) architectures, offers automated and non-destructive disk options, handles dynamic BCD pointer resolution, provisions fallback bootloaders, and includes deep post-deployment verification.

Zero external dependencies or third-party binaries required. All volume parsing and disk queries run directly via pure Windows CMD commands and native DiskPart script redirection, making it fully compatible with minimal WinPE environments where utilities like `findstr.exe` are missing.

---

Key Features:
1. Three Disk Deployment Modes:
- Option 1 (Non-destructive): Deploys directly to an existing partition without wiping; auto-appends multi-boot entries.
- Option 2 (Clean MBR): Converts disk to MBR, provisions a 500 MB Active "System Reserved" partition and OS volume.
- Option 3 (Clean GPT/UEFI): Converts disk to GPT, provisions a 260 MB FAT32 EFI System Partition (ESP), 16 MB MSR, and OS volume.
2. Disk-to-Volume Association: `create_uefi.bat` associates parent disk numbers with FAT32 volumes so you never target the wrong EFI partition on multi-drive rigs.
3. UEFI Fallback Provisioning: Automatically writes both primary `\EFI\Microsoft\Boot\bootmgfw.efi` and fallback `\EFI\Boot\bootx64.efi` for stubborn motherboard firmwares.
4. BCD Dynamic Pointer Fix: Automatically converts unresolved `{default}` dynamic "locate" pointers into fixed physical partitions.
5. Automated Verification Suite: Validates critical kernel binaries (`ntoskrnl.exe`, `winload.efi`, `winload.exe`), registry hives (`SYSTEM`, `SOFTWARE`), mounts EFI/System Reserved partitions, and displays all registered OS loaders.

---

1. deploy_win11.bat (Main Deployment Engine)
Code:
@Echo off
Title Universal Windows 11 Deployment Utility (UEFI / MBR)
Setlocal EnableDelayedExpansion

:: Ensure System32 binaries are always in PATH
Set "PATH=%SystemRoot%\System32;%SystemRoot%;%PATH%"

:: 1. Locate install.wim across drives
Set "WIM_PATH="
For %%i in (C D E F G H I J K L M N O P Q R S T U V W Y Z) Do (
    If Exist "%%i:\sources\install.wim" (
        Set "WIM_PATH=%%i:\sources\install.wim"
        Goto :FoundWim
    )
    If Exist "%%i:\sources\install.esd" (
        Set "WIM_PATH=%%i:\sources\install.esd"
        Goto :FoundWim
    )
)

:FoundWim
If not defined WIM_PATH (
    Echo [FAIL] Neither install.wim nor install.esd found on any available drive.
    Pause
    Exit /B 1
)

:: 2. Display available editions and indexes
Echo.
Echo ===============================================================================
Echo Available Editions in %WIM_PATH%:
Echo ===============================================================================
dism /Get-ImageInfo /ImageFile:"%WIM_PATH%"
Echo ===============================================================================
Echo.

:: 3. Prompt user for the target index
Set "INDEX_NUM=1"
Set /p "INDEX_NUM=Enter the Index number to install [default: 1]: "

:: 4. Disk Configuration Menu
Echo.
Echo ===============================================================================
Echo Disk Configuration:
Echo ===============================================================================
Echo [1] Use an existing partition [no wipe]
Echo [2] Wipe an entire disk and create MBR [System Reserved + OS]
Echo [3] Wipe an entire disk and create GPT [EFI + MSR + OS]
Echo ===============================================================================
Set "DISK_CONFIG=1"
Set /p "DISK_CONFIG=Enter choice [1, 2, or 3, default: 1]: "

If "%DISK_CONFIG%"=="2" Goto :PartitionDiskMBR
If "%DISK_CONFIG%"=="3" Goto :PartitionDiskGPT
Goto :SelectExisting

:: -------------------------------------------------------------------------------
:: Branch A: Wipe and Partition as MBR
:: -------------------------------------------------------------------------------
:PartitionDiskMBR
Echo.
(Echo lis dis) | diskpart
Echo.

:SelectDiskNumMBR
Set "TARGET_DISK="
Set /p "TARGET_DISK=Enter the DISK NUMBER to completely wipe and format as MBR: "
If not defined TARGET_DISK Goto :SelectDiskNumMBR

Set "CHECK_DIGIT=%TARGET_DISK%"
For /F "delims=0123456789" %%A in ("%CHECK_DIGIT%") Do Set "CHECK_DIGIT="
If not defined CHECK_DIGIT (
    Echo Invalid input. Please enter numbers only.
    Goto :SelectDiskNumMBR
)

Echo.
Echo *******************************************************************************
Echo WARNING: ALL DATA ON DISK %TARGET_DISK% WILL BE PERMANENTLY ERASED [MBR]!
Echo *******************************************************************************
Set /p "CONFIRM=Type YES to proceed with wipe: "
If /I not "%CONFIRM%"=="YES" (
    Echo Disk partitioning aborted by user.
    Goto :SelectExisting
)

(Echo sel vol S & Echo remove noerr & Echo sel vol W & Echo remove noerr) | diskpart >nul 2>&1

Set "DP_SCRIPT=%TEMP%\mbr_setup.txt"
>"%DP_SCRIPT%" Echo sel dis %TARGET_DISK%
>>"%DP_SCRIPT%" Echo clean
>>"%DP_SCRIPT%" Echo convert mbr
>>"%DP_SCRIPT%" Echo create partition primary size=500
>>"%DP_SCRIPT%" Echo format quick fs=ntfs label="System Reserved"
>>"%DP_SCRIPT%" Echo active
>>"%DP_SCRIPT%" Echo assign letter=S
>>"%DP_SCRIPT%" Echo create partition primary
>>"%DP_SCRIPT%" Echo format quick fs=ntfs label="Windows"
>>"%DP_SCRIPT%" Echo assign letter=W

Echo.
Echo Partitioning and formatting Disk %TARGET_DISK% as MBR...
diskpart /s "%DP_SCRIPT%" >nul 2>&1
Del "%DP_SCRIPT%" >nul 2>&1

Set "TARGET_DRIVE=W"
Set "BOOT_MODE=2"
Set "HAS_SYS_RES=1"
Echo [PASS] Disk %TARGET_DISK% partitioned as MBR. Target OS drive is W:\.
Goto :ApplyOS

:: -------------------------------------------------------------------------------
:: Branch B: Wipe and Partition as GPT (UEFI)
:: -------------------------------------------------------------------------------
:PartitionDiskGPT
Echo.
(Echo lis dis) | diskpart
Echo.

:SelectDiskNumGPT
Set "TARGET_DISK="
Set /p "TARGET_DISK=Enter the DISK NUMBER to completely wipe and format as GPT: "
If not defined TARGET_DISK Goto :SelectDiskNumGPT

Set "CHECK_DIGIT=%TARGET_DISK%"
For /F "delims=0123456789" %%A in ("%CHECK_DIGIT%") Do Set "CHECK_DIGIT="
If not defined CHECK_DIGIT (
    Echo Invalid input. Please enter numbers only.
    Goto :SelectDiskNumGPT
)

Echo.
Echo *******************************************************************************
Echo WARNING: ALL DATA ON DISK %TARGET_DISK% WILL BE PERMANENTLY ERASED [GPT/UEFI]!
Echo *******************************************************************************
Set /p "CONFIRM=Type YES to proceed with wipe: "
If /I not "%CONFIRM%"=="YES" (
    Echo Disk partitioning aborted by user.
    Goto :SelectExisting
)

(Echo sel vol S & Echo remove noerr & Echo sel vol W & Echo remove noerr) | diskpart >nul 2>&1

Set "DP_SCRIPT=%TEMP%\gpt_setup.txt"
>"%DP_SCRIPT%" Echo sel dis %TARGET_DISK%
>>"%DP_SCRIPT%" Echo clean
>>"%DP_SCRIPT%" Echo convert gpt
>>"%DP_SCRIPT%" Echo create partition efi size=260
>>"%DP_SCRIPT%" Echo format quick fs=fat32 label="System"
>>"%DP_SCRIPT%" Echo assign letter=S
>>"%DP_SCRIPT%" Echo create partition msr size=16
>>"%DP_SCRIPT%" Echo create partition primary
>>"%DP_SCRIPT%" Echo format quick fs=ntfs label="Windows"
>>"%DP_SCRIPT%" Echo assign letter=W

Echo.
Echo Partitioning and formatting Disk %TARGET_DISK% as GPT...
diskpart /s "%DP_SCRIPT%" >nul 2>&1
Del "%DP_SCRIPT%" >nul 2>&1

Set "TARGET_DRIVE=W"
Set "BOOT_MODE=1"
Set "HAS_SYS_RES=1"
Echo [PASS] Disk %TARGET_DISK% partitioned as GPT. Target OS drive is W:\.
Goto :ApplyOS

:: -------------------------------------------------------------------------------
:: Branch C: Select Existing Volume
:: -------------------------------------------------------------------------------
:SelectExisting
Echo.
Echo ===============================================================================
Echo Available Volumes:
Echo ===============================================================================
(Echo lis vol) | diskpart
Echo ===============================================================================
Echo.

:PromptTarget
Set "TARGET_DRIVE=D"
Set /p "TARGET_DRIVE=Enter the target drive letter to install to [default: D]: "
Set "TARGET_DRIVE=%TARGET_DRIVE:~0,1%"

If not Exist "%TARGET_DRIVE%:\" (
    Echo [FAIL] Drive %TARGET_DRIVE%:\ does not exist. Please check the volume list.
    Goto :PromptTarget
)

Echo.
Echo ===============================================================================
Echo Select Firmware / Boot Mode for Existing Drive:
Echo ===============================================================================
Echo [1] UEFI [GPT - Writes to EFI System Partition]
Echo [2] MBR / Legacy BIOS [Auto-detect System Reserved or existing boot store]
Echo [3] MBR / Legacy BIOS [Standalone - write bootmgr directly to %TARGET_DRIVE%:]
Echo ===============================================================================
Set "BOOT_MODE=1"
Set /p "BOOT_MODE=Enter choice [1, 2, or 3, default: 1]: "
Set "HAS_SYS_RES=0"
Set "EXISTING_BOOT_VOL="

If "%BOOT_MODE%"=="2" (
    :: Search for an unlettered System Reserved partition without findstr
    Set "TMP_DP_LIST=%TEMP%\dp_mbr_%RANDOM%.txt"
    Set "TMP_DP_OUT=%TEMP%\dp_mbrout_%RANDOM%.txt"
    (Echo list volume) > "!TMP_DP_LIST!"
    diskpart /s "!TMP_DP_LIST!" > "!TMP_DP_OUT!" 2>&1

    For /f "tokens=1,2,3,4,5,6,7*" %%A in ('type "!TMP_DP_OUT!"') Do (
        If /i "%%A"=="Volume" (
            Set "IS_SYS="
            If /i "%%C"=="System" Set "IS_SYS=1"
            If /i "%%D"=="System" Set "IS_SYS=1"
            If /i "%%C"=="System Rese" Set "IS_SYS=1"
           
            If defined IS_SYS (
                (Echo select volume %%B & Echo assign letter=S) | diskpart >nul 2>&1
                If Exist "S:\Boot\BCD" (
                    Set "EXISTING_BOOT_VOL=S:"
                    Set "HAS_SYS_RES=1"
                )
            )
        )
    )
    Del /f /q "!TMP_DP_LIST!" "!TMP_DP_OUT!" >nul 2>&1

    :: Check fixed local drives C: or D: as fallback
    If not defined EXISTING_BOOT_VOL (
        For %%D in (C D) Do (
            If Exist "%%D:\Boot\BCD" Set "EXISTING_BOOT_VOL=%%D:"
        )
    )
)

Goto :ApplyOS

:: -------------------------------------------------------------------------------
:: 5. Image Extraction via DISM
:: -------------------------------------------------------------------------------
:ApplyOS
Cls
Echo ===============================================================================
Echo Applying Image
Echo ===============================================================================
Echo Source WIM    : %WIM_PATH%
Echo Selected Index: %INDEX_NUM%
Echo Target Drive  : %TARGET_DRIVE%:\
Echo ===============================================================================
Echo.
Echo Extracting Windows files... [This may take several minutes]
Echo.

dism /Apply-Image /ImageFile:"%WIM_PATH%" /Index:%INDEX_NUM% /ApplyDir:%TARGET_DRIVE%:\
If %errorlevel% neq 0 (
    Echo.
    Echo [FAIL] DISM failed to apply the image [Error Level: %errorlevel%].
    Pause
    Goto :Cleanup
)

Echo.
Echo [PASS] Image applied successfully to %TARGET_DRIVE%:\.

:: -------------------------------------------------------------------------------
:: 6. Boot Configuration
:: -------------------------------------------------------------------------------
If "%BOOT_MODE%"=="1" (
    Goto :ConfigureUEFI
) Else (
    Goto :ConfigureMBR
)

:ConfigureUEFI
Echo.
Echo ===============================================================================
Echo Configuring UEFI Bootloader and NVRAM
Echo ===============================================================================

If Exist "%~dp0create_uefi.bat" (
    Echo Launching create_uefi.bat for target %TARGET_DRIVE%: ...
    Call "%~dp0create_uefi.bat" %TARGET_DRIVE%:
    Goto :PostBootCheck
)

If not exist "S:\" (
    Echo [*] Locating EFI System Partition (FAT32)...
    Set "ESP_VOL="
    Set "TMP_DP_LIST=%TEMP%\dp_fat_%RANDOM%.txt"
    Set "TMP_DP_OUT=%TEMP%\dp_fatout_%RANDOM%.txt"
    (Echo list volume) > "!TMP_DP_LIST!"
    diskpart /s "!TMP_DP_LIST!" > "!TMP_DP_OUT!" 2>&1

    For /f "tokens=1,2,3,4,5,6,7*" %%A in ('type "!TMP_DP_OUT!"') Do (
        If /i "%%A"=="Volume" (
            Set "IS_FAT="
            If /i "%%D"=="FAT32" Set "IS_FAT=1"
            If /i "%%E"=="FAT32" Set "IS_FAT=1"
            If /i "%%F"=="FAT32" Set "IS_FAT=1"
            If defined IS_FAT (
                Set "RAW_V=%%B"
                Set "ESP_VOL=!RAW_V: =!"
            )
        )
    )
    Del /f /q "!TMP_DP_LIST!" "!TMP_DP_OUT!" >nul 2>&1

    If defined ESP_VOL (
        (Echo sel vol !ESP_VOL! & Echo assign letter=S) | diskpart >nul 2>&1
    )
)

If not Exist "S:\" (
    Echo [FAIL] Could not mount FAT32 EFI partition to S:.
    Goto :End
)

If Exist "S:\EFI\Microsoft\Boot\BCD" attrib -s -h -r "S:\EFI\Microsoft\Boot\BCD" >nul 2>&1
"%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s S: /f UEFI
If %errorlevel% equ 0 (
    Echo [PASS] UEFI boot files written successfully.
    If not Exist "S:\EFI\Boot" mkdir "S:\EFI\Boot"
    If Exist "S:\EFI\Microsoft\Boot\bootmgfw.efi" (
        copy /y "S:\EFI\Microsoft\Boot\bootmgfw.efi" "S:\EFI\Boot\bootx64.efi" >nul 2>&1
        Echo [PASS] Created fallback bootx64.efi.
    )
    "%SystemRoot%\System32\bcdedit.exe" /enum firmware >nul 2>&1
    If !errorlevel! equ 0 (
        "%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s S: /f UEFI /p >nul 2>&1
        Echo [PASS] NVRAM entry synchronized.
    )
) Else (
    Echo [FAIL] bcdboot failed to write UEFI boot files.
)

(Echo sel vol S & Echo remove letter=S) | diskpart >nul 2>&1
Goto :PostBootCheck

:ConfigureMBR
Echo.
If defined EXISTING_BOOT_VOL (
    Echo [*] Updating existing bootloader on %EXISTING_BOOT_VOL%...
    "%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s %EXISTING_BOOT_VOL% /f BIOS
    If %errorlevel% equ 0 (
        Echo [PASS] Appended new OS entry to existing BCD on %EXISTING_BOOT_VOL%.
    ) Else (
        Echo [FAIL] BCDBoot failed to update %EXISTING_BOOT_VOL%.
    )
    If "%HAS_SYS_RES%"=="1" (
        (Echo select volume S & Echo remove letter=S) | diskpart >nul 2>&1
    )
    Goto :PostBootCheck
)

If "%HAS_SYS_RES%"=="1" (
    Echo Configuring MBR boot files on System Reserved partition...
    "%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s S: /f BIOS
    If !errorlevel! equ 0 (
        Echo [PASS] MBR bootloader configured on System Reserved.
    ) Else (
        Echo [FAIL] BCDboot failed to write boot files to S:.
    )
    (Echo sel vol S & Echo remove letter=S) | diskpart >nul 2>&1
) Else (
    Echo Configuring MBR boot files directly on %TARGET_DRIVE%:\...
    "%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s %TARGET_DRIVE%: /f BIOS
    If !errorlevel! equ 0 (
        (Echo sel vol %TARGET_DRIVE% & Echo active) | diskpart >nul 2>&1
        Echo [PASS] MBR bootloader configured on %TARGET_DRIVE%:.
    ) Else (
        Echo [FAIL] BCDboot failed to write MBR boot files.
    )
)
Goto :PostBootCheck

:: -------------------------------------------------------------------------------
:: 7. Resolve Any Dynamic Locate Pointers in BCD
:: -------------------------------------------------------------------------------
:PostBootCheck
Echo.
Echo [*] Checking BCD for dynamic locate pointers...
For /f "tokens=1,2" %%A in ('"%SystemRoot%\System32\bcdedit.exe" /enum osloader') Do (
    If /i "%%A"=="identifier" (
        Set "ENTRY_ID=%%B"
        For /f "tokens=1,2*" %%X in ('"%SystemRoot%\System32\bcdedit.exe" /enum !ENTRY_ID!') Do (
            If /i "%%X"=="osdevice" (
                Set "DEV_VAL=%%Y"
                If /i "!DEV_VAL:~0,6!"=="locate" (
                    Echo [*] Resolving dynamic locate pointer for entry !ENTRY_ID!...
                    "%SystemRoot%\System32\bcdedit.exe" /set !ENTRY_ID! device partition=%TARGET_DRIVE%: >nul 2>&1
                    "%SystemRoot%\System32\bcdedit.exe" /set !ENTRY_ID! osdevice partition=%TARGET_DRIVE%: >nul 2>&1
                )
            )
        )
    )
)
Echo [PASS] BCD validation completed.
Goto :End

:Cleanup
If "%HAS_SYS_RES%"=="1" (
    (Echo sel vol S & Echo remove letter=S) | diskpart >nul 2>&1
)

:End
Echo.
Echo ===============================================================================
Echo Deployment Process Complete.
Echo Calling Verification Script...
Echo ===============================================================================

If Exist "%~dp0verify_deploy.bat" (
    Call "%~dp0verify_deploy.bat" %TARGET_DRIVE%:
) Else (
    Echo [WARN] verify_deploy.bat not found in %~dp0. Skipping automatic verification.
    Pause
)
Exit /B 0

---

2. create_uefi.bat (EFI & Fallback Provisioner)
Code:
@echo off
setlocal EnableDelayedExpansion

set "PATH=%SystemRoot%\System32;%SystemRoot%;%PATH%"

title UEFI Bootloader and NVRAM Fallback Provisioner
echo ============================================================
echo        UEFI Bootloader and NVRAM Fallback Provisioner
echo ============================================================
echo.

set "TARGET_WIN=%~1"
if "%TARGET_WIN%"=="" (
    echo Available Drives with a Windows directory:
    for %%D in (C D E F G H I J K L M N O P Q R S T U V W Y Z) do (
        if exist "%%D:\Windows\System32\ntoskrnl.exe" (
            echo   - %%D:\Windows
        )
    )
    echo.
    set /p "TARGET_WIN=Enter Target Windows Drive Letter [e.g. K:]: "
)

if "%TARGET_WIN%"=="" (
    echo [ERROR] No target drive specified.
    goto :FAIL
)

set "TARGET_WIN=%TARGET_WIN:~0,1%:"

if not exist "%TARGET_WIN%\Windows\System32\ntoskrnl.exe" (
    echo [ERROR] No valid Windows installation found on %TARGET_WIN%.
    goto :FAIL
)
echo [OK] Verified target Windows on %TARGET_WIN%.
echo.

set "ESP_LTR=S"
set "TMP_DP_PROBE=%TEMP%\dp_probe_%RANDOM%.txt"
set "TMP_DP_OUT=%TEMP%\dp_out_%RANDOM%.txt"

echo [*] Scanning disks for FAT32 EFI partitions...

(
    echo list disk
    echo list volume
) > "%TMP_DP_PROBE%"
diskpart /s "%TMP_DP_PROBE%" > "%TMP_DP_OUT%" 2>&1
del /f /q "%TMP_DP_PROBE%" >nul 2>&1

set "TMP_DP_MAP=%TEMP%\dp_map_%RANDOM%.txt"
set "TMP_DP_MAP_OUT=%TEMP%\dp_mapout_%RANDOM%.txt"

> "%TMP_DP_MAP%" (
    for /f "tokens=1,2" %%A in ('type "%TMP_DP_OUT%"') do (
        if /i "%%A"=="Disk" (
            set "CHK_NUM=%%B"
            for /f "delims=0123456789" %%Z in ("!CHK_NUM!") do set "CHK_NUM="
            if defined CHK_NUM (
                echo select disk %%B
                echo detail disk
            )
        )
    )
)
diskpart /s "%TMP_DP_MAP%" > "%TMP_DP_MAP_OUT%" 2>&1
del /f /q "%TMP_DP_MAP%" >nul 2>&1

set "CURR_DSK="
for /f "tokens=1,2,3*" %%A in ('type "%TMP_DP_MAP_OUT%"') do (
    if /i "%%A"=="Disk" if not "%%B"=="" (
        set "CHK_NUM=%%B"
        for /f "delims=0123456789" %%Z in ("!CHK_NUM!") do set "CHK_NUM="
        if defined CHK_NUM set "CURR_DSK=%%B"
    )
    if /i "%%A"=="Volume" (
        set "VOL_DISK_%%B=!CURR_DSK!"
    )
)
del /f /q "%TMP_DP_MAP_OUT%" >nul 2>&1

echo.
echo ===============================================================================
echo Potential FAT32 EFI Partitions:
echo ===============================================================================
echo   Disk #   Volume ###  Ltr  Label        Fs     Type        Size     Status
echo   -------  ----------  ---  -----------  -----  ----------  -------  ---------

for /f "tokens=1,2,3,4,5,6,7,8*" %%A in ('type "%TMP_DP_OUT%"') do (
    if /i "%%A"=="Volume" (
        set "IS_FAT="
        if /i "%%D"=="FAT32" set "IS_FAT=1"
        if /i "%%E"=="FAT32" set "IS_FAT=1"
        if /i "%%F"=="FAT32" set "IS_FAT=1"
        if defined IS_FAT (
            set "V_NUM=%%B"
            set "D_NUM=!VOL_DISK_%%B!"
            if not defined D_NUM set "D_NUM=?"
            echo   Disk !D_NUM!   %%A %%B    %%C  %%D  %%E  %%F  %%G  %%H
        )
    )
)
echo ===============================================================================
del /f /q "%TMP_DP_OUT%" >nul 2>&1
echo.

set "ESP_VOL="
set /p "ESP_VOL=Enter FAT32 EFI Volume Number to provision: "
if "%ESP_VOL%"=="" (
    echo [ERROR] No volume number entered.
    goto :FAIL
)

echo [OK] Target EFI Volume selected: %ESP_VOL%
echo.

echo [*] Mounting Volume %ESP_VOL% to %ESP_LTR%:...
(echo select volume %ESP_VOL% & echo assign letter=%ESP_LTR% noerr) | diskpart >nul 2>&1
ping -n 3 127.0.0.1 >nul 2>&1

vol %ESP_LTR%: >nul 2>&1
if errorlevel 1 (
    echo [ERROR] Failed to mount Volume %ESP_VOL% to %ESP_LTR%:.
    goto :FAIL
)
echo [OK] EFI Partition mounted on %ESP_LTR%:.
echo.

echo [*] Running bcdboot to populate UEFI boot files...
bcdboot %TARGET_WIN%\Windows /s %ESP_LTR%: /f UEFI /p
if errorlevel 1 (
    echo [ERROR] bcdboot execution failed.
    goto :CLEANUP
)
echo [OK] Boot files successfully created.

echo [*] Provisioning default UEFI fallback bootloader...
if not exist "%ESP_LTR%:\EFI\Boot" mkdir "%ESP_LTR%:\EFI\Boot"

if exist "%ESP_LTR%:\EFI\Microsoft\Boot\bootmgfw.efi" (
    copy /y "%ESP_LTR%:\EFI\Microsoft\Boot\bootmgfw.efi" "%ESP_LTR%:\EFI\Boot\bootx64.efi" >nul
    echo [OK] Created %ESP_LTR%:\EFI\Boot\bootx64.efi
) else (
    echo [WARN] bootmgfw.efi not found to duplicate.
)
echo.

echo [*] Checking NVRAM access...
wmic /namespace:\\root\wmi path MS_SystemInformation get SystemBiosMajorVersion >nul 2>&1
if errorlevel 1 (
    echo [INFO] NVRAM write access restricted in current environment.
    echo [INFO] Relying on fallback loader bootx64.efi.
) else (
    echo [*] UEFI mode active. Synchronizing NVRAM table...
    bcdedit /store "%ESP_LTR%:\EFI\Microsoft\Boot\BCD" /set {bootmgr} description "Windows Boot Manager" >nul 2>&1
    echo [OK] Motherboard NVRAM entry synced.
)
echo.

:CLEANUP
echo [*] Unmounting %ESP_LTR%:...
cd /d "%TEMP%"
(echo select volume %ESP_LTR% & echo remove letter=%ESP_LTR% noerr) | diskpart >nul 2>&1
echo [OK] %ESP_LTR%: unmounted cleanly.
echo.

echo ============================================================
echo [SUCCESS] UEFI Bootloader Provisioning Complete.
echo ============================================================
echo.
pause
goto :END

:FAIL
echo.
echo ============================================================
echo [FAIL] Execution aborted or encountered errors.
echo ============================================================
echo.
pause
exit /b 1

:END
exit /b 0

---

3. verify_deploy.bat (Universal Verification Suite)
Code:
@echo off
setlocal EnableDelayedExpansion

set "PATH=%SystemRoot%\System32;%SystemRoot%;%PATH%"

title Universal Deployment Verification Utility (UEFI / MBR)
echo ============================================================
echo      Universal Deployment Verification Utility (UEFI / MBR)
echo ============================================================
echo.

set "DEFAULT_DRV=%~1"
if "%DEFAULT_DRV%"=="" set "DEFAULT_DRV=%SystemDrive%"
if "%DEFAULT_DRV%"=="" set "DEFAULT_DRV=C:"

echo Available Drives with a Windows directory:
for %%D in (C D E F G H I J K L M N O P Q R S T U V W Y Z) do (
    if exist "%%D:\Windows\System32\ntoskrnl.exe" (
        echo   - %%D:\Windows
    )
)
echo.
set /p "TGT_WIN=Enter Target Windows Drive Letter [default: %DEFAULT_DRV%]: "
if "%TGT_WIN%"=="" set "TGT_WIN=%DEFAULT_DRV%"
set "TGT_WIN=%TGT_WIN:~0,1%:"

echo Target selected: %TGT_WIN%\
echo.

echo [*] Verifying Windows System Files on %TGT_WIN%\...
set "CORE_FAIL=0"

for %%F in (ntoskrnl.exe winresume.efi winload.efi winload.exe) do (
    if exist "%TGT_WIN%\Windows\System32\%%F" (
        echo [PASS] Found: %%F
    )
)

for %%H in (SYSTEM SOFTWARE) do (
    if exist "%TGT_WIN%\Windows\System32\config\%%H" (
        echo [PASS] Found: Registry Hive %%H
    ) else (
        echo [FAIL] Missing: Registry Hive %%H
        set "CORE_FAIL=1"
    )
)

if "%CORE_FAIL%"=="1" (
    echo [ERROR] Core Windows registry files are missing on %TGT_WIN%.
    goto :CLEANUP_EXIT
)
echo [RESULT] Core Windows system files successfully verified.
echo.

echo ============================================================
echo Select Boot Mode to Verify:
echo ============================================================
echo [1] UEFI (GPT - ESP FAT32 partition and EFI BCD Store)
echo [2] MBR  (Legacy BIOS - bootmgr and Active partition)
set /p "BOOT_MODE=Enter choice [1 or 2, default: 1]: "
if "%BOOT_MODE%"=="" set "BOOT_MODE=1"

echo.
if "%BOOT_MODE%"=="1" goto :VERIFY_UEFI
if "%BOOT_MODE%"=="2" goto :VERIFY_MBR
goto :CLEANUP_EXIT

:VERIFY_UEFI
echo ============================================================
echo Verifying UEFI Bootloader Configuration
echo ============================================================

set "S_DRV=S:"
set "AUTO_MOUNTED=0"

if exist "%S_DRV%\EFI\Microsoft\Boot\BCD" (
    echo [*] EFI Partition already accessible on %S_DRV%
    goto :RUN_UEFI_CHECKS
)

echo [*] Locating EFI System Partition...

set "TMP_DP_LST=%TEMP%\dp_lst_%RANDOM%.txt"
set "TMP_DP_RES=%TEMP%\dp_res_%RANDOM%.txt"

echo list volume > "!TMP_DP_LST!"
diskpart /s "!TMP_DP_LST!" > "!TMP_DP_RES!" 2>&1
del /f /q "!TMP_DP_LST!" >nul 2>&1

set "ESP_VOL="
for /f "tokens=1,2,3,4,5,6,7*" %%A in ('type "!TMP_DP_RES!"') do (
    if /i "%%A"=="Volume" (
        set "IS_FAT="
        if /i "%%D"=="FAT32" set "IS_FAT=1"
        if /i "%%E"=="FAT32" set "IS_FAT=1"
        if /i "%%F"=="FAT32" set "IS_FAT=1"
       
        if defined IS_FAT (
            set "IS_REM=0"
            if /i "%%E"=="Removable" set "IS_REM=1"
            if /i "%%F"=="Removable" set "IS_REM=1"
            if /i "%%G"=="Removable" set "IS_REM=1"
            if "!IS_REM!"=="0" if not defined ESP_VOL (
                set "RAW_V=%%B"
                set "ESP_VOL=!RAW_V: =!"
            )
        )
    )
)
del /f /q "!TMP_DP_RES!" >nul 2>&1

if not defined ESP_VOL (
    echo [!] Could not auto-detect EFI partition volume.
    set /p "ESP_VOL=Enter FAT32 EFI Volume Number to verify: "
)

if not defined ESP_VOL (
    echo [FAIL] No volume selected.
    goto :CLEANUP_EXIT
)

echo [*] Mounting Volume !ESP_VOL! to S:...
set "TMP_DP_MNT=%TEMP%\dp_mnt_%RANDOM%.txt"
echo select volume !ESP_VOL!> "!TMP_DP_MNT!"
echo assign letter=S>> "!TMP_DP_MNT!"
diskpart /s "!TMP_DP_MNT!" >nul 2>&1
del /f /q "!TMP_DP_MNT!" >nul 2>&1
set "AUTO_MOUNTED=1"

ping -n 3 127.0.0.1 >nul 2>&1

:RUN_UEFI_CHECKS
set "MOUNTED_OK="
if exist "%S_DRV%\" set "MOUNTED_OK=1"
if exist "%S_DRV%\EFI" set "MOUNTED_OK=1"
if exist "%S_DRV%\EFI\Microsoft\Boot\BCD" set "MOUNTED_OK=1"
if not defined MOUNTED_OK (
    vol %S_DRV% >nul 2>&1 && set "MOUNTED_OK=1"
)

if not defined MOUNTED_OK (
    echo [FAIL] EFI partition is not accessible on %S_DRV%.
    goto :CLEANUP_EXIT
)

if exist "%S_DRV%\EFI\Microsoft\Boot\bootmgfw.efi" (
    echo [PASS] EFI bootloader found: %S_DRV%\EFI\Microsoft\Boot\bootmgfw.efi
) else (
    echo [FAIL] EFI bootloader missing: %S_DRV%\EFI\Microsoft\Boot\bootmgfw.efi
)

if exist "%S_DRV%\EFI\Boot\bootx64.efi" (
    echo [PASS] Fallback bootloader found: %S_DRV%\EFI\Boot\bootx64.efi
) else (
    echo [WARN] Fallback bootloader missing: %S_DRV%\EFI\Boot\bootx64.efi
)

if exist "%S_DRV%\EFI\Microsoft\Boot\BCD" (
    echo [PASS] UEFI BCD Store verified.
    echo.
    echo [*] Registered Boot Loaders:
    for /f "tokens=1,2*" %%A in ('bcdedit /store "%S_DRV%\EFI\Microsoft\Boot\BCD" /enum osloader') do (
        if /i "%%A"=="identifier" echo %%A              %%B
        if /i "%%A"=="device"     echo %%A                  %%B
        if /i "%%A"=="path"       echo %%A                    %%B
        if /i "%%A"=="osdevice"   echo %%A                %%B
    )
) else (
    echo [FAIL] UEFI BCD Store missing at %S_DRV%\EFI\Microsoft\Boot\BCD
)

if "%AUTO_MOUNTED%"=="1" (
    cd /d "%TEMP%"
    set "TMP_DP_UNM=%TEMP%\dp_unm_%RANDOM%.txt"
    echo select volume S> "!TMP_DP_UNM!"
    echo remove letter=S noerr>> "!TMP_DP_UNM!"
    diskpart /s "!TMP_DP_UNM!" >nul 2>&1
    del /f /q "!TMP_DP_UNM!" >nul 2>&1
    echo [PASS] Unmounted S: cleanly.
)
goto :CLEANUP_EXIT

:VERIFY_MBR
echo ============================================================
echo Verifying MBR Bootloader Configuration
echo ============================================================

set "MBR_TARGET="
set "MBR_AUTO_MOUNTED=0"

for %%D in (S C D %TGT_WIN:~0,1%) do (
    if exist "%%D:\bootmgr" (
        if exist "%%D:\Boot\BCD" (
            set "MBR_TARGET=%%D:"
            goto :RUN_MBR_CHECKS
        )
    )
)

echo [*] Searching for unlettered System Reserved partition...
set "SYS_RES_VOL="

set "TMP_DP_LST=%TEMP%\dp_lst_%RANDOM%.txt"
set "TMP_DP_RES=%TEMP%\dp_res_%RANDOM%.txt"

echo list volume > "!TMP_DP_LST!"
diskpart /s "!TMP_DP_LST!" > "!TMP_DP_RES!" 2>&1
del /f /q "!TMP_DP_LST!" >nul 2>&1

for /f "tokens=1,2,3,4,5,6,7*" %%A in ('type "!TMP_DP_RES!"') do (
    if /i "%%A"=="Volume" (
        set "IS_NTFS="
        if /i "%%D"=="NTFS" set "IS_NTFS=1"
        if /i "%%E"=="NTFS" set "IS_NTFS=1"
        if /i "%%F"=="NTFS" set "IS_NTFS=1"

        set "IS_SYS="
        if /i "%%C"=="System" set "IS_SYS=1"
        if /i "%%D"=="System" set "IS_SYS=1"
        if /i "%%C"=="System Rese" set "IS_SYS=1"

        if defined IS_NTFS if defined IS_SYS (
            if not defined SYS_RES_VOL (
                set "RAW_SV=%%B"
                set "SYS_RES_VOL=!RAW_SV: =!"
            )
        )
    )
)
del /f /q "!TMP_DP_RES!" >nul 2>&1

if not defined SYS_RES_VOL (
    echo [WARN] Could not find partition labeled "System Reserved".
    goto :RUN_MBR_CHECKS
)

echo [*] Found System Reserved as Volume !SYS_RES_VOL!. Mounting to S:...
set "TMP_DP_MNT=%TEMP%\dp_mnt_%RANDOM%.txt"
echo select volume !SYS_RES_VOL!> "!TMP_DP_MNT!"
echo assign letter=S>> "!TMP_DP_MNT!"
diskpart /s "!TMP_DP_MNT!" >nul 2>&1
del /f /q "!TMP_DP_MNT!" >nul 2>&1

ping -n 3 127.0.0.1 >nul 2>&1

set "MBR_MOUNTED_OK="
if exist "S:\" set "MBR_MOUNTED_OK=1"
if not defined MBR_MOUNTED_OK (
    vol S: >nul 2>&1 && set "MBR_MOUNTED_OK=1"
)

if not defined MBR_MOUNTED_OK (
    echo [FAIL] Failed to assign S: to Volume !SYS_RES_VOL!.
) else (
    set "MBR_TARGET=S:"
    set "MBR_AUTO_MOUNTED=1"
    echo [PASS] Successfully mounted Volume !SYS_RES_VOL! to S:.
)

:RUN_MBR_CHECKS
if not defined MBR_TARGET set "MBR_TARGET=%TGT_WIN%"

echo.
echo Target boot volume being verified: %MBR_TARGET%\

if exist "%MBR_TARGET%\bootmgr" (
    echo [PASS] Found bootmgr at %MBR_TARGET%\bootmgr
) else (
    echo [FAIL] Missing bootmgr at %MBR_TARGET%\bootmgr
)

if exist "%MBR_TARGET%\Boot\BCD" (
    echo [PASS] MBR BCD Store verified at %MBR_TARGET%\Boot\BCD
    echo.
    echo [*] Registered Boot Loaders:
    for /f "tokens=1,2*" %%A in ('bcdedit /store "%MBR_TARGET%\Boot\BCD" /enum osloader') do (
        if /i "%%A"=="identifier" echo %%A              %%B
        if /i "%%A"=="device"     echo %%A                  %%B
        if /i "%%A"=="path"       echo %%A                    %%B
        if /i "%%A"=="osdevice"   echo %%A                %%B
    )
) else (
    echo [FAIL] MBR BCD Store missing at %MBR_TARGET%\Boot\BCD
)

cd /d "%TEMP%"
if "%MBR_AUTO_MOUNTED%"=="1" (
    echo.
    echo [*] Unmounting temporary drive S:...
    set "TMP_DP_UNM=%TEMP%\dp_unm_%RANDOM%.txt"
    echo select volume S> "!TMP_DP_UNM!"
    echo remove letter=S noerr>> "!TMP_DP_UNM!"
    diskpart /s "!TMP_DP_UNM!" >nul 2>&1
    del /f /q "!TMP_DP_UNM!" >nul 2>&1
    echo [PASS] Unmounted S: cleanly.
)

:CLEANUP_EXIT
echo.
echo ============================================================
echo Verification Complete.
echo ============================================================
echo.
pause
exit /b 0

PROCEDURE TO USE BATCH FILES
Code:
1. Place all three batch files,attached below, deploy_win11.bat, create_uefi.bat, verify_deploy.bat in the same folder like "BATCH FILES" or in the root drive of Windows 11 boot disk(FAT32/NTFS X: AND/OR Y:)(See the complete procedure of making Windows 11 v26H2 boot media at the end of this text file, below) You can copy the code of these file and paste them in Notepad to save as ALL FILES>ANSI. Copy the code of deploy_win11.bat and paste it in Notepad. Click All Files , select ANSI and save as "deploy_win11.bat". Same for create_uefi.bat and veriry_deploy.bat

2. Boot from Windows 11 boot disk. At country/region selection screen, press Shift+F10.

3. X:\sources>diskpart
  
   DISKPART>list volume
  
   OR RUN ANY ONE OF FOLOWING COMMANDS TO FIND DRIVE LETTER OF WINDOWS 11 BOOT MEDIA(FAT32/NTFS)
 
   {X:\sources>for %i in (c D E F G H I J K L M N O P Q R S T U V W X Y Z)do @if exist %i:\sources\install.wim echo Found at %i
   Found at J
   X:\sources>for %i in (c D E F G H I J K L M N O P Q R S T U V W X Y Z)do @if exist %i:\sources\boot.wim echo Found at %i
   Found at F
   X:\sources>for %i in (c D E F G H I J K L M N O P Q R S T U V W X Y Z)do @if exist %i:\sources\install.esd echo Found at %i
   Found at K


4. Note the drive letter of boot disk. In my case it is J: And type exit to leave diskpart.

5. X:\sources>J:

6: J:>cd BATCH FILES

7. J:\BATCH FILES>deploy_win11.bat
  
   { OR J:>deploy_win11.bat if all three are in root drive of Windows 11 boot media.}
   {After image applied , other two batch files are called automatically.}
   {deploy_win11.bat , create_uefi.bat, verify_deploy.bat can be run independently within live os. User can run any     
   batch file from live os.This is helpful to check/repair efi, system reserved partition or windows core files.
8. User has to input index number, drive letter,disk number following corresponding commands.

9. User can install Windows 11 v26H2 in MBR (or GPT) in disk 0.Also user can install Windows 11 v26H2 in disk 1 in GPT(or MBR) parition style. If Disk 0 has                                               MBR installation and Disk 1 has GPT installation user has to select disk o or disk 1 as boot option 1. Disk 0 or Disk 1 can be selected as boot option 1.

10.User can install more than one Windows 11 on Disk 0 or Disk 1. In such case select option "No Wipe" for dual or multi installations.

11.Please backup your data on pc/laptop before applying these files.

12.Procedure to make Windows 11 boot media :-
   Download Windows 11 v26H2 iso from Microsoft website. Mount it to virtual drive.
   Attach pen/usb drive 32 GB .Run CMD as administrator.
   C:\Windows\system32>diskpart
   DISKPART> list volume
   DISKPART> select disk #(correct drive number of blank usb drive 1,2,3 in your pc/laptop.)
   DISKPART>clean
   DISKPART>convert mbr
   DISKPART>create partition primary size=2048
   DISKPART>create partition primary
   DISKPART>select partition 1
   DISKPART>format fs=FAT32 label="BOOT"
   DISKPART>assign letter=X
   DISKPART>active
   DISKPART>select partition 2
   DISKPART>format fs=NTFS label="INSTALL"
   DISKPART>assign letter=Y
   DISKPART>exit

13.From contents of mounted iso of Windows 11, copy all files and folders to Y: Select all files and folders, excluding 'sources' folder from mounted iso     and paste them in X: Make a folder named "sources" in X: From Y: cut file "boot.wim" and paste it into X:\sources. Three batch files deploy_win11.bat,  create_uefi.bat, verify_deploy.bat can be place in X:\BATCH FILES or Y:\BATCH FILES. Or simply in X: or Y: Done.

14 . Copy deploy_win11.bat, create_uefi.bat, verify_deploy.bat to same folder {BATCH FILES} or root drive of Windows 11 boot media{ X: OR Y:}

15. After running diskpart>list volume, we know drive letter. If it is J then
    X:\sources>J:
    J:>cd BATCH FILES
    J:\BATCH FILES>deploy_win11.bat
    OR J:>deploy_win11.bat {if deploy_win11.bat, create_uefi.bat, and verify_deploy.bat are placed in root drive (X: or Y: while in live os)

MBR WORKFLOW
Code:
===============================================================================
Applying Image
===============================================================================
Source WIM    : G:\sources\install.wim
Selected Index: 1
Target Drive  : I:\
===============================================================================

Extracting Windows files... [This may take several minutes]


Deployment Image Servicing and Management tool
Version: 10.0.26100.8972

Applying image
[==========================100.0%==========================]
The operation completed successfully.

[PASS] Image applied successfully to I:\.

[*] Updating existing bootloader on S:...
Boot files successfully created.
[PASS] Appended new OS entry to existing BCD on S:.

[*] Checking BCD for dynamic locate pointers...
[PASS] BCD validation completed.

===============================================================================
Deployment Process Complete.
Calling Verification Script...
===============================================================================
============================================================
     Universal Deployment Verification Utility (UEFI / MBR)
============================================================

Available Drives with a Windows directory:
  - C:\Windows
  - D:\Windows
  - E:\Windows

Enter Target Windows Drive Letter [default: C:]: C
Target selected: C:\

[*] Verifying Windows System Files on C:\...
[PASS] Found: ntoskrnl.exe
[PASS] Found: winresume.efi
[PASS] Found: winload.efi
[PASS] Found: winload.exe
[PASS] Found: Registry Hive SYSTEM
[PASS] Found: Registry Hive SOFTWARE
[RESULT] Core Windows system files successfully verified.

============================================================
Select Boot Mode to Verify:
============================================================
[1] UEFI (GPT - ESP FAT32 partition and EFI BCD Store)
[2] MBR  (Legacy BIOS - bootmgr and Active partition)
Enter choice [1 or 2, default: 1]: 2

============================================================
Verifying MBR Bootloader Configuration
============================================================
[*] Searching for unlettered System Reserved partition...
[*] Found System Reserved as Volume 1. Mounting to S:...
[PASS] Successfully mounted Volume 1 to S:.

Target boot volume being verified: S:\
[PASS] Found bootmgr at S:\bootmgr
[PASS] MBR BCD Store verified at S:\Boot\BCD

[*] Registered Boot Loaders:
identifier              {0cea54fa-cac7-11f1-90ba-aad710e4b29a}
device                  partition=C:
path                    \Windows\system32\winload.exe
osdevice                partition=C:
identifier              {default}
device                  partition=I:
path                    \Windows\system32\winload.exe
osdevice                partition=I:
identifier              {f32cbfc2-cac0-11f1-9298-ee870943cf00}
device                  ramdisk=[C:]\Recovery\WindowsRE\Winre.wim,{f32cbfc3-cac0-11f1-9298-ee870943cf00}
path                    \windows\system32\winload.exe
osdevice                ramdisk=[C:]\Recovery\WindowsRE\Winre.wim,{f32cbfc3-cac0-11f1-9298-ee870943cf00}

[*] Unmounting temporary drive S:...
[PASS] Unmounted S: cleanly.

============================================================
Verification Complete.
============================================================

Press any key to continue . . .

===============================================================================
Applying Image
===============================================================================
Source WIM    : J:\sources\install.wim
Selected Index: 6
Target Drive  : G:\
===============================================================================

Extracting Windows files... [This may take several minutes]


Deployment Image Servicing and Management tool
Version: 10.0.26100.8972

Applying image
[==========================100.0%==========================]
The operation completed successfully.

[PASS] Image applied successfully to G:\.

[*] Updating existing bootloader on S:...
Boot files successfully created.
[PASS] Appended new OS entry to existing BCD on S:.

[*] Checking BCD for dynamic locate pointers...
[PASS] BCD validation completed.

===============================================================================
Deployment Process Complete.
Calling Verification Script...
===============================================================================
============================================================
     Universal Deployment Verification Utility (UEFI / MBR)
============================================================

Available Drives with a Windows directory:
  - D:\Windows
  - E:\Windows
  - G:\Windows
  - H:\Windows

Enter Target Windows Drive Letter [default: X:]: G
Target selected: G:\

[*] Verifying Windows System Files on G:\...
[PASS] Found: ntoskrnl.exe
[PASS] Found: winresume.efi
[PASS] Found: winload.efi
[PASS] Found: winload.exe
[PASS] Found: Registry Hive SYSTEM
[PASS] Found: Registry Hive SOFTWARE
[RESULT] Core Windows system files successfully verified.

============================================================
Select Boot Mode to Verify:
============================================================
[1] UEFI (GPT - ESP FAT32 partition and EFI BCD Store)
[2] MBR  (Legacy BIOS - bootmgr and Active partition)
Enter choice [1 or 2, default: 1]: 2

============================================================
Verifying MBR Bootloader Configuration
============================================================
[*] Searching for unlettered System Reserved partition...
[*] Found System Reserved as Volume 1. Mounting to S:...
[PASS] Successfully mounted Volume 1 to S:.

Target boot volume being verified: S:\
[PASS] Found bootmgr at S:\bootmgr
[PASS] MBR BCD Store verified at S:\Boot\BCD

[*] Registered Boot Loaders:
identifier              {0cea54fa-cac7-11f1-90ba-aad710e4b29a}
device                  partition=H:
path                    \Windows\system32\winload.exe
osdevice                partition=H:
identifier              {default}
device                  partition=G:
path                    \Windows\system32\winload.exe
osdevice                partition=G:
identifier              {671bacc5-cb7e-11f1-b4f1-9014f5bfc0a3}
device                  ramdisk=[I:]\Recovery\WindowsRE\Winre.wim,{671bacc6-cb7e-11f1-b4f1-9014f5bfc0a3}
path                    \windows\system32\winload.exe
osdevice                ramdisk=[I:]\Recovery\WindowsRE\Winre.wim,{671bacc6-cb7e-11f1-b4f1-9014f5bfc0a3}
identifier              {e7273918-cb12-11f1-929a-00e04f0fa4d0}
device                  partition=I:
path                    \Windows\system32\winload.exe
osdevice                partition=I:
identifier              {f32cbfc2-cac0-11f1-9298-ee870943cf00}
device                  ramdisk=[H:]\Recovery\WindowsRE\Winre.wim,{f32cbfc3-cac0-11f1-9298-ee870943cf00}
path                    \windows\system32\winload.exe
osdevice                ramdisk=[H:]\Recovery\WindowsRE\Winre.wim,{f32cbfc3-cac0-11f1-9298-ee870943cf00}

[*] Unmounting temporary drive S:...
[PASS] Unmounted S: cleanly.

============================================================
Verification Complete.
============================================================

Press any key to continue . . .


GPT WORKFLOW
Code:
X:\sources>DISKPART

Microsoft DiskPart version 10.0.26100.1150

Copyright (C) Microsoft Corporation.
On computer: MININT-H4VLA33

DISKPART> LIST VOLUME

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     K                       DVD-ROM         0 B  No Media
  Volume 1     C   System Rese  NTFS   Partition    500 MB  Healthy
  Volume 2     H   Windows      NTFS   Partition    247 GB  Healthy
  Volume 3     I   TEST 1       NTFS   Partition    296 GB  Healthy
  Volume 4     G   TEST 2       NTFS   Partition    387 GB  Healthy
  Volume 5     D   Windows      NTFS   Partition     59 GB  Healthy
  Volume 6     E   Windows Hom  NTFS   Partition     59 GB  Healthy
  Volume 7         SYSTEM       FAT32  Partition    260 MB  Healthy    Hidden
  Volume 8     F   BOOT         FAT32  Removable   2048 MB  Healthy
  Volume 9     J   INSTALL      NTFS   Removable     27 GB  Healthy

DISKPART> exit

Leaving DiskPart...

X:\sources>J:

J:\>cd BATCH FILES

J:\BATCH FILES>DIR
 Volume in drive J is INSTALL
 Volume Serial Number is 6EAD-EC96

 Directory of J:\BATCH FILES

10/19/2026  08:58 AM    <DIR>          .
10/19/2026  07:40 AM             7,439 create_uefi.bat
10/17/2026  11:43 PM            15,323 deploy_win11.bat
10/19/2026  07:44 AM            33,102 ElevenForum_Post_Template.txt
10/19/2026  08:51 AM        55,076,370 Fix Windows 11 BCDedit.pdf
10/19/2026  08:54 AM                96 New Text Document.txt
10/19/2026  07:41 AM            10,827 verify_deploy.bat
               6 File(s)     55,143,157 bytes
               1 Dir(s)  11,609,669,632 bytes free

J:\BATCH FILES> deploy_win11.bat
===============================================================================
Available Editions in J:\sources\install.wim:
===============================================================================

Deployment Image Servicing and Management tool
Version: 10.0.26100.8972

Details for image : J:\sources\install.wim

Index : 1
Name : Windows 11 Home
Description : Windows 11 Home
Size : 25,730,139,683 bytes

Index : 2
Name : Windows 11 Home N
Description : Windows 11 Home N
Size : 25,002,017,930 bytes

Index : 3
Name : Windows 11 Home Single Language
Description : Windows 11 Home Single Language
Size : 25,726,661,488 bytes

Index : 4
Name : Windows 11 Education
Description : Windows 11 Education
Size : 26,767,384,556 bytes

Index : 5
Name : Windows 11 Education N
Description : Windows 11 Education N
Size : 26,016,541,654 bytes

Index : 6
Name : Windows 11 Pro
Description : Windows 11 Pro
Size : 26,770,709,765 bytes

Index : 7
Name : Windows 11 Pro N
Description : Windows 11 Pro N
Size : 26,037,976,877 bytes

Index : 8
Name : Windows 11 Pro Education
Description : Windows 11 Pro Education
Size : 26,767,435,194 bytes

Index : 9
Name : Windows 11 Pro Education N
Description : Windows 11 Pro Education N
Size : 26,016,567,423 bytes

Index : 10
Name : Windows 11 Pro for Workstations
Description : Windows 11 Pro for Workstations
Size : 26,767,485,832 bytes

Index : 11
Name : Windows 11 Pro N for Workstations
Description : Windows 11 Pro N for Workstations
Size : 26,016,593,192 bytes

The operation completed successfully.
===============================================================================

Enter the Index number to install [default: 1]: 6
===============================================================================
Disk Configuration:
===============================================================================
[1] Use an existing partition [no wipe]
[2] Wipe an entire disk and create MBR [System Reserved + OS]
[3] Wipe an entire disk and create GPT [EFI + MSR + OS]
===============================================================================
Enter choice [1, 2, or 3, default: 1]: 3


Microsoft DiskPart version 10.0.26100.1150

Copyright (C) Microsoft Corporation.
On computer: MININT-H4VLA33

DISKPART>
  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          931 GB  1024 KB
  Disk 1    Online          119 GB  1024 KB        *
  Disk 2    Online           29 GB      0 B

DISKPART>
Enter the DISK NUMBER to completely wipe and format as GPT: 1

===============================================================================
Applying Image
===============================================================================
Source WIM    : J:\sources\install.wim
Selected Index: 6
Target Drive  : W:\
===============================================================================

Extracting Windows files... [This may take several minutes]


Deployment Image Servicing and Management tool
Version: 10.0.26100.8972

Applying image
[==========================100.0%==========================]
The operation completed successfully.

[PASS] Image applied successfully to W:\.

===============================================================================
Configuring UEFI Bootloader and NVRAM
===============================================================================
Launching create_uefi.bat for target W: ...
============================================================
       UEFI Bootloader and NVRAM Fallback Provisioner
============================================================

[OK] Verified target Windows on W:.

[*] Scanning disks for FAT32 EFI partitions...

===============================================================================
Potential FAT32 EFI Partitions:
===============================================================================
  Disk #   Volume ###  Ltr  Label        Fs     Type        Size     Status
  -------  ----------  ---  -----------  -----  ----------  -------  ---------
  Disk 1   Volume 6    S  SYSTEM  FAT32  Partition  260  MB
  Disk 2   Volume 7    F  BOOT  FAT32  Removable  2048  MB
===============================================================================

Enter FAT32 EFI Volume Number to provision:6
[OK] Target EFI Volume selected: 6

[*] Mounting Volume 6 to S:...
[OK] EFI Partition mounted on S:.

[*] Running bcdboot to populate UEFI boot files...
BFSVC Error: AddBootmgrLast and PreserveBootOrder options are ignored when custom volume is specified
BFSVC Error: AddBootmgrLast and PreserveBootOrder options are ignored when custom volume is specified
Boot files successfully created.
[OK] Boot files successfully created.
[*] Provisioning default UEFI fallback bootloader...
[OK] Created S:\EFI\Boot\bootx64.efi

[*] Checking NVRAM access...
[INFO] NVRAM write access restricted in current environment.
[INFO] Relying on fallback loader bootx64.efi.

[*] Unmounting S:...
[OK] S: unmounted cleanly.

============================================================
[SUCCESS] UEFI Bootloader Provisioning Complete.
============================================================

Press any key to continue . . .

Press any key to continue . . .

[*] Checking BCD for dynamic locate pointers...
[PASS] BCD validation completed.

===============================================================================
Deployment Process Complete.
Calling Verification Script...
===============================================================================
============================================================
     Universal Deployment Verification Utility (UEFI / MBR)
============================================================

Available Drives with a Windows directory:
  - G:\Windows
  - H:\Windows
  - I:\Windows
  - W:\Windows

Enter Target Windows Drive Letter [default: W:]: W
Target selected: W:\

[*] Verifying Windows System Files on W:\...
[PASS] Found: ntoskrnl.exe
[PASS] Found: winresume.efi
[PASS] Found: winload.efi
[PASS] Found: winload.exe
[PASS] Found: Registry Hive SYSTEM
[PASS] Found: Registry Hive SOFTWARE
[RESULT] Core Windows system files successfully verified.

============================================================
Select Boot Mode to Verify:
============================================================
[1] UEFI (GPT - ESP FAT32 partition and EFI BCD Store)
[2] MBR  (Legacy BIOS - bootmgr and Active partition)
Enter choice [1 or 2, default: 1]: 1

============================================================
Verifying UEFI Bootloader Configuration
============================================================
[*] Locating EFI System Partition...
[*] Mounting Volume 6 to S:...
[PASS] EFI bootloader found: S:\EFI\Microsoft\Boot\bootmgfw.efi
[PASS] Fallback bootloader found: S:\EFI\Boot\bootx64.efi
[PASS] UEFI BCD Store verified.

[*] Registered Boot Loaders:
identifier              {default}
device                  partition=W:
path                    \Windows\system32\winload.efi
osdevice                partition=W:
[PASS] Unmounted S: cleanly.

============================================================
Verification Complete.
============================================================

Press any key to continue . . .

J:\BATCH FILES>

J:\BATCH FILES>deploy_win11.bat

===============================================================================
Available Editions in J:\sources\install.wim:
===============================================================================

Deployment Image Servicing and Management tool
Version: 10.0.26100.8972

Details for image : J:\sources\install.wim

Index : 1
Name : Windows 11 Home
Description : Windows 11 Home
Size : 25,730,139,683 bytes

Index : 2
Name : Windows 11 Home N
Description : Windows 11 Home N
Size : 25,002,017,930 bytes

Index : 3
Name : Windows 11 Home Single Language
Description : Windows 11 Home Single Language
Size : 25,726,661,488 bytes

Index : 4
Name : Windows 11 Education
Description : Windows 11 Education
Size : 26,767,384,556 bytes

Index : 5
Name : Windows 11 Education N
Description : Windows 11 Education N
Size : 26,016,541,654 bytes

Index : 6
Name : Windows 11 Pro
Description : Windows 11 Pro
Size : 26,770,709,765 bytes

Index : 7
Name : Windows 11 Pro N
Description : Windows 11 Pro N
Size : 26,037,976,877 bytes

Index : 8
Name : Windows 11 Pro Education
Description : Windows 11 Pro Education
Size : 26,767,435,194 bytes

Index : 9
Name : Windows 11 Pro Education N
Description : Windows 11 Pro Education N
Size : 26,016,567,423 bytes

Index : 10
Name : Windows 11 Pro for Workstations
Description : Windows 11 Pro for Workstations
Size : 26,767,485,832 bytes

Index : 11
Name : Windows 11 Pro N for Workstations
Description : Windows 11 Pro N for Workstations
Size : 26,016,593,192 bytes

The operation completed successfully.
===============================================================================

Enter the Index number to install [default: 1]: 1

===============================================================================
Disk Configuration:
===============================================================================
[1] Use an existing partition [no wipe]
[2] Wipe an entire disk and create MBR [System Reserved + OS]
[3] Wipe an entire disk and create GPT [EFI + MSR + OS]
===============================================================================
Enter choice [1, 2, or 3, default: 1]:1

===============================================================================
Available Volumes:
===============================================================================

Microsoft DiskPart version 10.0.26100.1150

Copyright (C) Microsoft Corporation.
On computer: MININT-7KCADLV

DISKPART>
  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     K                       DVD-ROM         0 B  No Media
  Volume 1     C   System Rese  NTFS   Partition    500 MB  Healthy
  Volume 2     H   Windows      NTFS   Partition    247 GB  Healthy
  Volume 3     I   TEST 1       NTFS   Partition    296 GB  Healthy
  Volume 4     G   TEST 2       NTFS   Partition    387 GB  Healthy
  Volume 5     D   Windows      NTFS   Partition     70 GB  Healthy
  Volume 6     E   Windows Hom  NTFS   Partition     48 GB  Healthy
  Volume 7         SYSTEM       FAT32  Partition    260 MB  Healthy    Hidden
  Volume 8     F   BOOT         FAT32  Removable   2048 MB  Healthy
  Volume 9     J   INSTALL      NTFS   Removable     27 GB  Healthy

DISKPART> ===============================================================================

Enter the target drive letter to install to [default: D]: E
===============================================================================
Applying Image
===============================================================================
Source WIM    : J:\sources\install.wim
Selected Index: 1
Target Drive  : E:\
===============================================================================

Extracting Windows files... [This may take several minutes]


Deployment Image Servicing and Management tool
Version: 10.0.26100.8972

Applying image
[==========================100.0%==========================]
The operation completed successfully.

[PASS] Image applied successfully to E:\.

===============================================================================
Configuring UEFI Bootloader and NVRAM
===============================================================================
Launching create_uefi.bat for target E: ...
============================================================
       UEFI Bootloader and NVRAM Fallback Provisioner
============================================================

[OK] Verified target Windows on E:.

[*] Scanning disks for FAT32 EFI partitions...

===============================================================================
Potential FAT32 EFI Partitions:
===============================================================================
  Disk #   Volume ###  Ltr  Label        Fs     Type        Size     Status
  -------  ----------  ---  -----------  -----  ----------  -------  ---------
  Disk 1   Volume 7    SYSTEM  FAT32  Partition  260  MB  Healthy
  Disk 2   Volume 8    F  BOOT  FAT32  Removable  2048  MB
===============================================================================

Enter FAT32 EFI Volume Number to provision:7
[OK] Target EFI Volume selected: 7

[*] Mounting Volume 7 to S:...
[OK] EFI Partition mounted on S:.

[*] Running bcdboot to populate UEFI boot files...
BFSVC Error: AddBootmgrLast and PreserveBootOrder options are ignored when custom volume is specified
BFSVC Error: AddBootmgrLast and PreserveBootOrder options are ignored when custom volume is specified
Boot files successfully created.
[OK] Boot files successfully created.
[*] Provisioning default UEFI fallback bootloader...
[OK] Created S:\EFI\Boot\bootx64.efi

[*] Checking NVRAM access...
[INFO] NVRAM write access restricted in current environment.
[INFO] Relying on fallback loader bootx64.efi.

[*] Unmounting S:...
[OK] S: unmounted cleanly.

============================================================
[SUCCESS] UEFI Bootloader Provisioning Complete.
============================================================

Press any key to continue . . .

[*] Checking BCD for dynamic locate pointers...
[PASS] BCD validation completed.

===============================================================================
Deployment Process Complete.
Calling Verification Script...
===============================================================================
============================================================
     Universal Deployment Verification Utility (UEFI / MBR)
============================================================

Available Drives with a Windows directory:
  - D:\Windows
  - E:\Windows
  - G:\Windows
  - H:\Windows
  - I:\Windows

Enter Target Windows Drive Letter [default: E:]: E
Target selected: E:\

[*] Verifying Windows System Files on E:\...
[PASS] Found: ntoskrnl.exe
[PASS] Found: winresume.efi
[PASS] Found: winload.efi
[PASS] Found: winload.exe
[PASS] Found: Registry Hive SYSTEM
[PASS] Found: Registry Hive SOFTWARE
[RESULT] Core Windows system files successfully verified.

============================================================
Select Boot Mode to Verify:
============================================================
[1] UEFI (GPT - ESP FAT32 partition and EFI BCD Store)
[2] MBR  (Legacy BIOS - bootmgr and Active partition)
Enter choice [1 or 2, default: 1]: 1
============================================================
Verifying UEFI Bootloader Configuration
============================================================
[*] Locating EFI System Partition...
[*] Mounting Volume 7 to S:...
[PASS] EFI bootloader found: S:\EFI\Microsoft\Boot\bootmgfw.efi
[PASS] Fallback bootloader found: S:\EFI\Boot\bootx64.efi
[PASS] UEFI BCD Store verified.

[*] Registered Boot Loaders:
identifier              {default}
device                  partition=E:
path                    \Windows\system32\winload.efi
osdevice                partition=E:
identifier              {f170bff0-cc55-11f1-932c-8b58cf23bcec}
device                  partition=D:
path                    \Windows\system32\winload.efi
osdevice                partition=D:
identifier              {f1e54001-cc4e-11f1-a33a-8d8e799bdfc0}
device                  ramdisk=[D:]\Recovery\WindowsRE\Winre.wim,{f1e54002-cc4e-11f1-a33a-8d8e799bdfc0}
path                    \windows\system32\winload.efi
osdevice                ramdisk=[D:]\Recovery\WindowsRE\Winre.wim,{f1e54002-cc4e-11f1-a33a-8d8e799bdfc0}
[PASS] Unmounted S: cleanly.

============================================================
Verification Complete.
============================================================

Press any key to continue . . .

THANKS FOR READING THIS THREAD AND SHARING YOUR VALUABLE TIME.
 
Windows Build/Version
Windows 11 v26H2 OS BUILD 26300.9457

Attachments

Last edited:

My Computer My Computer

At a glance

Window 11 v24H2 Build 26100.2033Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz 3.10 GHz4.00 GB (3.89 GB usable)Onboard
OS
Window 11 v24H2 Build 26100.2033
Computer type
PC/Desktop
Manufacturer/Model
ASSEMMBLED
CPU
Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz 3.10 GHz
Motherboard
ZEBRONICS
Memory
4.00 GB (3.89 GB usable)
Graphics Card(s)
Onboard
Sound Card
Onboard
Monitor(s) Displays
LG
Screen Resolution
1366x768
Hard Drives
Toshiba HDD 1 TB
Keyboard
Mechanical
Mouse
Mechanical
Internet Speed
700 kb/s
Browser
Microsoft EDGE, CHROME
Antivirus
Microsoft Defender
UPDATE: Toolkit v2.0 Released – Script-File Mounting, In-Memory Disk Mapping & Full WinPE Offline Resilience

Following extensive end-to-end testing across both Live Windows and Windows PE environments (on internal SSDs and multi-partition external HDDs), all three batch scripts have been updated to version 2.0.

Key Fixes & Architectural Improvements in v2.0:
  • Eliminated VDS / Drive Letter Collisions: Piped compound commands ((echo sel vol X & echo assign letter=S) | diskpart) frequently drop arguments under nested block conditions or fail when the kernel retains a cached mount. All three scripts now execute DiskPart via self-cleaning script files (diskpart /s) combined with an upfront mountvol S:\ /D flush.
  • 100% In-Memory Parent Disk & ESP Querying: Auto-detection of physical disks and candidate FAT32 EFI System Partitions now operates entirely in memory using subshell loops. Zero temporary scratch files are written to disk for queries, guaranteeing seamless execution on WinPE RAM disks (X:\).
  • Windows 11 Build 26100+ (24H2) Compatibility Hook: Prevents Error code = 0xc1 (checksum validation failure) during bcdboot execution by automatically mirroring boot templates to \Windows\boot\EFI_EX\bootmgfw_EX.efi.
  • Automated Verification Chaining: deploy_win11.bat now directly passes the target drive letter and boot mode to verify_deploy.bat, executing end-to-end verification and streaming BCD osloader tables with zero manual prompts.
  • Diagnostic & Test Mode: Added a /skipimage switch and interactive [Y/N] prompt to deploy_win11.bat to test partition layout, mounting, bcdboot, fallback loaders, and NVRAM without extracting a 25 GB WIM image every run.

---

Script Suite v2.0 Source Codes

Code:
@Echo off
Title Universal Windows 11 Deployment Utility (UEFI / MBR)
Setlocal EnableDelayedExpansion

:: Ensure System32 binaries are always in PATH across WinPE and Live OS
set "PATH=X:\Windows\System32;C:\Windows\System32;%SystemRoot%\System32;%WINDIR%\System32;%PATH%"

:: Check for command-line switch to skip DISM
Set "FLAG_SKIP_IMAGE=0"
If /I "%~1"=="/skipimage" Set "FLAG_SKIP_IMAGE=1"
If /I "%~1"=="-skipimage" Set "FLAG_SKIP_IMAGE=1"

:: 1. Locate install.wim across drives
Set "WIM_PATH="
For %%i in (C D E F G H I J K L M N O P Q R S T U V W Y Z) Do (
    If Exist "%%i:\sources\install.wim" (
        Set "WIM_PATH=%%i:\sources\install.wim"
        Goto :FoundWim
    )
    If Exist "%%i:\sources\install.esd" (
        Set "WIM_PATH=%%i:\sources\install.esd"
        Goto :FoundWim
    )
)

:FoundWim
If not defined WIM_PATH (
    If "%FLAG_SKIP_IMAGE%"=="1" (
        Set "WIM_PATH=SKIPPED"
        Goto :PromptTargetDirect
    )
    Echo [FAIL] Neither install.wim nor install.esd found on any available drive.
    Pause
    Exit /B 1
)

:: 2. Display available editions and indexes
Echo.
Echo ===============================================================================
Echo Available Editions in %WIM_PATH%:
Echo ===============================================================================
If not "%WIM_PATH%"=="SKIPPED" (
    dism /Get-ImageInfo /ImageFile:"%WIM_PATH%"
)
Echo ===============================================================================
Echo.

Set "INDEX_NUM=1"
Set /p "INDEX_NUM=Enter the Index number to install [default: 1]: "

:: 3. Disk Configuration Menu
:PromptTargetDirect
Echo.
Echo ===============================================================================
Echo Disk Configuration:
Echo ===============================================================================
Echo [1] Use an existing partition [no wipe]
Echo [2] Wipe an entire disk and create MBR [System Reserved + OS]
Echo [3] Wipe an entire disk and create GPT [EFI + MSR + OS]
Echo ===============================================================================
Set "DISK_CONFIG=1"
Set /p "DISK_CONFIG=Enter choice [1, 2, or 3, default: 1]: "

If "%DISK_CONFIG%"=="2" Goto :PartitionDiskMBR
If "%DISK_CONFIG%"=="3" Goto :PartitionDiskGPT
Goto :SelectExisting

:: -------------------------------------------------------------------------------
:: Branch A: Wipe and Partition as MBR
:: -------------------------------------------------------------------------------
:PartitionDiskMBR
Echo.
(Echo lis dis) | diskpart
Echo.

:SelectDiskNumMBR
Set "TARGET_DISK="
Set /p "TARGET_DISK=Enter the DISK NUMBER to completely wipe and format as MBR: "
If not defined TARGET_DISK Goto :SelectDiskNumMBR

Set "CHECK_DIGIT=%TARGET_DISK%"
For /F "delims=0123456789" %%A in ("%CHECK_DIGIT%") Do Set "CHECK_DIGIT="
If not defined CHECK_DIGIT (
    Echo Invalid input. Please enter numbers only.
    Goto :SelectDiskNumMBR
)

Echo.
Echo *******************************************************************************
Echo WARNING: ALL DATA ON DISK %TARGET_DISK% WILL BE PERMANENTLY ERASED [MBR]!
Echo *******************************************************************************
Set /p "CONFIRM=Type YES to proceed with wipe: "
If /I not "%CONFIRM%"=="YES" (
    Echo Disk partitioning aborted by user.
    Goto :SelectExisting
)

(Echo sel vol S & Echo remove noerr & Echo sel vol W & Echo remove noerr) | diskpart >nul 2>&1

Set "DP_SCRIPT=%TEMP%\mbr_setup_clean.txt"
if not exist "%TEMP%" Set "DP_SCRIPT=X:\mbr_setup_clean.txt"
>"%DP_SCRIPT%" Echo sel dis %TARGET_DISK%
>>"%DP_SCRIPT%" Echo clean
>>"%DP_SCRIPT%" Echo convert mbr
>>"%DP_SCRIPT%" Echo create partition primary size=500
>>"%DP_SCRIPT%" Echo format quick fs=ntfs label="System Reserved"
>>"%DP_SCRIPT%" Echo active
>>"%DP_SCRIPT%" Echo assign letter=S
>>"%DP_SCRIPT%" Echo create partition primary
>>"%DP_SCRIPT%" Echo format quick fs=ntfs label="Windows"
>>"%DP_SCRIPT%" Echo assign letter=W

Echo.
Echo Partitioning and formatting Disk %TARGET_DISK% as MBR...
diskpart /s "%DP_SCRIPT%" >nul 2>&1
If Exist "%DP_SCRIPT%" Del /f /q "%DP_SCRIPT%" >nul 2>&1

Set "TARGET_DRIVE=W"
Set "BOOT_MODE=2"
Set "HAS_SYS_RES=1"
Echo [PASS] Disk %TARGET_DISK% partitioned as MBR. Target OS drive is W:\.
Goto :ApplyOS

:: -------------------------------------------------------------------------------
:: Branch B: Wipe and Partition as GPT (UEFI)
:: -------------------------------------------------------------------------------
:PartitionDiskGPT
Echo.
(Echo lis dis) | diskpart
Echo.

:SelectDiskNumGPT
Set "TARGET_DISK="
Set /p "TARGET_DISK=Enter the DISK NUMBER to completely wipe and format as GPT: "
If not defined TARGET_DISK Goto :SelectDiskNumGPT

Set "CHECK_DIGIT=%TARGET_DISK%"
For /F "delims=0123456789" %%A in ("%CHECK_DIGIT%") Do Set "CHECK_DIGIT="
If not defined CHECK_DIGIT (
    Echo Invalid input. Please enter numbers only.
    Goto :SelectDiskNumGPT
)

Echo.
Echo *******************************************************************************
Echo WARNING: ALL DATA ON DISK %TARGET_DISK% WILL BE PERMANENTLY ERASED [GPT/UEFI]!
Echo *******************************************************************************
Set /p "CONFIRM=Type YES to proceed with wipe: "
If /I not "%CONFIRM%"=="YES" (
    Echo Disk partitioning aborted by user.
    Goto :SelectExisting
)

(Echo sel vol S & Echo remove noerr & Echo sel vol W & Echo remove noerr) | diskpart >nul 2>&1

Set "DP_SCRIPT=%TEMP%\gpt_setup_clean.txt"
if not exist "%TEMP%" Set "DP_SCRIPT=X:\gpt_setup_clean.txt"
>"%DP_SCRIPT%" Echo sel dis %TARGET_DISK%
>>"%DP_SCRIPT%" Echo clean
>>"%DP_SCRIPT%" Echo convert gpt
>>"%DP_SCRIPT%" Echo create partition efi size=260
>>"%DP_SCRIPT%" Echo format quick fs=fat32 label="System"
>>"%DP_SCRIPT%" Echo assign letter=S
>>"%DP_SCRIPT%" Echo create partition msr size=16
>>"%DP_SCRIPT%" Echo create partition primary
>>"%DP_SCRIPT%" Echo format quick fs=ntfs label="Windows"
>>"%DP_SCRIPT%" Echo assign letter=W

Echo.
Echo Partitioning and formatting Disk %TARGET_DISK% as GPT...
diskpart /s "%DP_SCRIPT%" >nul 2>&1
If Exist "%DP_SCRIPT%" Del /f /q "%DP_SCRIPT%" >nul 2>&1

Set "TARGET_DRIVE=W"
Set "BOOT_MODE=1"
Set "HAS_SYS_RES=1"
Echo [PASS] Disk %TARGET_DISK% partitioned as GPT. Target OS drive is W:\.
Goto :ApplyOS

:: -------------------------------------------------------------------------------
:: Branch C: Select Existing Volume
:: -------------------------------------------------------------------------------
:SelectExisting
Echo.
Echo ===============================================================================
Echo Available Volumes:
Echo ===============================================================================
(Echo list volume) | diskpart
Echo ===============================================================================
Echo.

:PromptTarget
Set "TARGET_DRIVE=D"
Set /p "TARGET_DRIVE=Enter the target drive letter to install to [default: D]: "
Set "TARGET_DRIVE=%TARGET_DRIVE:~0,1%"

If not Exist "%TARGET_DRIVE%:\" (
    Echo [FAIL] Drive %TARGET_DRIVE%:\ does not exist. Please check the volume list.
    Goto :PromptTarget
)

Echo.
Echo ===============================================================================
Echo Select Firmware / Boot Mode for Existing Drive:
Echo ===============================================================================
Echo [1] UEFI [GPT - Writes to EFI System Partition]
Echo [2] MBR / Legacy BIOS [Auto-detect System Reserved or existing boot store]
Echo [3] MBR / Legacy BIOS [Standalone - write bootmgr directly to %TARGET_DRIVE%:]
Echo ===============================================================================
Set "BOOT_MODE=1"
Set /p "BOOT_MODE=Enter choice [1, 2, or 3, default: 1]: "
Set "HAS_SYS_RES=0"
Set "EXISTING_BOOT_VOL="

If "%BOOT_MODE%"=="2" (
    For /f "tokens=1,2,3,4,5,6,7*" %%A in ('^(Echo list volume^) ^| diskpart ^| findstr /I "System"') Do (
        If /i "%%A"=="Volume" (
            (Echo select volume %%B & Echo assign letter=S) | diskpart >nul 2>&1
            If Exist "S:\Boot\BCD" (
                Set "EXISTING_BOOT_VOL=S:"
                Set "HAS_SYS_RES=1"
            )
        )
    )

    If not defined EXISTING_BOOT_VOL (
        For %%D in (C D) Do (
            If Exist "%%D:\Boot\BCD" Set "EXISTING_BOOT_VOL=%%D:"
        )
    )
)

Goto :ApplyOS

:: -------------------------------------------------------------------------------
:: 4. Image Extraction via DISM
:: -------------------------------------------------------------------------------
:ApplyOS
Cls
Echo ===============================================================================
Echo Target Installation Overview
Echo ===============================================================================
Echo Source WIM    : %WIM_PATH%
Echo Selected Index: %INDEX_NUM%
Echo Target Drive  : %TARGET_DRIVE%:\
Echo ===============================================================================
Echo.

:: Check command-line switch first
If "%FLAG_SKIP_IMAGE%"=="1" (
    Echo [*] Command-line switch detected: Skipping DISM image extraction.
    Goto :SkipDismStep
)

:: Interactive skip prompt
Set "SKIP_DISM=N"
Set /p "SKIP_DISM=Skip DISM extraction and test bootloader configuration only? [Y/N, default: N]: "
If /I "%SKIP_DISM%"=="Y" (
    Echo.
    Echo [*] Skipping DISM image extraction. Proceeding directly to bootloader setup...
    Goto :SkipDismStep
)

Echo.
Echo Extracting Windows files... [This may take several minutes]
Echo.

dism /Apply-Image /ImageFile:"%WIM_PATH%" /Index:%INDEX_NUM% /ApplyDir:%TARGET_DRIVE%:\
If %errorlevel% neq 0 (
    Echo.
    Echo [FAIL] DISM failed to apply the image [Error Level: %errorlevel%].
    Pause
    Goto :Cleanup
)

Echo.
Echo [PASS] Image applied successfully to %TARGET_DRIVE%:\.

:SkipDismStep
If "%BOOT_MODE%"=="1" (
    Goto :ConfigureUEFI
) Else (
    Goto :ConfigureMBR
)

:: -------------------------------------------------------------------------------
:: 5. In-Memory UEFI Bootloader & NVRAM Provisioning (100% WinPE Native)
:: -------------------------------------------------------------------------------
:ConfigureUEFI
Echo.
Echo ===============================================================================
Echo Configuring UEFI Bootloader and NVRAM
Echo ===============================================================================

Set "MNT_LTR=S"
Set "AUTO_MNT_ESP=0"

If "%HAS_SYS_RES%"=="1" (
    Set "ESP_TARGET_VOL=S:"
    Goto :WriteUEFIBootFiles
)

:: Resolve physical parent disk in memory
Set "PARENT_DISK="
For /f "tokens=1,2,3*" %%A in ('^(Echo select volume %TARGET_DRIVE% ^& Echo detail volume^) ^| diskpart') Do (
    If /i "%%A"=="Disk" Set "PARENT_DISK=%%B"
    If "%%A"=="*" If /i "%%B"=="Disk" Set "PARENT_DISK=%%C"
)
If defined PARENT_DISK (
    For /f "delims=0123456789" %%Z in ("!PARENT_DISK!") Do Set "PARENT_DISK="
)

:: Detect candidate ESP (FAT32, MB-sized, non-removable)
Set "SUGGESTED_ESP="
If defined PARENT_DISK (
    For /f "tokens=1,2,3,4,5,6,7,8*" %%A in ('^(Echo select disk !PARENT_DISK! ^& Echo detail disk^) ^| diskpart ^| findstr /I "FAT32"') Do (
        If /i "%%A"=="Volume" (
            Set "LINE_FAT=%%A %%B %%C %%D %%E %%F %%G %%H"
            Echo !LINE_FAT! | findstr /V /I "GB Removable" >nul
            If not errorlevel 1 (
                If not defined SUGGESTED_ESP Set "SUGGESTED_ESP=%%B"
            )
        )
    )
)

:: Fallback interactive volume display if detection was indeterminate
If not defined SUGGESTED_ESP (
    Echo.
    Echo [!] Automatic EFI pinpointing indeterminate.
    Echo ===============================================================================
    Echo Available Volumes on System:
    Echo ===============================================================================
    (Echo list volume) | diskpart
    Echo ===============================================================================
    Echo.
) Else (
    Echo [OK] Detected matching EFI System Partition: Volume !SUGGESTED_ESP!
)

Set "PROMPT_MSG=Enter FAT32 EFI Volume Number to mount"
If defined SUGGESTED_ESP Set "PROMPT_MSG=Enter FAT32 EFI Volume Number to mount [default: !SUGGESTED_ESP!]"

Set "ESP_VOL="
Set /p "ESP_VOL=!PROMPT_MSG!: "
If "!ESP_VOL!"=="" If defined SUGGESTED_ESP Set "ESP_VOL=!SUGGESTED_ESP!"

If "!ESP_VOL!"=="" (
    Echo [FAIL] No EFI volume selected. Bootloader not configured.
    Goto :PostBootCheck
)

:: Ensure valid scratch directory
Set "SCRATCH_DIR=%TEMP%"
If not exist "%SCRATCH_DIR%" Set "SCRATCH_DIR=X:\windows\temp"
If not exist "%SCRATCH_DIR%" Set "SCRATCH_DIR=X:\"

:: Clean Non-Colliding Mount Routine via Script File
Set "ALREADY_MOUNTED="
dir !MNT_LTR!:\ >nul 2>&1 && Set "ALREADY_MOUNTED=1"
If Exist "!MNT_LTR!:\EFI" Set "ALREADY_MOUNTED=1"

If not defined ALREADY_MOUNTED (
    mountvol !MNT_LTR!:\ /D >nul 2>&1
    Echo [*] Mounting Volume !ESP_VOL! to !MNT_LTR!:...
    
    Set "TMP_DP_MNT=%SCRATCH_DIR%\dp_dep_mnt.txt"
    (
        Echo select volume !ESP_VOL!
        Echo assign letter=!MNT_LTR!
    ) > "!TMP_DP_MNT!"
    
    diskpart /s "!TMP_DP_MNT!" >nul 2>&1
    If exist "!TMP_DP_MNT!" del /f /q "!TMP_DP_MNT!" >nul 2>&1
    Set "AUTO_MNT_ESP=1"
    ping -n 3 127.0.0.1 >nul 2>&1
) Else (
    Echo [*] EFI Partition is already accessible on !MNT_LTR!:.
)

Set "MOUNTED_VALID="
For /L %%i in (1,1,6) Do (
    If not defined MOUNTED_VALID (
        dir !MNT_LTR!:\ >nul 2>&1 && Set "MOUNTED_VALID=1"
        If Exist "!MNT_LTR!:\EFI" Set "MOUNTED_VALID=1"
        If not defined MOUNTED_VALID ping -n 2 127.0.0.1 >nul 2>&1
    )
)

If not defined MOUNTED_VALID (
    Echo [FAIL] Could not mount FAT32 EFI partition to !MNT_LTR!:.
    Echo [*] DiskPart verbose diagnostic:
    (Echo select volume !ESP_VOL! & Echo detail volume) | diskpart
    Goto :PostBootCheck
)

Echo [PASS] Volume !ESP_VOL! successfully mounted and accessible on !MNT_LTR!:.

Set "ESP_TARGET_VOL=!MNT_LTR!:"

:WriteUEFIBootFiles
:: Build 26100+ EFI_EX compatibility hook
If Exist "%TARGET_DRIVE%:\Windows\boot\EFI" (
    If not Exist "%TARGET_DRIVE%:\Windows\boot\EFI_EX\bootmgfw_EX.efi" (
        Echo [*] Applying Build 26100+ EFI_EX compatibility hook...
        xcopy /E /I /H /Y "%TARGET_DRIVE%:\Windows\boot\EFI" "%TARGET_DRIVE%:\Windows\boot\EFI_EX" >nul 2>&1
        copy /y "%TARGET_DRIVE%:\Windows\boot\EFI\bootmgfw.efi" "%TARGET_DRIVE%:\Windows\boot\EFI_EX\bootmgfw_EX.efi" >nul 2>&1
        Echo [OK] EFI_EX fallback templates synchronized.
    )
)

If Exist "%ESP_TARGET_VOL%\EFI\Microsoft\Boot\BCD" attrib -s -h -r "%ESP_TARGET_VOL%\EFI\Microsoft\Boot\BCD" >nul 2>&1
"%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s %ESP_TARGET_VOL% /f UEFI
If %errorlevel% equ 0 (
    Echo [PASS] UEFI boot files written successfully.
    If not Exist "%ESP_TARGET_VOL%\EFI\Boot" mkdir "%ESP_TARGET_VOL%\EFI\Boot"
    If Exist "%ESP_TARGET_VOL%\EFI\Microsoft\Boot\bootmgfw.efi" (
        copy /y "%ESP_TARGET_VOL%\EFI\Microsoft\Boot\bootmgfw.efi" "%ESP_TARGET_VOL%\EFI\Boot\bootx64.efi" >nul 2>&1
        Echo [PASS] Created fallback bootx64.efi.
    )
    "%SystemRoot%\System32\bcdedit.exe" /store "%ESP_TARGET_VOL%\EFI\Microsoft\Boot\BCD" /set {bootmgr} description "Windows Boot Manager" >nul 2>&1
    Echo [PASS] NVRAM entry synchronized.
) Else (
    Echo [FAIL] bcdboot failed to write UEFI boot files.
)

If "!AUTO_MNT_ESP!"=="1" (
    Set "TMP_DP_UNM=%SCRATCH_DIR%\dp_dep_unm.txt"
    (
        Echo select volume !ESP_VOL!
        Echo remove letter=!MNT_LTR!
    ) > "!TMP_DP_UNM!"
    diskpart /s "!TMP_DP_UNM!" >nul 2>&1
    If exist "!TMP_DP_UNM!" del /f /q "!TMP_DP_UNM!" >nul 2>&1
    Echo [PASS] Unmounted !MNT_LTR!: cleanly.
)
Goto :PostBootCheck

:: -------------------------------------------------------------
:: 6. MBR Bootloader Configuration
:: -------------------------------------------------------------
:ConfigureMBR
Echo.
If defined EXISTING_BOOT_VOL (
    Echo [*] Updating existing bootloader on %EXISTING_BOOT_VOL%...
    "%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s %EXISTING_BOOT_VOL% /f BIOS
    If %errorlevel% equ 0 (
        Echo [PASS] Appended new OS entry to existing BCD on %EXISTING_BOOT_VOL%.
    ) Else (
        Echo [FAIL] BCDBoot failed to update %EXISTING_BOOT_VOL%.
    )
    If "%HAS_SYS_RES%"=="1" (
        (Echo select volume S & Echo remove letter=S) | diskpart >nul 2>&1
    )
    Goto :PostBootCheck
)

If "%HAS_SYS_RES%"=="1" (
    Echo Configuring MBR boot files on System Reserved partition...
    "%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s S: /f BIOS
    If !errorlevel! equ 0 (
        Echo [PASS] MBR bootloader configured on System Reserved.
    ) Else (
        Echo [FAIL] BCDboot failed to write boot files to S:.
    )
    (Echo select volume S & Echo remove letter=S) | diskpart >nul 2>&1
) Else (
    Echo Configuring MBR boot files directly on %TARGET_DRIVE%:\...
    "%SystemRoot%\System32\bcdboot.exe" %TARGET_DRIVE%:\Windows /s %TARGET_DRIVE%: /f BIOS
    If !errorlevel! equ 0 (
        (Echo sel vol %TARGET_DRIVE% & Echo active) | diskpart >nul 2>&1
        Echo [PASS] MBR bootloader configured on %TARGET_DRIVE%:
    ) Else (
        Echo [FAIL] BCDboot failed to write MBR boot files.
    )
)
Goto :PostBootCheck

:: -------------------------------------------------------------
:: 7. Resolve Any Dynamic Locate Pointers in BCD
:: -------------------------------------------------------------
:PostBootCheck
Echo.
Echo [*] Checking BCD for dynamic locate pointers...
For /f "tokens=1,2" %%A in ('"%SystemRoot%\System32\bcdedit.exe" /enum osloader 2^>nul') Do (
    If /i "%%A"=="identifier" (
        Set "ENTRY_ID=%%B"
        For /f "tokens=1,2*" %%X in ('"%SystemRoot%\System32\bcdedit.exe" /enum !ENTRY_ID! 2^>nul') Do (
            If /i "%%X"=="osdevice" (
                Set "DEV_VAL=%%Y"
                If /i "!DEV_VAL:~0,6!"=="locate" (
                    Echo [*] Resolving dynamic locate pointer for entry !ENTRY_ID!...
                    "%SystemRoot%\System32\bcdedit.exe" /set !ENTRY_ID! device partition=%TARGET_DRIVE%: >nul 2>&1
                    "%SystemRoot%\System32\bcdedit.exe" /set !ENTRY_ID! osdevice partition=%TARGET_DRIVE%: >nul 2>&1
                )
            )
        )
    )
)
Echo [PASS] BCD validation completed.
Goto :End

:Cleanup
If "%HAS_SYS_RES%"=="1" (
    (Echo sel vol S & Echo remove letter=S) | diskpart >nul 2>&1
)

:End
Echo.
Echo ===============================================================================
Echo [SUCCESS] Windows 11 Deployment Cycle Completed.
Echo Target: %TARGET_DRIVE%:\
Echo ===============================================================================
Echo.

:: -------------------------------------------------------------
:: 8. Automated Chained Verification Call
:: -------------------------------------------------------------
Set "VERIFY_SCRIPT="
If Exist "%~dp0verify_deploy.bat" Set "VERIFY_SCRIPT=%~dp0verify_deploy.bat"
If not defined VERIFY_SCRIPT If Exist "verify_deploy.bat" Set "VERIFY_SCRIPT=verify_deploy.bat"

If defined VERIFY_SCRIPT (
    Echo [*] Launching automated deployment verification utility...
    Echo.
    Call "%VERIFY_SCRIPT%" "%TARGET_DRIVE%" "%BOOT_MODE%"
) Else (
    Echo [WARN] verify_deploy.bat not found in the same folder.
    Echo You can run verification manually using verify_deploy.bat.
    Pause
)

Exit /B 0

Code:
@echo off
setlocal EnableDelayedExpansion

:: Ensure System32 binaries are always in PATH across WinPE and Live OS
set "PATH=X:\Windows\System32;C:\Windows\System32;%SystemRoot%\System32;%WINDIR%\System32;%PATH%"

title UEFI Bootloader and NVRAM Fallback Provisioner
echo ============================================================
echo        UEFI Bootloader and NVRAM Fallback Provisioner
echo ============================================================
echo.

:: -------------------------------------------------------------
:: 1. Validate Target Windows Drive
:: -------------------------------------------------------------
echo Available Drives with a Windows directory:
for %%D in (C D E F G H I J K L M N O P Q R S T U V W Y Z) do (
    if exist "%%D:\Windows\System32" (
        echo   - %%D:\Windows
    )
)
echo.

set "INPUT_WIN="
set /p "INPUT_WIN=Enter Target Windows Drive Letter [e.g. C]: "
if "!INPUT_WIN!"=="" set "INPUT_WIN=C"

set "TGT_LTR=!INPUT_WIN:~0,1!"
set "TARGET_WIN=!TGT_LTR!:"

if not exist "!TARGET_WIN!\Windows" (
    echo [ERROR] No valid Windows installation found on !TARGET_WIN!\.
    pause
    goto :FAIL
)
echo [OK] Verified target Windows on !TARGET_WIN!\.
echo.

:: -------------------------------------------------------------
:: 2. Identify Physical Disk of Target Windows (In-Memory)
:: -------------------------------------------------------------
set "PARENT_DISK="

for /f "tokens=1,2,3*" %%A in ('^(echo select volume !TGT_LTR! ^& echo detail volume^) ^| diskpart') do (
    if /i "%%A"=="Disk" (
        set "PARENT_DISK=%%B"
    ) else if "%%A"=="*" if /i "%%B"=="Disk" (
        set "PARENT_DISK=%%C"
    )
)

if defined PARENT_DISK (
    for /f "delims=0123456789" %%Z in ("!PARENT_DISK!") do set "PARENT_DISK="
)

if defined PARENT_DISK (
    echo [*] Target Windows [!TARGET_WIN!] resides on Disk !PARENT_DISK!.
) else (
    echo [INFO] Multiple disks or parent disk indeterminate.
)
echo.

:: -------------------------------------------------------------
:: 3. Map Volumes to Disks & Search ESP (In-Memory)
:: -------------------------------------------------------------
set "MNT_LTR=S"

echo [*] Scanning disks for FAT32 EFI partitions...

:: Build associative array: VOL_DISK_<VolumeNum> = DiskNum directly in memory
set "CURR_DSK="
for /f "tokens=1,2,3*" %%A in ('^(for /L %%d in (0,1,6^) do @echo select disk %%d ^& @echo detail disk^) ^| diskpart') do (
    if /i "%%A"=="Disk" if not "%%B"=="" (
        set "CHK_NUM=%%B"
        for /f "delims=0123456789" %%Z in ("!CHK_NUM!") do set "CHK_NUM="
        if defined CHK_NUM set "CURR_DSK=%%B"
    )
    if /i "%%A"=="Volume" (
        set "VOL_DISK_%%B=!CURR_DSK!"
    )
)

set "SUGGESTED_ESP="

if defined PARENT_DISK (
    for /f "tokens=1,2,3,4,5,6,7,8*" %%A in ('^(echo list volume^) ^| diskpart ^| findstr /I "FAT32"') do (
        if /i "%%A"=="Volume" (
            set "D_NUM=!VOL_DISK_%%B!"
            if "!D_NUM!"=="!PARENT_DISK!" (
                set "LINE_ALL=%%A %%B %%C %%D %%E %%F %%G %%H"
                echo !LINE_ALL! | findstr /I "MB" >nul
                if not errorlevel 1 (
                    echo !LINE_ALL! | findstr /I "GB Removable" >nul
                    if errorlevel 1 (
                        if not defined SUGGESTED_ESP set "SUGGESTED_ESP=%%B"
                    )
                )
            )
        )
    )
)

:: Interactive fallback table if automatic pinpointing fails
if not defined SUGGESTED_ESP (
    echo.
    echo [!] Automatic EFI pinpointing indeterminate.
    echo ===============================================================================
    echo Available Volumes on System:
    echo ===============================================================================
    (echo list volume) | diskpart
    echo ===============================================================================
    echo.
) else (
    echo [OK] Detected matching EFI System Partition: Volume !SUGGESTED_ESP!
)

set "PROMPT_MSG=Enter FAT32 EFI Volume Number to provision"
if defined SUGGESTED_ESP set "PROMPT_MSG=Enter FAT32 EFI Volume Number to provision [default: !SUGGESTED_ESP!]"

set "ESP_VOL="
set /p "ESP_VOL=!PROMPT_MSG!: "
if "!ESP_VOL!"=="" if defined SUGGESTED_ESP set "ESP_VOL=!SUGGESTED_ESP!"

if "!ESP_VOL!"=="" (
    echo [ERROR] No volume number entered.
    pause
    goto :FAIL
)

echo [OK] Target EFI Volume selected: !ESP_VOL!
echo.

:: -------------------------------------------------------------
:: 4. Mount EFI Partition (Script-File Based & Collision Safe)
:: -------------------------------------------------------------
set "AUTO_MOUNTED=0"
set "ALREADY_MOUNTED="

:: Ensure valid scratch directory across WinPE RAM-disk and Live OS
set "SCRATCH_DIR=%TEMP%"
if not exist "%SCRATCH_DIR%" set "SCRATCH_DIR=X:\windows\temp"
if not exist "%SCRATCH_DIR%" set "SCRATCH_DIR=X:\"

dir S:\ >nul 2>&1 && set "ALREADY_MOUNTED=1"
if exist "S:\EFI" set "ALREADY_MOUNTED=1"

if not defined ALREADY_MOUNTED (
    mountvol S:\ /D >nul 2>&1
    echo [*] Mounting Volume !ESP_VOL! to S:...
    
    set "TMP_DP_MNT=%SCRATCH_DIR%\dp_uefi_mnt.txt"
    (
        echo select volume !ESP_VOL!
        echo assign letter=S
    ) > "!TMP_DP_MNT!"
    
    diskpart /s "!TMP_DP_MNT!" >nul 2>&1
    if exist "!TMP_DP_MNT!" del /f /q "!TMP_DP_MNT!" >nul 2>&1
    set "AUTO_MOUNTED=1"
    ping -n 3 127.0.0.1 >nul 2>&1
) else (
    echo [*] EFI Partition is already accessible on S:.
)

set "MOUNTED_VALID="
for /L %%i in (1,1,6) do (
    if not defined MOUNTED_VALID (
        dir S:\ >nul 2>&1 && set "MOUNTED_VALID=1"
        if exist "S:\EFI" set "MOUNTED_VALID=1"
        if not defined MOUNTED_VALID ping -n 2 127.0.0.1 >nul 2>&1
    )
)

if not defined MOUNTED_VALID (
    echo [ERROR] Failed to mount Volume !ESP_VOL! to S:.
    echo [*] Diagnostic detail from DiskPart:
    (echo select volume !ESP_VOL! & echo detail volume) | diskpart
    pause
    goto :FAIL
)
echo [OK] EFI Partition mounted on S:.
echo.

:: -------------------------------------------------------------
:: 5. EFI_EX Compatibility Safeguard (Windows 11 Build 26100+)
:: -------------------------------------------------------------
if exist "!TARGET_WIN!\Windows\boot\EFI" (
    if not exist "!TARGET_WIN!\Windows\boot\EFI_EX\bootmgfw_EX.efi" (
        echo [*] Applying Build 26100+ EFI_EX boot template compatibility hook...
        xcopy /E /I /H /Y "!TARGET_WIN!\Windows\boot\EFI" "!TARGET_WIN!\Windows\boot\EFI_EX" >nul 2>&1
        copy /y "!TARGET_WIN!\Windows\boot\EFI\bootmgfw.efi" "!TARGET_WIN!\Windows\boot\EFI_EX\bootmgfw_EX.efi" >nul 2>&1
        echo [OK] EFI_EX fallback templates synchronized.
        echo.
    )
)

:: -------------------------------------------------------------
:: 6. Populate UEFI Boot Files
:: -------------------------------------------------------------
echo [*] Running bcdboot to populate UEFI boot files...
bcdboot !TARGET_WIN!\Windows /s S: /f UEFI
if errorlevel 1 (
    echo [ERROR] bcdboot execution failed.
    pause
    goto :CLEANUP
)
echo [OK] Boot files successfully created.

:: -------------------------------------------------------------
:: 7. Provision Default Fallback Bootloader
:: -------------------------------------------------------------
echo [*] Provisioning default UEFI fallback bootloader...
if not exist "S:\EFI\Boot" mkdir "S:\EFI\Boot"

if exist "S:\EFI\Microsoft\Boot\bootmgfw.efi" (
    copy /y "S:\EFI\Microsoft\Boot\bootmgfw.efi" "S:\EFI\Boot\bootx64.efi" >nul
    echo [OK] Created S:\EFI\Boot\bootx64.efi
)

:: -------------------------------------------------------------
:: 8. Check UEFI NVRAM Environment & Display Entries
:: -------------------------------------------------------------
echo [*] Synchronizing NVRAM table...
bcdedit /store "S:\EFI\Microsoft\Boot\BCD" /set {bootmgr} description "Windows Boot Manager" >nul 2>&1
echo [OK] Motherboard NVRAM entry synced.
echo.

echo [*] Registered Boot Loaders in BCD:
for /f "tokens=1,2*" %%A in ('bcdedit /store "S:\EFI\Microsoft\Boot\BCD" /enum osloader 2^>nul') do (
    if /i "%%A"=="identifier" echo   %%A              %%B
    if /i "%%A"=="device"     echo   %%A                  %%B
    if /i "%%A"=="path"       echo   %%A                    %%B
    if /i "%%A"=="osdevice"   echo   %%A                %%B
)
echo.

:: -------------------------------------------------------------
:: 9. Clean Dismount of EFI Partition (Script-File Based)
:: -------------------------------------------------------------
:CLEANUP
if "!AUTO_MOUNTED!"=="1" (
    echo [*] Unmounting S:...
    set "TMP_DP_UNM=%SCRATCH_DIR%\dp_uefi_unm.txt"
    (
        echo select volume !ESP_VOL!
        echo remove letter=S
    ) > "!TMP_DP_UNM!"
    diskpart /s "!TMP_DP_UNM!" >nul 2>&1
    if exist "!TMP_DP_UNM!" del /f /q "!TMP_DP_UNM!" >nul 2>&1
    echo [OK] S: unmounted cleanly.
)
echo.

echo ============================================================
echo [SUCCESS] UEFI Bootloader Provisioning Complete.
echo ============================================================
echo.
pause
goto :END

:FAIL
echo.
echo ============================================================
echo [FAIL] Execution aborted or encountered errors.
echo ============================================================
echo.
pause
exit /b 1

:END
exit /b 0

Code:
@echo off
setlocal EnableDelayedExpansion

set "PATH=X:\Windows\System32;C:\Windows\System32;%SystemRoot%\System32;%WINDIR%\System32;%PATH%"

title Universal Deployment Verification Utility (UEFI / MBR)
echo ============================================================
echo      Universal Deployment Verification Utility (UEFI / MBR)
echo ============================================================
echo.

:: -------------------------------------------------------------
:: Target Windows Selection (Direct Argument or Interactive)
:: -------------------------------------------------------------
set "TGT_INPUT=%~1"
if not defined TGT_INPUT (
    echo Available Drives with a Windows directory:
    for %%D in (C D E F G H I J K L M N O P Q R S T U V W Y Z) do (
        if exist "%%D:\Windows\System32" (
            echo   - %%D:\Windows
        )
    )
    echo.
    set /p "TGT_INPUT=Enter Target Windows Drive Letter [e.g. C]: "
)
if "!TGT_INPUT!"=="" set "TGT_INPUT=C"

set "TGT_LTR=!TGT_INPUT:~0,1!"
set "TGT_WIN=!TGT_LTR!:"

if not exist "!TGT_WIN!\Windows" (
    echo [ERROR] No valid Windows installation directory found on !TGT_WIN!\.
    echo Please verify the drive letter from the list above.
    pause
    exit /b 1
)

echo Target selected: !TGT_WIN!\
echo.

:: -------------------------------------------------------------
:: 1. Verify Core Windows Files
:: -------------------------------------------------------------
echo [*] Verifying Windows System Files on !TGT_WIN!\...
set "CORE_FAIL=0"

for %%F in (ntoskrnl.exe winresume.efi winload.efi winload.exe) do (
    if exist "!TGT_WIN!\Windows\System32\%%F" (
        echo [PASS] Found: %%F
    )
)

for %%H in (SYSTEM SOFTWARE) do (
    if exist "!TGT_WIN!\Windows\System32\config\%%H" (
        echo [PASS] Found: Registry Hive %%H
    ) else (
        echo [FAIL] Missing: Registry Hive %%H
        set "CORE_FAIL=1"
    )
)

if "!CORE_FAIL!"=="1" (
    echo [ERROR] Core Windows registry files are missing on !TGT_WIN!.
    pause
    exit /b 1
)
echo [RESULT] Core Windows system files successfully verified.
echo.

:: -------------------------------------------------------------
:: 2. Boot Mode Selection (Direct Argument or Interactive)
:: -------------------------------------------------------------
set "BOOT_CHOICE=%~2"
if defined BOOT_CHOICE goto :CHECK_BOOT_CHOICE

echo ============================================================
echo Select Boot Mode to Verify:
echo ============================================================
echo [1] UEFI (GPT - ESP FAT32 partition and EFI BCD Store)
echo [2] MBR  (Legacy BIOS - bootmgr and Active partition)
set "BOOT_CHOICE=1"
set /p "BOOT_CHOICE=Enter choice [1 or 2, default: 1]: "

:CHECK_BOOT_CHOICE
if "!BOOT_CHOICE!"=="" set "BOOT_CHOICE=1"
echo.

if "!BOOT_CHOICE!"=="1" goto :VERIFY_UEFI
if "!BOOT_CHOICE!"=="2" goto :VERIFY_MBR
goto :CLEANUP_EXIT

:: -------------------------------------------------------------
:: Mode 1: UEFI Verification
:: -------------------------------------------------------------
:VERIFY_UEFI
echo ============================================================
echo Verifying UEFI Bootloader Configuration
echo ============================================================

set "AUTO_MOUNTED=0"

echo [*] Identifying physical disk for !TGT_WIN!...
set "PARENT_DISK="

for /f "tokens=1,2,3*" %%A in ('^(echo select volume !TGT_LTR! ^& echo detail volume^) ^| diskpart') do (
    if /i "%%A"=="Disk" (
        set "PARENT_DISK=%%B"
    ) else if "%%A"=="*" if /i "%%B"=="Disk" (
        set "PARENT_DISK=%%C"
    )
)

if defined PARENT_DISK (
    for /f "delims=0123456789" %%Z in ("!PARENT_DISK!") do set "PARENT_DISK="
)

if defined PARENT_DISK (
    echo [*] Target Windows [!TGT_WIN!] is located on Disk !PARENT_DISK!.
) else (
    echo [WARN] Unable to determine parent disk. Scanning all available volumes.
)

set "ESP_VOL="

if defined PARENT_DISK (
    for /f "tokens=1,2,3,4,5,6,7,8*" %%A in ('^(echo select disk !PARENT_DISK! ^& echo detail disk^) ^| diskpart ^| findstr /I "FAT32"') do (
        if /i "%%A"=="Volume" (
            set "LINE_FAT=%%A %%B %%C %%D %%E %%F %%G %%H"
            echo !LINE_FAT! | findstr /V /I "GB Removable" >nul
            if not errorlevel 1 (
                if not defined ESP_VOL set "ESP_VOL=%%B"
            )
        )
    )
)

if not defined ESP_VOL (
    for /f "tokens=1,2,3,4,5,6,7,8*" %%A in ('^(echo list volume^) ^| diskpart ^| findstr /I "FAT32"') do (
        if /i "%%A"=="Volume" (
            set "LINE_FAT=%%A %%B %%C %%D %%E %%F %%G %%H"
            echo !LINE_FAT! | findstr /V /I "GB Removable" >nul
            if not errorlevel 1 (
                if not defined ESP_VOL set "ESP_VOL=%%B"
            )
        )
    )
)

if not defined ESP_VOL (
    echo [!] Could not automatically pinpoint target EFI partition volume.
    set /p "ESP_VOL=Enter FAT32 EFI Volume Number to verify: "
)

if "!ESP_VOL!"=="" (
    echo [FAIL] No volume selected.
    pause
    goto :CLEANUP_EXIT
)

:: Ensure temporary working directory
set "SCRATCH_DIR=%TEMP%"
if not exist "%SCRATCH_DIR%" set "SCRATCH_DIR=X:\windows\temp"
if not exist "%SCRATCH_DIR%" set "SCRATCH_DIR=X:\"

echo [*] Mounting Volume !ESP_VOL! to S:...

:: Release any active or cached mount on S:
mountvol S:\ /D >nul 2>&1

set "TMP_DP_MNT=%SCRATCH_DIR%\dp_mnt_ver.txt"
(
    echo select volume !ESP_VOL!
    echo assign letter=S
) > "%TMP_DP_MNT%"

diskpart /s "%TMP_DP_MNT%" >nul 2>&1
if exist "%TMP_DP_MNT%" del /f /q "%TMP_DP_MNT%" >nul 2>&1
set "AUTO_MOUNTED=1"

:: Allow kernel arrival registration
ping -n 3 127.0.0.1 >nul 2>&1

set "MOUNTED_OK="
for /L %%i in (1,1,6) do (
    if not defined MOUNTED_OK (
        dir S:\ >nul 2>&1 && set "MOUNTED_OK=1"
        if exist "S:\EFI" set "MOUNTED_OK=1"
        if not defined MOUNTED_OK ping -n 2 127.0.0.1 >nul 2>&1
    )
)

if not defined MOUNTED_OK (
    echo [FAIL] EFI partition is not accessible on S:.
    echo [*] Verbose DiskPart Output for Diagnosis:
    (echo select volume !ESP_VOL! & echo assign letter=S) | diskpart
    pause
    goto :CLEANUP_EXIT
)

:RUN_UEFI_CHECKS
if exist "S:\EFI\Microsoft\Boot\bootmgfw.efi" (
    echo [PASS] EFI bootloader found: S:\EFI\Microsoft\Boot\bootmgfw.efi
) else (
    echo [FAIL] EFI bootloader missing: S:\EFI\Microsoft\Boot\bootmgfw.efi
)

if exist "S:\EFI\Boot\bootx64.efi" (
    echo [PASS] Fallback bootloader found: S:\EFI\Boot\bootx64.efi
) else (
    echo [WARN] Fallback bootloader missing: S:\EFI\Boot\bootx64.efi
)

if exist "S:\EFI\Microsoft\Boot\BCD" (
    echo [PASS] UEFI BCD Store verified.
    echo.
    echo [*] Registered Boot Loaders:
    for /f "tokens=1,2*" %%A in ('bcdedit /store "S:\EFI\Microsoft\Boot\BCD" /enum osloader 2^>nul') do (
        if /i "%%A"=="identifier" echo   %%A              %%B
        if /i "%%A"=="device"     echo   %%A                  %%B
        if /i "%%A"=="path"       echo   %%A                    %%B
        if /i "%%A"=="osdevice"   echo   %%A                %%B
    )
) else (
    echo [FAIL] UEFI BCD Store missing at S:\EFI\Microsoft\Boot\BCD
)

if "!AUTO_MOUNTED!"=="1" (
    set "TMP_DP_UNM=%SCRATCH_DIR%\dp_unm_ver.txt"
    (
        echo select volume !ESP_VOL!
        echo remove letter=S
    ) > "%TMP_DP_UNM%"
    diskpart /s "%TMP_DP_UNM%" >nul 2>&1
    if exist "%TMP_DP_UNM%" del /f /q "%TMP_DP_UNM%" >nul 2>&1
    echo [PASS] Unmounted S: cleanly.
)
goto :CLEANUP_EXIT

:: -------------------------------------------------------------
:: Mode 2: MBR Verification
:: -------------------------------------------------------------
:VERIFY_MBR
echo ============================================================
echo Verifying MBR Bootloader Configuration
echo ============================================================

set "MBR_TARGET="
set "MBR_AUTO_MOUNTED=0"

for %%D in (S C D !TGT_LTR!) do (
    if exist "%%D:\bootmgr" (
        if exist "%%D:\Boot\BCD" (
            set "MBR_TARGET=%%D:"
            goto :RUN_MBR_CHECKS
        )
    )
)

echo [*] Searching for System Reserved partition...
set "SYS_RES_VOL="
set "MBR_PARENT_DISK="

for /f "tokens=1,2,3*" %%A in ('^(echo select volume !TGT_LTR! ^& echo detail volume^) ^| diskpart') do (
    if /i "%%A"=="Disk" (
        set "MBR_PARENT_DISK=%%B"
    ) else if "%%A"=="*" if /i "%%B"=="Disk" (
        set "MBR_PARENT_DISK=%%C"
    )
)

if defined MBR_PARENT_DISK (
    for /f "delims=0123456789" %%Z in ("!MBR_PARENT_DISK!") do set "MBR_PARENT_DISK="
)

if defined MBR_PARENT_DISK (
    for /f "tokens=1,2,3,4,5,6,7*" %%A in ('^(echo select disk !MBR_PARENT_DISK! ^& echo detail disk^) ^| diskpart ^| findstr /I "NTFS"') do (
        if /i "%%A"=="Volume" (
            echo %%C %%D | findstr /I "System" >nul
            if not errorlevel 1 (
                if not defined SYS_RES_VOL set "SYS_RES_VOL=%%B"
            )
        )
    )
)

if not defined SYS_RES_VOL (
    for /f "tokens=1,2,3,4,5,6,7*" %%A in ('^(echo list volume^) ^| diskpart ^| findstr /I "NTFS"') do (
        if /i "%%A"=="Volume" (
            echo %%C %%D | findstr /I "System" >nul
            if not errorlevel 1 (
                if not defined SYS_RES_VOL set "SYS_RES_VOL=%%B"
            )
        )
    )
)

if not defined SYS_RES_VOL (
    echo [WARN] Could not find partition labeled "System Reserved".
    goto :RUN_MBR_CHECKS
)

echo [*] Found System Reserved as Volume !SYS_RES_VOL!. Mounting to S:...
mountvol S:\ /D >nul 2>&1

set "TMP_DP_MNT=%SCRATCH_DIR%\dp_mnt_mbr.txt"
(
    echo select volume !SYS_RES_VOL!
    echo assign letter=S
) > "%TMP_DP_MNT%"
diskpart /s "%TMP_DP_MNT%" >nul 2>&1
if exist "%TMP_DP_MNT%" del /f /q "%TMP_DP_MNT%" >nul 2>&1
set "MBR_AUTO_MOUNTED=1"

ping -n 3 127.0.0.1 >nul 2>&1

set "MBR_MOUNTED_OK="
dir S:\ >nul 2>&1 && set "MBR_MOUNTED_OK=1"
if exist "S:\Boot\BCD" set "MBR_MOUNTED_OK=1"

if not defined MBR_MOUNTED_OK (
    echo [FAIL] Failed to assign S: to Volume !SYS_RES_VOL!.
) else (
    set "MBR_TARGET=S:"
    echo [PASS] Successfully mounted Volume !SYS_RES_VOL! to S:.
)

:RUN_MBR_CHECKS
if not defined MBR_TARGET set "MBR_TARGET=!TGT_WIN!"

echo.
echo Target boot volume being verified: !MBR_TARGET!\

if exist "!MBR_TARGET!\bootmgr" (
    echo [PASS] Found bootmgr at !MBR_TARGET!\bootmgr
) else (
    echo [FAIL] Missing bootmgr at !MBR_TARGET!\bootmgr
)

if exist "!MBR_TARGET!\Boot\BCD" (
    echo [PASS] MBR BCD Store verified at !MBR_TARGET!\Boot\BCD
    echo.
    echo [*] Registered Boot Loaders:
    for /f "tokens=1,2*" %%A in ('bcdedit /store "!MBR_TARGET!\Boot\BCD" /enum osloader 2^>nul') do (
        if /i "%%A"=="identifier" echo   %%A              %%B
        if /i "%%A"=="device"     echo   %%A                  %%B
        if /i "%%A"=="path"       echo   %%A                    %%B
        if /i "%%A"=="osdevice"   echo   %%A                %%B
    )
) else (
    echo [FAIL] MBR BCD Store missing at !MBR_TARGET!\Boot\BCD
)

if "!MBR_AUTO_MOUNTED!"=="1" (
    set "TMP_DP_UNM=%SCRATCH_DIR%\dp_unm_mbr.txt"
    (
        echo select volume !SYS_RES_VOL!
        echo remove letter=S
    ) > "%TMP_DP_UNM%"
    diskpart /s "%TMP_DP_UNM%" >nul 2>&1
    if exist "%TMP_DP_UNM%" del /f /q "%TMP_DP_UNM%" >nul 2>&1
    echo [PASS] Unmounted S: cleanly.
)

:CLEANUP_EXIT
echo.
echo ============================================================
echo Verification Complete.
echo ============================================================
echo.
pause
exit /b 0

---

Live WinPE Field Verification Logs (Internal SSD & External HDD)

Code:
K:\Upload to ElevenForum>deploy_win11.bat

===============================================================================
Available Editions in K:\sources\install.wim:
===============================================================================

Deployment Image Servicing and Management tool
Version: 10.0.26100.8972

Details for image : K:\sources\install.wim

Index : 1  - Windows 11 Home
Index : 2  - Windows 11 Home N
Index : 3  - Windows 11 Home Single Language
Index : 4  - Windows 11 Education
Index : 5  - Windows 11 Education N
Index : 6  - Windows 11 Pro
Index : 7  - Windows 11 Pro N
Index : 8  - Windows 11 Pro Education
Index : 9  - Windows 11 Pro Education N
Index : 10 - Windows 11 Pro for Workstations
Index : 11 - Windows 11 Pro N for Workstations

Enter the Index number to install [default: 1]: 6

===============================================================================
Disk Configuration:
===============================================================================
[1] Use an existing partition [no wipe]
[2] Wipe an entire disk and create MBR [System Reserved + OS]
[3] Wipe an entire disk and create GPT [EFI + MSR + OS]
===============================================================================
Enter choice [1, 2, or 3, default: 1]: 1

===============================================================================
Available Volumes:
===============================================================================
  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     C   Windows 10   NTFS   Partition     64 GB  Healthy
  Volume 1     D   Windows 11   NTFS   Partition     55 GB  Healthy
  Volume 2                      FAT32  Partition    100 MB  Healthy    Hidden
  Volume 3     E   Windows_26H  NTFS   Partition    130 GB  Healthy
  Volume 4     F   TEST WINDOW  NTFS   Partition    112 GB  Healthy
  Volume 5     G   DATA BACKUP  NTFS   Partition    585 GB  Healthy
  Volume 6     H   RECOVERY PA  NTFS   Partition     90 GB  Healthy
  Volume 7     I   4DDIG        FAT32  Partition     10 GB  Healthy
  Volume 8         SYSTEM       FAT32  Partition    500 MB  Healthy    Hidden
  Volume 9                      NTFS   Partition    820 MB  Healthy    Hidden
  Volume 10    J   BOOT         FAT32  Removable   2048 MB  Healthy
  Volume 11    K   INSTALL      NTFS   Removable     27 GB  Healthy

Enter the target drive letter to install to [default: D]: E

===============================================================================
Select Firmware / Boot Mode for Existing Drive:
===============================================================================
[1] UEFI [GPT - Writes to EFI System Partition]
[2] MBR / Legacy BIOS [Auto-detect System Reserved or existing boot store]
[3] MBR / Legacy BIOS [Standalone - write bootmgr directly to E:]
===============================================================================
Enter choice [1, 2, or 3, default: 1]: 1

===============================================================================
Target Installation Overview
===============================================================================
Source WIM    : K:\sources\install.wim
Selected Index: 6
Target Drive  : E:\
===============================================================================

Skip DISM extraction and test bootloader configuration only? [Y/N, default: N]: Y

[*] Skipping DISM image extraction. Proceeding directly to bootloader setup...

===============================================================================
Configuring UEFI Bootloader and NVRAM
===============================================================================
[OK] Detected matching EFI System Partition: Volume 8
Enter FAT32 EFI Volume Number to mount [default: 8]: 8
[*] Mounting Volume 8 to S:...
[PASS] Volume 8 successfully mounted and accessible on S:.
Boot files successfully created.
[PASS] UEFI boot files written successfully.
[PASS] Created fallback bootx64.efi.
[PASS] NVRAM entry synchronized.
[PASS] Unmounted S: cleanly.

[*] Checking BCD for dynamic locate pointers...
[PASS] BCD validation completed.

===============================================================================
[SUCCESS] Windows 11 Deployment Cycle Completed.
Target: E:\
===============================================================================

[*] Launching automated deployment verification utility...

============================================================
     Universal Deployment Verification Utility (UEFI / MBR)
============================================================

Target selected: E:\

[*] Verifying Windows System Files on E:\...
[PASS] Found: ntoskrnl.exe
[PASS] Found: winresume.efi
[PASS] Found: winload.efi
[PASS] Found: winload.exe
[PASS] Found: Registry Hive SYSTEM
[PASS] Found: Registry Hive SOFTWARE
[RESULT] Core Windows system files successfully verified.

============================================================
Verifying UEFI Bootloader Configuration
============================================================
[*] Identifying physical disk for E:...
[*] Target Windows [E:] is located on Disk 1.
[*] Mounting Volume 8 to S:...
[PASS] EFI bootloader found: S:\EFI\Microsoft\Boot\bootmgfw.efi
[PASS] Fallback bootloader found: S:\EFI\Boot\bootx64.efi
[PASS] UEFI BCD Store verified.

[*] Registered Boot Loaders:
  identifier              {4006154f-cf54-11f1-afdf-a53569bc85a3}
  device                  partition=F:
  path                    \Windows\system32\winload.efi
  osdevice                partition=F:
  identifier              {baa180a0-ce82-11f1-8f3f-f318d0052f68}
  device                  ramdisk=[E:]\Recovery\WindowsRE\Winre.wim,{baa180a1-ce82-11f1-8f3f-f318d0052f68}
  path                    \windows\system32\winload.efi
  osdevice                ramdisk=[E:]\Recovery\WindowsRE\Winre.wim,{baa180a1-ce82-11f1-8f3f-f318d0052f68}
  identifier              {default}
  device                  partition=E:
  path                    \Windows\system32\winload.efi
  osdevice                partition=E:
[PASS] Unmounted S: cleanly.

============================================================
Verification Complete.
============================================================

Code:
K:\Upload to ElevenForum>deploy_win11.bat

===============================================================================
Available Editions in K:\sources\install.wim:
===============================================================================
Index : 3  - Windows 11 Home Single Language

Enter the Index number to install [default: 1]: 3

===============================================================================
Disk Configuration:
===============================================================================
[1] Use an existing partition [no wipe]
[2] Wipe an entire disk and create MBR [System Reserved + OS]
[3] Wipe an entire disk and create GPT [EFI + MSR + OS]
===============================================================================
Enter choice [1, 2, or 3, default: 1]: 1

Enter the target drive letter to install to [default: D]: C

===============================================================================
Select Firmware / Boot Mode for Existing Drive:
===============================================================================
[1] UEFI [GPT - Writes to EFI System Partition]
[2] MBR / Legacy BIOS [Auto-detect System Reserved or existing boot store]
[3] MBR / Legacy BIOS [Standalone - write bootmgr directly to C:]
===============================================================================
Enter choice [1, 2, or 3, default: 1]: 1

Target Installation Overview
===============================================================================
Source WIM    : K:\sources\install.wim
Selected Index: 3
Target Drive  : C:\
===============================================================================

Skip DISM extraction and test bootloader configuration only? [Y/N, default: N]: Y
[*] Skipping DISM image extraction. Proceeding directly to bootloader setup...

===============================================================================
Configuring UEFI Bootloader and NVRAM
===============================================================================
[OK] Detected matching EFI System Partition: Volume 2
Enter FAT32 EFI Volume Number to mount [default: 2]: 2
[*] Mounting Volume 2 to S:...
[PASS] Volume 2 successfully mounted and accessible on S:.
Boot files successfully created.
[PASS] UEFI boot files written successfully.
[PASS] Created fallback bootx64.efi.
[PASS] NVRAM entry synchronized.
[PASS] Unmounted S: cleanly.

[*] Checking BCD for dynamic locate pointers...
[PASS] BCD validation completed.

===============================================================================
[SUCCESS] Windows 11 Deployment Cycle Completed.
Target: C:\
===============================================================================

[*] Launching automated deployment verification utility...

============================================================
     Universal Deployment Verification Utility (UEFI / MBR)
============================================================

Target selected: C:\

[*] Verifying Windows System Files on C:\...
[PASS] Found: ntoskrnl.exe
[PASS] Found: winresume.efi
[PASS] Found: winload.efi
[PASS] Found: winload.exe
[PASS] Found: Registry Hive SYSTEM
[PASS] Found: Registry Hive SOFTWARE
[RESULT] Core Windows system files successfully verified.

============================================================
Verifying UEFI Bootloader Configuration
============================================================
[*] Identifying physical disk for C:...
[*] Target Windows [C:] is located on Disk 0.
[*] Mounting Volume 2 to S:...
[PASS] EFI bootloader found: S:\EFI\Microsoft\Boot\bootmgfw.efi
[PASS] Fallback bootloader found: S:\EFI\Boot\bootx64.efi
[PASS] UEFI BCD Store verified.

[*] Registered Boot Loaders:
  identifier              {2ce9cdd9-cf7b-11f1-9dc0-c4898ccbcada}
  device                  partition=D:
  path                    \Windows\system32\winload.efi
  osdevice                partition=D:
  identifier              {default}
  device                  partition=C:
  path                    \Windows\system32\winload.efi
  osdevice                partition=C:
[PASS] Unmounted S: cleanly.

============================================================
Verification Complete.
============================================================

Code:
K:\Upload to ElevenForum>create_uefi.bat
============================================================
       UEFI Bootloader and NVRAM Fallback Provisioner
============================================================

Available Drives with a Windows directory:
  - C:\Windows
  - D:\Windows
  - E:\Windows
  - F:\Windows

Enter Target Windows Drive Letter [e.g. C]: C
[OK] Verified target Windows on C:\.

[*] Target Windows [C:] resides on Disk 0.

[*] Scanning disks for FAT32 EFI partitions...
[OK] Detected matching EFI System Partition: Volume 2
Enter FAT32 EFI Volume Number to provision [default: 2]: 2
[OK] Target EFI Volume selected: 2

[*] Mounting Volume 2 to S:...
[OK] EFI Partition mounted on S:.

[*] Running bcdboot to populate UEFI boot files...
Boot files successfully created.
[OK] Boot files successfully created.
[*] Provisioning default UEFI fallback bootloader...
[OK] Created S:\EFI\Boot\bootx64.efi
[*] Synchronizing NVRAM table...
[OK] Motherboard NVRAM entry synced.

[*] Registered Boot Loaders in BCD:
  identifier              {2ce9cdd9-cf7b-11f1-9dc0-c4898ccbcada}
  device                  partition=D:
  path                    \Windows\system32\winload.efi
  osdevice                partition=D:
  identifier              {default}
  device                  partition=C:
  path                    \Windows\system32\winload.efi
  osdevice                partition=C:

[*] Unmounting S:...
[OK] S: unmounted cleanly.

============================================================
[SUCCESS] UEFI Bootloader Provisioning Complete.
============================================================

K:\Upload to ElevenForum>create_uefi.bat
============================================================
       UEFI Bootloader and NVRAM Fallback Provisioner
============================================================

Available Drives with a Windows directory:
  - C:\Windows
  - D:\Windows
  - E:\Windows
  - F:\Windows

Enter Target Windows Drive Letter [e.g. C]: E
[OK] Verified target Windows on E:\.

[*] Target Windows [E:] resides on Disk 1.

[*] Scanning disks for FAT32 EFI partitions...
[OK] Detected matching EFI System Partition: Volume 8
Enter FAT32 EFI Volume Number to provision [default: 8]: 8
[OK] Target EFI Volume selected: 8

[*] Mounting Volume 8 to S:...
[OK] EFI Partition mounted on S:.

[*] Running bcdboot to populate UEFI boot files...
Boot files successfully created.
[OK] Boot files successfully created.
[*] Provisioning default UEFI fallback bootloader...
[OK] Created S:\EFI\Boot\bootx64.efi
[*] Synchronizing NVRAM table...
[OK] Motherboard NVRAM entry synced.

[*] Registered Boot Loaders in BCD:
  identifier              {default}
  device                  partition=E:
  path                    \Windows\system32\winload.efi
  osdevice                partition=E:
  identifier              {4006154f-cf54-11f1-afdf-a53569bc85a3}
  device                  partition=F:
  path                    \Windows\system32\winload.efi
  osdevice                partition=F:
  identifier              {baa180a0-ce82-11f1-8f3f-f318d0052f68}
  device                  ramdisk=[E:]\Recovery\WindowsRE\Winre.wim,{baa180a1-ce82-11f1-8f3f-f318d0052f68}
  path                    \windows\system32\winload.efi
  osdevice                ramdisk=[E:]\Recovery\WindowsRE\Winre.wim,{baa180a1-ce82-11f1-8f3f-f318d0052f68}

[*] Unmounting S:...
[OK] S: unmounted cleanly.

============================================================
[SUCCESS] UEFI Bootloader Provisioning Complete.
============================================================
 

Attachments

My Computer My Computer

At a glance

Window 11 v24H2 Build 26100.2033Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz 3.10 GHz4.00 GB (3.89 GB usable)Onboard
OS
Window 11 v24H2 Build 26100.2033
Computer type
PC/Desktop
Manufacturer/Model
ASSEMMBLED
CPU
Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz 3.10 GHz
Motherboard
ZEBRONICS
Memory
4.00 GB (3.89 GB usable)
Graphics Card(s)
Onboard
Sound Card
Onboard
Monitor(s) Displays
LG
Screen Resolution
1366x768
Hard Drives
Toshiba HDD 1 TB
Keyboard
Mechanical
Mouse
Mechanical
Internet Speed
700 kb/s
Browser
Microsoft EDGE, CHROME
Antivirus
Microsoft Defender

Latest Support Threads

Back
Top Bottom