Win10 Setup Disk [For UEFI or BIOS / UEFI with Secure Boot / Install.wim over 4 GB]

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

  1. tigercheng

    tigercheng MDL Junior Member

    May 4, 2015
    80
    93
    0
    freddie-o, some clarifications needed from you on the above. Does it mean that in order to create the said UEFI bootable USB, the windows I am using to create it must be of Windows 10 v1703" (Build 15063) and later versions?

    Thanks for sharing of the tool and I intend to use it once you cleared my doubt.
     
  2. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    655
    734
    30
    #262 freddie-o, Nov 21, 2019
    Last edited: Nov 21, 2019
    (OP)
    Yes, earlier versions of Windows do not support reading and creating multiple partitions on removable storage devices. MS only started support for multiple partitions on removable media on Windows 10 Version 1703.
     
  3. uffbros

    uffbros MDL Senior Member

    Aug 9, 2010
    376
    31
    10
  4. tigercheng

    tigercheng MDL Junior Member

    May 4, 2015
    80
    93
    0
    I agree, these two threads really very informative and summarize everything about UEFI bootable USB.
    Freddie-o, good job & thanks for sharing.
     
  5. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    655
    734
    30
    #265 freddie-o, May 2, 2020
    Last edited: Nov 10, 2020
    (OP)
    For a Windows ISO with an install.wim under 4 GB you just need to format your USB disk to FAT32 and copy the contents of your Windows ISO to the disk
    or
    you can use this automated script




    What the script does
    1. Converts your USB disk to MBR scheme.
    2. Creates a FAT32 active partition.
    3. Mounts your Windows ISO.
    4. Copies the entire contents of the Windows ISO to the USB disk.



    Script (Updated Nov 11, 2020)
    Code:
    <# : standard way of doing hybrid batch + powershell scripts
    @title Setup Disk @ forums.mydigitallife.net &color f0
    @set "__ARGS__=%*" &powershell -noprofile "$ScriptPath='%~f0';iex((Get-Content('%~f0') -Raw))" &exit/b
    #>
    #
    #   Website: https://forums.mydigitallife.net/threads/win10-setup-disk-for-uefi-or-bios-uefi-with-secure-boot-install-wim-over-4-gb.79268/
    #
    #   This script must be executed with admin privilege
    #
    #   Test Administrator privileges
    If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
    {
        $uac_error="Elevating UAC for Administrator Privileges failed"
        #   The following test is to avoid infinite looping if elevating UAC for Administrator Privileges failed
        if ($env:__ARGS__ -eq $uac_error) {
        read-host "$uac_error`r`nRight click on the script and select ""Run as administrator""`r`nPress Enter to exit...";exit}
    #   Restart the script to get Administrator privileges and exit
                                                                                      
        Start-Process "$ScriptPath" $uac_error -Verb runAs; exit
    }
    $pswindow = $host.ui.rawui          # create a reference to the console’s UI.RawUI child object
    $pswindow.windowtitle = ([string]($pswindow.windowtitle -split "^.*  ")).trim() ; $ShortTitle=($pswindow.windowtitle -split " @ .*")[0]
    #
    Add-Type -AssemblyName System.Windows.Forms # Load the class System.Windows.Forms
    #
    # Filebrowser dialog object
    $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
        Multiselect = $false # One file can be chosen
        Filter = 'ISO images (*.iso)|*.iso' # Select only iso files
    }
    #
    Function MsgBox {[System.Windows.Forms.MessageBox]::Show($Args[0],$ShortTitle,$Args[1],$Args[2])}
    #
    clear-host
    $USB=$Null
    $Form=New-Object System.Windows.Forms.Form # Create the screen form (window)
    $Form.TopMost = $True
    # Set the title and size of the window:
    $Form.Text=$ShortTitle
    $Form.Font='Consolas,10'
    $Form.Width=420 ; $Form.Height=265
    $Form.StartPosition = "CenterScreen"
    $Form.SizeGripStyle = "Hide"
    [System.Windows.Forms.Application]::EnableVisualStyles();
    
    # Create a drop-down list and fill it
    $USBDiskList=New-Object System.Windows.Forms.ComboBox
    $USBDiskList.DropDownStyle=[System.Windows.Forms.ComboBoxStyle]::DropDownList;
    $USBDiskList.Location=New-Object System.Drawing.Point(20,50)
    $USBDiskList.Size=New-Object System.Drawing.Size(363,22)
    $Form.Controls.Add($SelectUSBDiskList)
    $USBDisks=@() # array with USB disk number
    #
    $Disks=$Null;While (!$Disks){
        If(!($Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")})){
    
                  
            if((MsgBox "Please plug in your USB disk first. `n`nClick OK to continue." "OKCancel" "Information") -eq "Cancel") {exit}}}
    
    $USBDisk=New-Object System.Windows.Forms.Label # Put the USB Disk label on the form
    $USBDisk.Location=New-Object System.Drawing.Point(20,30)
    $USBDisk.Text="USB Disk"                    
    $USBDisk.Size=New-Object System.Drawing.Size(200,20)
    $Form.Controls.Add($USBDisk)
    
    $ISOImage=New-Object System.Windows.Forms.Label # Put the ISO Image label on the form
    $ISOImage.Location=New-Object System.Drawing.Point(20,95)                
    $ISOImage.Size=New-Object System.Drawing.Size(200,20)
    $ISOImage.text="ISO Image"
    $Form.Controls.Add($ISOImage)
    
    $ISOFile=New-Object System.Windows.Forms.Label # Put the ISO file name on the form
    $ISOFile.Location=New-Object System.Drawing.Point(20,115)
    $ISOFile.Text=" "
    $ISOFile.Size=New-Object System.Drawing.Size(364,24)
    $ISOFile.Backcolor = [System.Drawing.Color]::White
    $ISOFile.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
    $Form.Controls.Add($ISOFile)
    
    $CancelButton=New-Object System.Windows.Forms.Button # Put the Cancel button on the form
    $CancelButton.Location=New-Object System.Drawing.Point(285,180)
    $CancelButton.Text="Cancel"                                                          
    $CancelButton.Size=New-Object System.Drawing.Size(100,26)
    $Form.Controls.Add($CancelButton)
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    
    $SelectISOButton=New-Object System.Windows.Forms.Button # Put the Select ISO button on the form
    $SelectISOButton.Location=New-Object System.Drawing.Point(175,180)
    $SelectISOButton.Text="Select ISO"                                                                  
    $SelectISOButton.Size=New-Object System.Drawing.Size(100,26)
    $Form.Controls.Add($SelectISOButton)
    $CreateDiskButton=New-Object System.Windows.Forms.Button # Put the Create Disk button on the form
    $CreateDiskButton.Location=New-Object System.Drawing.Point(65,180)
    $CreateDiskButton.Text="Create Disk"                                
                                        
    $CreateDiskButton.Size=New-Object System.Drawing.Size(100,26)
    $Form.Controls.Add($CreateDiskButton)
    $CreateDiskButton.Enabled = $false
    $CreateDiskButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
    
    $SelectISOButton.Add_Click({
        If ($FileBrowser.ShowDialog() -ne "Cancel"){ # if Cancel, just ignore
            $Global:ImagePath = $FileBrowser.filename    # return the file name
            $ISOFile.Text= Split-Path -Path $ImagePath -leaf # extract filename and extension (iso)
            if (($ISOFile.Text).length -gt 44) {$ISOFile.Text = $ImagePath.PadRight(100," ").substring(0,43)+"..."}
            $CreateDiskButton.Enabled = $true
            $CreateDiskButton.Focus()}})
    
    Foreach ($USBDisk in $Disks) {
        $FriendlyName=($USBDisk.FriendlyName).PadRight(40," ").substring(0,39)
        $USBDisks+=$USBDisk.DiskNumber
        $USBDiskList.Items.Add(("{0,-39}{1:n2} GB" -f $FriendlyName,($USBDisk.Size/1GB)))|out-null
        $Partitions = Get-Partition | Where-Object { $_.DiskNumber -eq $USBDisk.DiskNumber}
        If ($Partitions) {
            Foreach ($Partition in $Partitions) {
            $Volumes=get-volume | Where-Object {$Partition.AccessPaths -contains  $_.path }
                Foreach ($Volume in $Volumes) {
                    $USBDisks+=$USBDisk.DiskNumber
                    $USBDiskList.Items.Add(("{0,0}({1,1}:){2,-32}[{3:n2} GB]" -f " ", ($Partition.DriveLetter), $Volume.FileSystemLabel.PadRight(25," ").substring(0,25), ($Partition.Size/1GB)))|out-null
                }
            }
        }
    }
    $form.Controls.Add($USBDiskList)
    $USBDiskList.SelectedIndex=0
    #
    $Groupbox=New-Object System.Windows.Forms.Groupbox # Add a group box on the form
    $Groupbox.Location=New-Object System.Drawing.Point(7,0)
    $Groupbox.Text=""
    $Groupbox.Size=New-Object System.Drawing.Size(390,220)
    $Form.Controls.Add($Groupbox)
    #                                                                              
    if($form.ShowDialog() -eq "Cancel") {MsgBox "The script was cancelled." "OK" "Information"|out-Null;exit}
    #
    # At this point the mounted USB disk and the iso image file path are defined
    #
    $USB=$USBDisks[$USBDiskList.SelectedIndex]
    #
    If((MsgBox "WARNING! `n`nYour USB disk will be converted to MBR scheme, repartitioned and reformatted.`n`nAll partitions and data currently stored in the USB disk will be erased.`r`n`r`nAre you sure you want to continue?" "YESNO" "Warning") -eq "NO"){exit}
    # Mount the image file if not already mounted and get the drive letter
    #
    #   Check if iso already mounted by getting driveletter
    If($ISO=(Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter){$Mounted=$True}    Else
    #    Mount iso and get drive letter
                
        {$Mounted=$False; Mount-DiskImage -ImagePath $ImagePath -StorageType ISO |out-null
         If(!($ISO=(Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter)){Exit}}
    $ISO=$ISO+":"                       
    #                                                                                                                                                                                                                                                                                                      
    Clear-Host
    #    Clear the USB stick
    Clear-Disk $usb -RemoveData -RemoveOEM -Confirm:$false
    set-disk $usb -partitionstyle mbr
    Stop-Service ShellHWDetection -erroraction silentlycontinue|out-null
    #    Create the fat32 boot partition
    $usbfat32=(New-Partition -DiskNumber $usb -UseMaximumSize -AssignDriveLetter -IsActive | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "Win10XPE").DriveLetter + ":"
    robocopy $iso $usbfat32 /e
    
    # Eject the mounted iso image if it was loaded by the script
    If(!$Mounted){DisMount-DiskImage -ImagePath $ImagePath |out-null}
    MsgBox (($ShortTitle -split " @.*")[0]+" completed successfully.") "OK" "Information" |Out-Null;exit
    
    
     
  6. sebus

    sebus MDL Guru

    Jul 23, 2008
    6,133
    1,914
    210
    The statement on its own is misleading (and some people will read just that bit), you do need to emphasize that using the script will actually do it!
     
  7. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,135
    943
    60
    In case of Legacy BIOS boot, you should ensure that the USB disk partition is active :
    Code:
    $usbfat32=(New-Partition -DiskNumber $usb -UseMaximumSize -AssignDriveLetter  -IsActive | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "Windows Installation Disk").DriveLetter + ":"







     
  8. qwesta

    qwesta MDL Member

    Jul 22, 2011
    204
    59
    10
    I tried that script, but got errors as shown here in the image
     

    Attached Files:

  9. qwesta

    qwesta MDL Member

    Jul 22, 2011
    204
    59
    10
    How can I check this please?
    And if so, is there another script which covers this limit?
     
  10. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    655
    734
    30
    #273 freddie-o, May 3, 2020
    Last edited: May 10, 2020
    (OP)
    Mount your Windows ISO. Navigate to "sources" folder. Locate "install.wim". Right click "Properties".

    Untitled.png

    Usually this is the error you get when the install.wim is beyond the 4GB limit.




    Win10 Installation Disk 1.9.2 is for install.wims over 4GB




     
  11. qwesta

    qwesta MDL Member

    Jul 22, 2011
    204
    59
    10
    Okay, that was the problem
    Thank you for the explanation
     
  12. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    655
    734
    30
    #276 freddie-o, May 14, 2020
    Last edited: May 14, 2020
    (OP)
    @rpo I don't know why I only noticed this now :confused:
    when booting into uefi the windows cover the entire screen


    20200514_221927.jpg 20200514_221959.jpg
     
  13. qwesta

    qwesta MDL Member

    Jul 22, 2011
    204
    59
    10
    So what is wrong with this, It will disappear after you finish the installation
     
  14. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    655
    734
    30
  15. alcit

    alcit MDL Novice

    Mar 1, 2017
    5
    2
    0
    working great.. good bye install.esd
     
  16. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,135
    943
    60
    This doesn't disturb me...