How does boot.wim look for sources when installing?

Discussion in 'Windows 11' started by Corvinus, Jan 31, 2023.

  1. Corvinus

    Corvinus MDL Novice

    Feb 25, 2014
    16
    2
    0
    #1 Corvinus, Jan 31, 2023
    Last edited: Jan 31, 2023
    Splitting sources folder to fat32/ntfs primary partitions on a simple manually created gpt flash drive worked far better than I had thought. Makes it so simple to deal with the larger-than-fat32-life install.wim file. Had no idea it was this easy to create an uefi bootable drive just having the iso, but makes me wonder exactly what boot.wim does in efforts to find install files. If I can trust this behavior or if it's just random fluke of some kind.

    That \sources\boot.wim on fat32 will be able to always find the rest of \sources\ content on another ntfs partition. I also parked setup.exe on the ntfs drive next to the folder so it can be started via a custom boot.wim if I want to.
     
  2. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,163
    5,978
    150
    #2 Dark Dinosaur, Jan 31, 2023
    Last edited: Jan 31, 2023
    completely wrong way if I understood you correctly
    you only copy the boot files, modify store, to run Source\Boot.wim on the second partition
    (ntfs partition with source & install wim files etc etc)

    Look into this thread,
    https://forums.mydigitallife.net/th...secure-boot-bios-install-wim-over-4-gb.79268/

    Code:
    Mounts your source Windows ISO.
    Converts your target USB disk to MBR partition scheme.
    Creates a FAT32partition. Copies all the necessary boot files/folders (“boot” folder, “efi” folder, “bootmgr”, “bootmgr.efi” and “boot.wim”) from the Windows ISO to the FAT32 partition then hides the partition.
    Creates an NTFS partition. Copies the entire contents of the Windows ISO to the NTFS partition.
    Adds Legacy BootMenuPolicy to the BCD store to show a progress bar while booting on Legacy BIOS systems.
    or this thread,
    https://forums.mydigitallife.net/th...uefi-system-with-install-wim-over-4-gb.79199/

    upload_2023-1-31_20-24-42.png
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Corvinus

    Corvinus MDL Novice

    Feb 25, 2014
    16
    2
    0
    No. It can't be completely wrong if it works. And no, you don't have to do anything with any BCD store at all.

    All I have to do is to use diskpart to select the drive, convert gpt, create par pri fat32 and ntfs, assign letters. Put all boot files on fat32 but only \sources\boot.wim The rest of sources on the nfts partition.

    Lo and behold, it will boot and run perfectly fine on any uefi computer. So, as my original question stated, I'm curious how boot.wim finds the sources folder on the other partition. If it's made to scan all drives or selects the second one or what.
     
  4. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,163
    5,978
    150
    now I curios.
    I look into it using bootIce.
    its not have path to a specific drive, only to '\sources\etc'
    trying look for more documentation about that in the web

    upload_2023-1-31_20-46-8.png
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. berr1sfueller

    berr1sfueller MDL Senior Member

    Nov 17, 2022
    413
    451
    10
    WIM is a container/archive, and does not detect. Setup.exe is doing the source-folder detection.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Corvinus

    Corvinus MDL Novice

    Feb 25, 2014
    16
    2
    0
    "boot.wim\2\sources\setup.exe" ? Then at least I have something to reverse in IDA and take a closer look.

    No s**t...
     
  7. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,479
    1,474
    60
    I share your interrogation. I have been working a lot on this thread : Win10+ Setup Disk (Works with UEFI Secure Boot / BIOS / Install.wim over 4 GB) | My Digital Life Forums
    It works, but I don't understand why it works; how can boot.wim on the fat32 partition find the ntfs partition? Perhaps it is searching on the drives present on the system to find an install.wim?
    This is incomprehensible like quantum mechanics; it works, but we don't know why.
     
  8. berr1sfueller

    berr1sfueller MDL Senior Member

    Nov 17, 2022
    413
    451
    10
    Has nothing to do with the type of partition the WIM is located on. NTFS partitions automatically mount during boot.
    Yes, Setup.exe source folder detection spans across partitions. Except it's not really that interesting due to the fact it's scanning drive letters by this point, not boot objects. The fat32 partition isn't even being referenced anymore once booted into a WIM.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,479
    1,474
    60
    Once booted into boot.wim, I suppose the content of the second index is loaded into the ram disk x: and setup.exe in contained in the source folder.
     
  10. Corvinus

    Corvinus MDL Novice

    Feb 25, 2014
    16
    2
    0
    I've done a few more tests, figuring that maybe boot.wim is entirely standalone with its own sources. But it stops at finding a SATA driver during setup on its own. The setup.exe inside boot.wim (ran as x:\sources\setup.exe during boot) definitely goes on a search for the rest of sources. I wrote a script yesterday where I create 4 partitions. 2x fat32 with boot.wims (one a custom ISO PE I use on weekly basis and another with rufus baked 11 tweaks), 3rd ntfs with sources incl. install.wim I can run from my own ISO PE, and a 4th just for misc files and whatever.

    If booting from the setup boot.wim, it still finds the 3rd partition where the needed sources are. if I remove that source, it halts on missing SATA driver. So it definitely uses it.

    Interesting point is that it scans letters at all, to me at least. I always assumed it was hardcoded somewhere. The flexibility of having the sources and install.wim on any ntfs volume without care is great.


    By skimming over winsetup.dll (called via boot.wim sources/setup.exe via autorun.dll):

    Module_Init_SourceMedia():
    WdsSubscribeEx(v4, L"SourceMedia", 6422528i64, sub_8C390, v7):

    Seems to iterate disks with CreateFileW (common for disk IO),
    uses GetLogicalDriveStringsW on it and proceeds to:

    "FindSetupMedia:Checking source type %d."
    Builds "Sources" string and GetFileAttributesW.

    Then logs via WDS based on return value:
    "Callback_WinPE_SetSourceMediaInfo:Sources folder path is [%s]".

    It all seems tied closely to wdscore.dll so I didn't bother spending more time on it, but there's definitely drive and volume iteration going on and will make it so easy to not having to deal with ESD or WIM splitting anymore. I'm left wondering how long this have been the case, perhaps since recent 10 builds at least.
     
  11. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,163
    5,978
    150
    #11 Dark Dinosaur, Feb 1, 2023
    Last edited: Feb 1, 2023
    Not work ...
    Not work buddy
    Separate the sources folder apart from EFI partition
    kept the original EFI folder, nothing changed
    Nada nothing work. Test it now.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,479
    1,474
    60
    It worked with earlier version of windows 10 but you need at least 1703 to be able to partition a usb flash drive, unless you use third party software.
     
  13. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,163
    5,978
    150
    #13 Dark Dinosaur, Feb 1, 2023
    Last edited: Feb 1, 2023
    it does work if I apply this code. (from RPO ^ Above)
    rebuild the bcd store file from scratch
    data partition contains all the files,
    efi partition have boot files only

    efi bcd file --> point to --> DATA partition
    ramdisk=[!targetDrive!:]\sources\boot.wim,!ramdisk!

    Code:
    >nul popd
    >nul 2>nul md "!EFI_PARTITION!:\EFI"
    >nul 2>nul xcopy "!cd!\EFI" "!EFI_PARTITION!:\EFI" /e /q /g /h /r /y /c /i
    
    >nul 2>nul md "!EFI_PARTITION!:\BOOT"
    >nul 2>nul xcopy "!cd!\BOOT" "!EFI_PARTITION!:\BOOT" /e /q /g /h /r /y /c /i
    
    >nul 2>nul copy /y "!cd!\BOOTMGR*.*" "!EFI_PARTITION!:\"
    Code:
    echo:
    Echo Remove old BCD store entries
    >nul 2>nul bcdedit /store "!EFI_PARTITION!:\boot\bcd" /f /delete {default}
    >nul 2>nul bcdedit /store "!EFI_PARTITION!:\boot\bcd" /f /delete {memdiag}
    >nul 2>nul bcdedit /store "!EFI_PARTITION!:\EFI\Microsoft\boot\bcd" /f /delete {default}
    >nul 2>nul bcdedit /store "!EFI_PARTITION!:\EFI\Microsoft\boot\bcd" /f /delete {memdiag}.
    
    echo:
    
    rem Credit RPO
    rem https://forums.mydigitallife.net/threads/79199/
    
    >nul pushd "!targetDrive!:\"
    
    Echo Creating BCD entry for Windows Setup [boot\bcd]
    set "BCDEDIT=bcdedit.exe /store "!EFI_PARTITION!:\boot\bcd" "
    
    Echo Creating ramdisksdidevice entry...
    for /f "tokens=2 delims={}" %%g in ('!BCDEDIT!  /create /device') do set ramdisk={%%g}
    >nul 2>nul !BCDEDIT!  /set !ramdisk! description             "Windows Setup"
    >nul 2>nul !BCDEDIT!  /set !ramdisk! ramdisksdidevice        partition=!EFI_PARTITION!:
    >nul 2>nul !BCDEDIT!  /set !ramdisk! ramdisksdipath          \boot\boot.sdi
    
    Echo Adding RAM Boot Windows Setup entry
    for /f "tokens=2 delims={}" %%g in ('!BCDEDIT!  /create /application osloader') do set GUID={%%g}
    >nul 2>nul !BCDEDIT!  /set !guid! device                  ramdisk=[!targetDrive!:]\sources\boot.wim,!ramdisk!
    >nul 2>nul !BCDEDIT!  /set !guid! path                    \Windows\System32\Boot\winload.efi
    >nul 2>nul !BCDEDIT!  /set !guid! description             "Windows Setup"
    >nul 2>nul !BCDEDIT!  /set !guid! osdevice                ramdisk=[!targetDrive!:]\sources\boot.wim,!ramdisk!
    >nul 2>nul !BCDEDIT!  /set !guid! systemroot              \Windows
    >nul 2>nul !BCDEDIT!  /set !guid! detecthal               Yes
    >nul 2>nul !BCDEDIT!  /set !guid! winpe                   Yes
    >nul 2>nul !BCDEDIT!  /displayorder !guid! /addlast
    
    echo:
    
    Echo Creating BCD entry for Windows Setup [EFI\Microsoft\boot\bcd]
    set "BCDEDIT=bcdedit.exe /store "!EFI_PARTITION!:\EFI\Microsoft\boot\bcd" "
    
    Echo Creating ramdisksdidevice entry...
    for /f "tokens=2 delims={}" %%g in ('!BCDEDIT!  /create /device') do set ramdisk={%%g}
    >nul 2>nul !BCDEDIT!  /set !ramdisk! description             "Windows Setup"
    >nul 2>nul !BCDEDIT!  /set !ramdisk! ramdisksdidevice        partition=!EFI_PARTITION!:
    >nul 2>nul !BCDEDIT!  /set !ramdisk! ramdisksdipath          \boot\boot.sdi
    
    Echo Adding RAM Boot Windows Setup entry
    for /f "tokens=2 delims={}" %%g in ('!BCDEDIT!  /create /application osloader') do set GUID={%%g}
    >nul 2>nul !BCDEDIT!  /set !guid! device                  ramdisk=[!targetDrive!:]\sources\boot.wim,!ramdisk!
    >nul 2>nul !BCDEDIT!  /set !guid! path                    \Windows\System32\Boot\winload.efi
    >nul 2>nul !BCDEDIT!  /set !guid! description             "Windows Setup"
    >nul 2>nul !BCDEDIT!  /set !guid! osdevice                ramdisk=[!targetDrive!:]\sources\boot.wim,!ramdisk!
    >nul 2>nul !BCDEDIT!  /set !guid! systemroot              \Windows
    >nul 2>nul !BCDEDIT!  /set !guid! detecthal               Yes
    >nul 2>nul !BCDEDIT!  /set !guid! winpe                   Yes
    >nul 2>nul !BCDEDIT!  /displayorder !guid! /addlast
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Corvinus

    Corvinus MDL Novice

    Feb 25, 2014
    16
    2
    0
    We're way beyond if it works or not. You don't need EFI partition with BCD for any of this, that's the great and interesting thing about it. A GPT drive with a normal primary fat32 partition is all that's needed to show up as UEFI boot option. With boot files and \sources\boot.wim on fat32 and the rest of sources on a second, third, fourth, or N number ntfs one - whatever you want to make. It will boot all day long on computers that has real UEFI option enabled. If it doesn't work for you, you're doing something wrong (like using EFI par) which is pretty hard to do when it's this easy.
     
  15. Corvinus

    Corvinus MDL Novice

    Feb 25, 2014
    16
    2
    0
    Good to know, thx.
     
  16. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,163
    5,978
    150
    that case ... its work fine ...
    I talked about his idea.
    (separate sources folder etc etc)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...