Win10+ Setup Disk (Works with UEFI Secure Boot / BIOS / Install.wim over 4 GB)

Discussion in 'Scripting' started by freddie-o, Mar 21, 2019.

  1. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,166
    1,580
    60
    The script is what started this thread. People already know how to do it manually.

    What script is missing?
     
  2. He was right as the thread goes too far in back which makes it difficult for a new user to check if this script is also there on MDL.

    i hope i am correct in this :)
     
  3. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,305
    1,256
    60
    you are absolutely right
     
  4. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,166
    1,580
    60


    No matter how "simple" a task is, if I can execute it with a script, I will.
     
  5. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,305
    1,256
    60
    The script works when creating a USB stick, but fails if the USB device is a hard disk. The failing instructions are :
    Clear-Disk $usb -RemoveData -RemoveOEM -Confirm:$false
    set-disk $usb -partitionstyle mbr
    A workaround is to replace the PowerShell cmdlets by the "old" diskpart :
    @"
    Select disk $USB
    clean
    convert MBR
    rescan
    exit
    "@ | diskpart
    I tested this with an USB connected hard drive on a PC with legacy BIOS; too lazy to test on UEFI pc.
     
  6. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,305
    1,256
    60
    No. This complicates the script for marginal use. If the iso is expanded on disk, boot a WinPE system and execute setup.exe.
     
  7. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    1,718
    2,009
    60
    as far as i know
    you just have to format your USB
    copy all files from the iso
    and use bootsect to make it bootable.
    i dont understand why making 2 partition for this ?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. sebus

    sebus MDL Guru

    Jul 23, 2008
    6,259
    1,979
    210
    Because to be able to do both MBR & UEFI boot, first pertition needs to be FAT32 & second NTFS (where you can have >4Gb .wim file)
     
  9. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,848
    839
    60
    These days most UEFI also include an NTFS driver. You can boot directly from NTFS, no fat32 partition required. Sure if you're still working on old systems you'd still need to do this...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. sebus

    sebus MDL Guru

    Jul 23, 2008
    6,259
    1,979
    210
    One never knows what kind of system it might be, why get caught when it is so easy not to assume anything?
     
  11. spanishfly

    spanishfly MDL Senior Member

    Dec 5, 2018
    352
    521
    10
    #333 spanishfly, Aug 5, 2021
    Last edited: Aug 6, 2021
    If someone comes here seeking to use this threads universal USB answer to package their pre-expanded, Windows media folder, then I have consolidated the suggested solutions.

    If your WIM is smaller than 4GB, than the recommendation is to use the ideas presented by @freddie-o in the just mentioned link: https://forums.mydigitallife.net/th...tall-wim-over-4-gb.79268/page-14#post-1593928
    If your WIM is larger than 4GB and you're working with a device fronted by a modern UEFI, than the recommendation is to format your USB disk as NTFS and copy the contents of your expanded Windows media folder to the disk.
    If you want to use the contents of your expanded Windows media folder to accomplish the goals stated in the title of this thread, then you're welcome to use my less-than-ideal-solution:
    A wrapper script that runs the following pipeline: Expanded Windows media folder to> ISO to> USB with option to keep or delete the created ISO.​

    Download this threads "Win10 Setup Disk X.X.bat" and rename it "Win10 Setup Disk.bat"
    Park "Win10 Setup Disk.bat" next to "Wrapper.bat" which uses ISO making code provided by @BAU see https://forums.mydigitallife.net/threads/abbodi1406s-batch-scripts-repo.74197/page-78#post-1679801
    Run "Wrapper.bat" and follow the instructions.

    Wrapper.bat:
    Code:
    @ECHO OFF
    CD /D "%~dp0"
    CHCP 437 >NUL
    COLOR 9F
    
    SETLOCAL EnableExtensions
    SETLOCAL EnableDelayedExpansion
    ::====================================================================
    CLS
    SET /P DIR= ^> Enter the directory location for your Windows media files:
    
    ECHO:
    ECHO Wait for your new ISO to get created . . .
    
    :: Create-ISO via @BAU :DIR2ISO lean and mean snippet
    CALL :DIR2ISO -dir "%DIR%" "4USB.iso"
    
    ECHO:
    ECHO When the time comes to select your ISO, choose the file "4USB.iso" that just appeared next to this script.
    
    ECHO:
    PAUSE
    
    CLS
    CALL "%~dp0Win10 Setup Disk.bat"
    
    COLOR 9F
    
    ECHO:
    ECHO:
    CHOICE /C:NY /N /M "Do you want to keep your new ISO? ['Y'es/'N'o] : "
    IF %ERRORLEVEL% EQU 2 (
    CLS
    ECHO Rename "4USB.iso" with a proper descriptive name.
    ECHO:
    PAUSE
    GOTO :QUIT
    )
    
    ECHO Deleting "4USB.iso"
    DEL "%~dp04USB.iso"
    ECHO:
    PAUSE
    
    :QUIT
    CLS
    COLOR 1C
    ECHO:
    ECHO Exiting...
    powershell Sleep -s 1
    
    ::====================================================================
    ENDLOCAL EnableExtensions
    ENDLOCAL EnableDelayedExpansion
    
    COLOR 00
    EXIT
    
    :: Source: @BAU https://forums.mydigitallife.net/threads/abbodi1406s-batch-scripts-repo.74197/page-78#post-1679801
    
    $:DIR2ISO: #,# [PARAMS] directory file.iso
    set ^ #="$f0=[io.file]::ReadAllText($env:0);$0=($f0-split'\$%0:.*')[1];$1=$env:1-replace'([`@$])','`$1';iex(\"$0 `r`n %0 $1\")"
    set ^ #=& set "0=%~f0"& set 1=%*& powershell -nop -c %#%& exit/b %errorcode%
    function :DIR2ISO ($dir, $iso) { if (!(test-path -Path $dir -pathtype Container)) {"[ERR] $dir\ :DIR2ISO";exit 1}; $dir2iso=@"
     using System; using System.IO; using System.Runtime.Interop`Services; using System.Runtime.Interop`Services.ComTypes;
     public class dir2iso {public int AveYo=2021; [Dll`Import("shlwapi",CharSet=CharSet.Unicode,PreserveSig=false)]
     internal static extern void SHCreateStreamOnFileEx(string f,uint m,uint d,bool b,IStream r,out IStream s);
     public static void Create(string file, ref object obj, int bs, int tb) { IStream dir=(IStream)obj, iso;
     try {SHCreateStreamOnFileEx(file,0x1001,0x80,true,null,out iso);} catch(Exception e) {Console.WriteLine(e.Message); return;}
     int d=tb>1024 ? 1024 : 1, pad=tb%d, block=bs*d, total=(tb-pad)/d, c=total>100 ? total/100 : total, i=1, MB=(bs/1024)*tb/1024;
     Console.Write("{0,3}%  {1}MB {2}  :DIR2ISO",0,MB,file); if (pad > 0) dir.CopyTo(iso, pad * block, Int`Ptr.Zero, Int`Ptr.Zero);
     while (total-- > 0) {dir.CopyTo(iso, block, Int`Ptr.Zero, Int`Ptr.Zero); if (total % c == 0) {Console.Write("\r{0,3}%",i++);}}
     iso.Commit(0); Console.WriteLine("\r{0,3}%  {1}MB {2}  :DIR2ISO", 100, MB, file); } }
    "@; & { $cs=new-object CodeDom.Compiler.CompilerParameters; $cs.GenerateInMemory=1 #,# no`warnings
     $compile=(new-object Microsoft.CSharp.CSharpCodeProvider).CompileAssemblyFromSource($cs, $dir2iso)
     $BOOT=@(); $bootable=0; $mbr_efi=@(0,0xEF); $images=@('boot\etfsboot.com','efi\microsoft\boot\efisys.bin') #,# efisys_noprompt
     0,1|% { $bootimage=join-path $dir -child $images[$_]; if (test-path -Path $bootimage -pathtype Leaf) {
     $bin=new-object -ComObject ADODB.Stream; $bin.Open(); $bin.Type=1; $bin.LoadFromFile($bootimage)
     $opt=new-object -ComObject IMAPI2FS.BootOptions; $opt.AssignBootImage($bin.psobject.BaseObject); $opt.Manufacturer='Microsoft'
     $opt.PlatformId=$mbr_efi[$_]; $opt.Emulation=0; $bootable=1; $BOOT += $opt.psobject.BaseObject } }
     $fsi=new-object -ComObject IMAPI2FS.MsftFileSystemImage; $fsi.FileSystemsToCreate=4; $fsi.FreeMediaBlocks=0
     if ($bootable) {$fsi.BootImageOptionsArray=$BOOT}; $CONTENT=$fsi.Root; $CONTENT.AddTree($dir,$false); $fsi.VolumeName='DVD_ROM'
     $obj=$fsi.CreateResultImage(); [dir2iso]::Create($iso,[ref]$obj.ImageStream,$obj.BlockSize,$obj.TotalBlocks) };[GC]::Collect()
    } $:DIR2ISO: #,# export directory as (bootable) udf iso - lean and mean snippet by AveYo, 2021
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    1,718
    2,009
    60
    Finally Tried it today
    Work as expected :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. spanishfly

    spanishfly MDL Senior Member

    Dec 5, 2018
    352
    521
    10
    #336 spanishfly, Aug 6, 2021
    Last edited: Aug 6, 2021
    I think you're directing the question to me? If not, please ignore my reply . . .

    I don't keep the mounted Windows ISO. I only keep the extracted WIM which I optimize offline and then, very occasionally, reinsert back into the extracted official ISO files in order to make an optimized ISO or USB.

    I predominantly work only with the Windows WIM as part of:
    Occasionally, I need a Windows ISO or USB
    My need for a "proper" Windows USB is even more rare now that Ventoy (USB) uses a plugin to boot any sized WIM file (Legacy BIOS + UEFI). https://www.ventoy.net/en/plugin_wimboot.html
    Third-party projects (Ventoy) come and go, so I want a reserve ISO/USB making pipeline that is pure Windows (what you've developed here).
    I wrote/shared the script I posted above more as a personal demo test of @BAU 's pure-windows ISO making code. The fact that your pure-windows USB script gets its required ISO is simply a bonus outcome! (AND yes, I know, that oscdimg.exe comes with ADK and is a great tool to make ISOs, but I wanted to see if I could get "DIR2ISO lean and mean snippet" to do the job)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. shhnedo

    shhnedo MDL Expert

    Mar 20, 2011
    1,320
    1,764
    60
    Could one bypass this limitation by just putting the 1507/1511/1607 install.wim inside a more recent version iso? I would imagine it is, since the part that supports particular type of booting is gonna just be dumped on the FAT partition and the install.wim is just a container to be unpacked.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,166
    1,580
    60
    #338 freddie-o, Aug 9, 2021
    Last edited: Aug 9, 2021
    (OP)

    This limitation applies to the version of Windows 10 you are currently using to create the Setup disk -- not the install.wim used for the script.

    Updated the OP so it's clearer.
     
  16. shhnedo

    shhnedo MDL Expert

    Mar 20, 2011
    1,320
    1,764
    60
    ^ Ye I may have not expressed myself all that clearly either. I reading the limitation back then i thought it applies to the WinPE part of 1507-1607 images. Turns out I was thinking about the wrong thing.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. uffbros

    uffbros MDL Senior Member

    Aug 9, 2010
    425
    55
    10
    I just updated to the 2.4 script and while attempting to make the boot disk it no longer makes the 2 separate drives...E & F in my case. Is this because of Windows 11?