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

Discussion in 'MDL Projects and Applications' started by rpo, Mar 18, 2019.

  1. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,603
    2,673
    60
    @rpo what say ye? add another option to select a folder of extracted ISO?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,603
    2,673
    60
    I also just remembered @rpo ... a week or two ago I tried using the script (similar to this) on an external harddrive but it kept on having errors. Any ideas?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. sebus

    sebus MDL Guru

    Jul 23, 2008
    6,386
    2,041
    210
    Do you really need script to do it for you?

    It takes a moment to do it "by hand" in worse case (surely you do not create it daily?)

    Anyway, the "script" is missing from this thread all together!
     
  4. freddie-o

    freddie-o MDL Expert

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

    What script is missing?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. 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 :)
     
  6. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,603
    2,673
    60
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,502
    1,504
    60
    you are absolutely right
     
  8. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,603
    2,673
    60


    No matter how "simple" a task is, if I can execute it with a script, I will.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,502
    1,504
    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.
     
  10. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,502
    1,504
    60
    No. This complicates the script for marginal use. If the iso is expanded on disk, boot a WinPE system and execute setup.exe.
     
  11. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,603
    2,673
    60
    Updated to Win10 Setup Disk 2.4
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,265
    6,139
    150
    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...
  13. sebus

    sebus MDL Guru

    Jul 23, 2008
    6,386
    2,041
    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)
     
  14. Flipp3r

    Flipp3r MDL Guru

    Feb 11, 2009
    2,021
    970
    90
    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...
  15. sebus

    sebus MDL Guru

    Jul 23, 2008
    6,386
    2,041
    210
    One never knows what kind of system it might be, why get caught when it is so easy not to assume anything?
     
  16. spanishfly

    spanishfly MDL Senior Member

    Dec 5, 2018
    365
    540
    10
    #336 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...
  17. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,603
    2,673
    60
    I'm just curious why one would rather keep a copy of a mounted Windows ISO rather than the ISO itself.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    4,265
    6,139
    150
    Finally Tried it today
    Work as expected :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. spanishfly

    spanishfly MDL Senior Member

    Dec 5, 2018
    365
    540
    10
    #339 spanishfly, Aug 6, 2021
    Last edited: Aug 6, 2021
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. shhnedo

    shhnedo MDL Expert

    Mar 20, 2011
    1,879
    2,515
    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.