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. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
    Figured it out... it's "bootx64.efi" in the \efi\boot folder
     
  2. Carbon12

    Carbon12 MDL Novice

    Aug 29, 2014
    1
    0
    0
    #282 Carbon12, Jul 24, 2020
    Last edited: Jul 24, 2020
    I don't understand why any of this is necessary. So the install.wim is bigger than 4gb...split it to 4gb or less .swm files. Put the whole thing on the fat32 and you can boot legacy or uefi from fat32. One partition, no sweat. I must be missing something...what?
     
  3. qwesta

    qwesta MDL Member

    Jul 22, 2011
    203
    60
    10
    indeed, you are missing something, read about this in the previous posts, why this is necessary
    Answer is in the BIOS, as a tip
     
  4. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,710
    753
    60
    It must be something to do with 20H1. I've just upgraded my ADK to this build & have noticed my WinPE no longer shows the UEFI logo but the Windows logo & my WinPE is at a lower resolution.
    Copying back the 19H1 WinPE wim's & all is back to normal...
     
  5. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,710
    753
    60
    I use a 128GB USB3 key for all my installations. All the Windows and Server Editions I need are included. ESD is much easier to maintain & install from...
     
  6. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
    #286 freddie-o, Jul 24, 2020
    Last edited: Oct 3, 2020
    (OP)
    It's giving people more options. Others prefer not to split their install.wim and disable Secure Boot

    More options here...

    [SOLUTIONS] Installing Windows on UEFI System with install.wim over 4 GB
     
  7. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
    It seems to be "bootx64.efi" of 20H1 ("efi\boot" folder).
     
  8. qwesta

    qwesta MDL Member

    Jul 22, 2011
    203
    60
    10
    i don't know what was wrong with my USB or the script.
    I'm getting this error all the time
     

    Attached Files:

  9. qwesta

    qwesta MDL Member

    Jul 22, 2011
    203
    60
    10
    got the error,
    the device manager wasn't recognising my USB drive, so I went to properties and made driver update, thereafter all went fine as it should be.
    Thank so for the response
     
  10. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
    #291 freddie-o, Oct 3, 2020
    Last edited: Oct 3, 2020
    (OP)
    Updated the script

    v2.0 (Oct 3, 2020)
    Renamed the script to Win10 Setup Disk
    Few cosmetic changes
     
  11. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,138
    947
    60
    Some people get worried because the file explorer shows the two partitions on the usb disk : just remove the driver letter from the fat32 partition by additing the following statement after line 177 (remove-item ($env:temp + "\bcd.*") -force) :
    Code:
    Get-Volume -DriveLetter $usbfat32.substring(0,$usbfat32.Length-1) | Get-Partition | Remove-PartitionAccessPath -accesspath $usbfat32
     
  12. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
    @rpo I was just thinking about this yesterday.
    What if we did this before creating the NTFS partition.
    Will the script work on older versions of Windows that do not support reading and creating multiple partitions on removable storage devices??
    Because it will hide the Fat32 partition first and then create the NTFS partition
     
  13. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,138
    947
    60
    No, it will not work because you can't hide tha fat32 partition as you have robocopy and copy-item statements. Hiding the partition removes the drive letter.
     
  14. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
    Sorry I wasn't clear. What I meant was...
    First create the fat32 partition
    Copy all the boot files/folders to the fat32 partition
    Hide the fat32 partition
    Then, create the ntfs partition
    Copy the ISO to the ntfs partition

    Will this work?

    Also noticed this small detail after creating the Setup disk

    Untitled.png
     
  15. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,138
    947
    60
    Yes, this will work. I will adapt the script and i found the correction for the detail you observed.
     
  16. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
  17. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,138
    947
    60
    Here we are : https://pastebin.com/pMFdzets
    Code:
    <# : standard way of doing hybrid batch + powershell scripts
    @title Win10 Setup Disk 2.1 @ forums.mydigitallife.net &color 3E
    @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.Width=420 ; $Form.Height=250
    $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,45)
    $USBDiskList.Size=New-Object System.Drawing.Size(365,20)
    $USBDiskList.Font='Consolas,10'
    $Form.Controls.Add($SelectUSBDiskList)
    $USBDisks=@() # array with USB disk number
    $Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")}
    
    While (!$Disks) {
    if((MsgBox "Please plug in your USB disk first. `n`nClick OK to continue." "OKCancel" "Information") -eq "Cancel") {exit}
        $Disks=Get-Disk | Where-Object {($_.BusType -eq "USB") -and ($_.OperationalStatus -eq "Online")}
    }
    $USBDisk=New-Object System.Windows.Forms.Label # Put the USB Disk label on the form
    $USBDisk.Location=New-Object System.Drawing.Point(20,25)
    $USBDisk.Text="USB Disk"
    $USBDisk.Font='Default Font,9'
    $USBDisk.Size=New-Object System.Drawing.Size(400,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,90)
    $ISOImage.Font='Default Font,9'
    $ISOImage.Size=New-Object System.Drawing.Size(350,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,110)
    $ISOFile.Text=" "
    $ISOFile.Font='Consolas,10'
    $ISOFile.Size=New-Object System.Drawing.Size(365,23)
    $ISOFile.Backcolor = [System.Drawing.Color]::White
    $ISOFile.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
    $Form.Controls.Add($ISOFile)
    
    $SelectISOButton=New-Object System.Windows.Forms.Button # Put the Select ISO button on the form
    $SelectISOButton.Location=New-Object System.Drawing.Point(195,170)
    $SelectISOButton.Text="Select ISO"
    $SelectISOButton.Font='Default Font,9'
    $SelectISOButton.Size=New-Object System.Drawing.Size(90,26)
    $Form.Controls.Add($SelectISOButton)
    
    $CancelButton=New-Object System.Windows.Forms.Button # Put the Cancel button on the form
    $CancelButton.Location=New-Object System.Drawing.Point(295,170)
    $CancelButton.Text="Cancel"
    $CancelButton.Font='Default Font,9'
    $CancelButton.Size=New-Object System.Drawing.Size(90,26)
    $Form.Controls.Add($CancelButton)
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    
    $CreateDiskButton=New-Object System.Windows.Forms.Button # Put the Create Disk button on the form
    $CreateDiskButton.Location=New-Object System.Drawing.Point(95,170)
    $CreateDiskButton.Text="Create Disk"
    $CreateDiskButton.Font='Default Font,9'
    $CreateDiskButton.Size=New-Object System.Drawing.Size(90,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) {
            If(!$Partition.DriveLetter){$AccessPath="  "} Else {$AccessPath=$Partition.DriveLetter+":"}       
            $Volumes=get-volume | Where-Object {$Partition.AccessPaths -contains  $_.path }
                Foreach ($Volume in $Volumes) {
                    $USBDisks+=$USBDisk.DiskNumber
                    $USBDiskList.Items.Add(("{0,0}({1,2}){2,-32}[{3:n2} GB]" -f " ", ($AccessPath), $Volume.FileSystemLabel.PadRight(25," ").substring(0,25), ($Partition.Size/1GB)))|out-null
                }
            }
        }
    }
    $form.Controls.Add($USBDiskList)
    $USBDiskList.SelectedIndex=0
    #
    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
        $ISO=(Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter  # get drive letter if ISO mounted
    #    Mount iso
        $Mounted=$True
        If (!$ISO) {$Mounted=$False;Mount-DiskImage -ImagePath $ImagePath -StorageType ISO |out-null
        $ISO = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter}
        $ISO=$ISO+":"
    If ($ISO -eq ":") {exit}
    #
    # set bootmenupolicy Legacy
    Copy-Item $ISO"\boot\bcd" $env:temp\bcdmbr -Force
    & bcdedit /store ($env:temp + "\bcdmbr") /set '{default}' bootmenupolicy Legacy
    Set-ItemProperty -Path ($env:temp + "\bcdmbr") -Name IsReadOnly -Value $true
    Copy-Item $ISO"\EFI\Microsoft\boot\bcd" $env:temp\bcdefi -Force
    & bcdedit /store ($env:temp + "\bcdefi") /set '{default}' bootmenupolicy Legacy
    Set-ItemProperty -Path ($env:temp + "\bcdefi") -Name IsReadOnly -Value $true
    #
    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 -Size  1GB -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "BOOT").DriveLetter + ":"
    #    Copy needed files to the fat32 boot partition
    robocopy $iso"\" $usbfat32"\" bootmgr bootmgr.efi
    robocopy $iso"\boot" $usbfat32"\boot" /e /xf $iso\boot\bcd
    robocopy $iso"\efi" $usbfat32"\efi" /e /xf $iso\efi\microsoft\boot\bcd
    robocopy $iso"\sources" $usbfat32"\sources" boot.wim
    Copy-Item ($env:temp + "\bcdmbr") $usbfat32"\boot\bcd" -Force
    Copy-Item ($env:temp + "\bcdefi") $usbfat32"\EFI\Microsoft\boot\bcd" -Force
    #     Remove the drive letter to hide the device
    Get-Volume -DriveLetter $usbfat32.substring(0,$usbfat32.Length-1) | Get-Partition | Remove-PartitionAccessPath -accesspath $usbfat32
    #
    #    Create the NTFS intall partition
    $usbntfs=(New-Partition -DiskNumber $usb -UseMaximumSize -AssignDriveLetter -IsActive | Format-Volume -FileSystem NTFS -NewFileSystemLabel "SETUP").DriveLetter + ":"
    Start-Service ShellHWDetection -erroraction silentlycontinue|out-null
    #
    #    Copy needed files to the NTFS install partition
    robocopy $iso $usbntfs /e /xf $iso\boot\bcd $iso\efi\microsoft\boot\bcd
    Copy-Item ($env:temp + "\bcdmbr") $usbntfs"\boot\bcd" -Force
    Copy-Item ($env:temp + "\bcdefi") $usbntfs"\EFI\Microsoft\boot\bcd" -Force
    #
    #    House keeping
    remove-item ($env:temp + "\bcdmbr") -force
    remove-item ($env:temp + "\bcdmbr.*") -force
    remove-item ($env:temp + "\bcdefi") -force
    remove-item ($env:temp + "\bcdefi.*") -force
    #
    # 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
    
    Windows 1607 is not supported (cf limitations in post #1)
    Adequated PowerShell level is required
     
  18. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
    I was hoping that if we hid the 1st (fat32) partition before creating the 2nd (ntfs) partition the script might work on Windows 1607 and older versions, but it didn't :p

    Anyways :thumbsup:
     
  19. freddie-o

    freddie-o MDL Addicted

    Jul 29, 2009
    674
    747
    30
    Updated the OP

    v2.1 Boot partition is now hidden so the USB Disk only displays one drive letter