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


Ramesh Sharma

Well-known member
Member
Local time
10:19 AM
Posts
297
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)
[CODE]
[/SPOILER]

THANKS FOR READING THIS THREAD.
 
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
Back
Top Bottom