Solved ISO issue!


Alexey2912

Well-known member
Member
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home
Hi,

Downloaded W11 multi edition zip, files would get extracted easily on the system drive, but not on a empty 16 GB USB drive.

Message/ error, one file is too large i.e. approx 4 GB, a (zipped folder) not enough space?... strange.

Single version gets extracted with none issues on a similar drive.

Any ideas.

Thanks.
 

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD

FreeBooter

Well-known member
Power User
VIP
Local time
6:38 PM
Posts
1,004
Location
Adana
OS
Windows 11
Fat32 file system only support 4 GB file size.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1

Alexey2912

Well-known member
Member
Thread Starter
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home
Fat32 file system only support 4 GB file size.
It's a 16 GB USB pen drive. Single edition extracts fine. Should I change the filesystem?

What are my options to use the bootable USB ISO?

Thanks
 

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD

FreeBooter

Well-known member
Power User
VIP
Local time
6:38 PM
Posts
1,004
Location
Adana
OS
Windows 11
Latest versions of Windows 10 ISO contains WIM file that is big for FAT32 file system.

Files larger than 4GB can NOT be stored on a FAT32 partition. This is due to FAT32 limitation.

If you want to boot under UEFI firmware by utilizing NTFS file system you might fail, as not all UEFI systems are able to boot from external boot media using NTFS.

This tutorial will show you how to extract the needed edition from the original install.wim to get a smaller install.wim file.


1 Extract the required install.wim out of the ISO file or mount the ISO file.

2 Open the Command Prompt by typing cmd.exe into Start Menu, right-click on Cmd.exe, and open it as an administrator.

3 Execute the following DISM command with the correct path to the install.wim to get the index that represents needed Windows edition:

Code:
Dism /Get-WimInfo /WimFile:"E:\Sources\install.wim"

The output might look like the following:


4 Execute following command to create a "Mount" folder at root of C: partition.

Code:
Md C:\Mount

5 Extract the right index (6 in this case as I want to install Windows 10 Pro edition) into a new WIM file via DISM command:

Code:
Dism /Export-Image /SourceImageFile:"E:\sources\install.wim" /SourceIndex:6 /DestinationImageFile:"c:\Mount\install.wim



Replace the "E:\sources\install.wim" path with correct path to the install.wim file.

It reduced the install.wim file size to only 3.80 GB which will now fits within the file size limitation of FAT32.

6. Copy newly created install.wim file stored within C:\Mount folder onto an already prepared USB stick with all the other needed files from the original ISO.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1

Alexey2912

Well-known member
Member
Thread Starter
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home
Latest versions of Windows 10 ISO contains WIM file that is big for FAT32 file system.

Files larger than 4GB can NOT be stored on a FAT32 partition. This is due to FAT32 limitation.

If you want to boot under UEFI firmware by utilizing NTFS file system you might fail, as not all UEFI systems are able to boot from external boot media using NTFS.

This tutorial will show you how to extract the needed edition from the original install.wim to get a smaller install.wim file.


1 Extract the required install.wim out of the ISO file or mount the ISO file.

2 Open the Command Prompt by typing cmd.exe into Start Menu, right-click on Cmd.exe, and open it as an administrator.

3 Execute the following DISM command with the correct path to the install.wim to get the index that represents needed Windows edition:

Code:
Dism /Get-WimInfo /WimFile:"E:\Sources\install.wim"

The output might look like the following:


4 Execute following command to create a "Mount" folder at root of C: partition.

Code:
Md C:\Mount

5 Extract the right index (6 in this case as I want to install Windows 10 Pro edition) into a new WIM file via DISM command:

Code:
Dism /Export-Image /SourceImageFile:"E:\sources\install.wim" /SourceIndex:6 /DestinationImageFile:"c:\Mount\install.wim



Replace the "E:\sources\install.wim" path with correct path to the install.wim file.

It reduced the install.wim file size to only 3.80 GB which will now fits within the file size limitation of FAT32.

6. Copy newly created install.wim file stored within C:\Mount folder onto an already prepared USB stick with all the other needed files from the original ISO.

Thanks 🙏. You provided an instant solution.

Best regards!
 

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD

FreeBooter

Well-known member
Power User
VIP
Local time
6:38 PM
Posts
1,004
Location
Adana
OS
Windows 11

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1

Alexey2912

Well-known member
Member
Thread Starter
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD

Alexey2912

Well-known member
Member
Thread Starter
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home
@FreeBooter , one more question how can I download the W11 Home only, for my laptop?
 

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD

FreeBooter

Well-known member
Power User
VIP
Local time
6:38 PM
Posts
1,004
Location
Adana
OS
Windows 11

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1

FreeBooter

Well-known member
Power User
VIP
Local time
6:38 PM
Posts
1,004
Location
Adana
OS
Windows 11

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1

Alexey2912

Well-known member
Member
Thread Starter
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD

SIW2

Well-known member
Member
VIP
Local time
4:38 PM
Posts
422
OS
Win7
Or you can have it on a different usb stick or hd or ssd.
 

My Computer

System One

  • OS
    Win7
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    ga b75m ds3h
    Memory
    2x8gb 3200mhz
    Graphics Card(s)
    no thanks
    Hard Drives
    yes
    PSU
    bequiet pure power 11 400CM
    Case
    some old thing
    Cooling
    cryorig m9i

hsehestedt

Well-known member
Power User
VIP
Local time
10:38 AM
Posts
986
Location
Texas, USA
OS
Windows 11 21H2
For any who may be interested, there is a method to create a bootable flash drive, HDD, or SSD from which Windows can be installed that offers a number of advantages:

1) File size doesn't matter. Your Windows image file could be any size at all and this method will work.

2) Normally, to allow for files of any size, you need to use NTFS rather than FAT32. However, the BIOS on some systems will not allow for boot from a flash drive formatted with NTFS. This method uses a hybrid approach, booting initially from a small FAT32 partition and then transitioning to an NTFS partition. This gives you the best of both worlds - unlimited file sizes and compatibility with systems that don't like booting from NTFS flash drives.

3) This method is also compatible with everything - BIOS or UEFI based systems, x86 (for Windows 10) and x64 based systems, large files on the media, NTFS boot intolerant systems.

Below, you will find two items. The text below tells you step-by-step how to create the media yourself while the batch file does all the work for you, creating the media completely on its own, after prompting for a few simple pieces of information.

Please note the following:

1) If you are not interested in what the batch file does or don't want to perform the procedure manually yourself, then simply ignore the text of the "Procedure" section below.

2) For the batch file, there are some behaviors that you can customize. Look at the start of the batch file which has a section called "Explanation of User Customizable Settings" if this interests you. However, the defaults should be just fine.

3) The batch file has some advanced features. For example, I like to use large flash drives, like 256 GB. When creating Windows boot media there is a LOT of extra space so I create a very large additional partition on which I can carry a bunch of software, docs, etc. The batch file has a "Refresh" feature that allows you to update the bootable Windows image while at the same time leaving any additional partitions alone.

Procedure
======

This is an explanation of what the batch file does and provides instructions to allow you to create your own boot media using this method.

I've seen some rare circumstances, such as when a flash drive was configured for GPT, where the media creation tool did not yield a working flash drive. I like this procedure because I have NEVER seen this not work. You will be able to boot it on any system whether that system is BIOS based or UEFI based. In addition, there is no issue with having files that are greater than 4GB in size. I just keep this procedure handy in case I have any difficulties with any other method of creating the boot disk. It may be easier to use Rufus or the Media Creation Tool, but this is still a good reference to keep on hand.

Here is the procedure:

1) Begin by having your Windows ISO image available. Double-click that file. That should "mount" the ISO image. This means that the ISO image is opened and assigned a drive letter, much like inserting a DVD in a drive. Take note of the drive letter that File Explorer shows for the image.

2) Plug in your flash drive if it is not already plugged in.

3) Press WinLogoKey +R, type in "diskpart" (without the quotes), press <ENTER>.

4) From the DISKPART> prompt, run this command:

list disk

5) From the size of the disks, try to determine which disk your thumb drive is and note the drive number. If that is not enough information, run these commands to get more detail on any disk. In this example, I want more info on disk 4:

select disk 4
detail disk

Here is some sample output:

DISKPART> list disk

Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 476 GB 0 B *
Disk 1 Online 3726 GB 0 B *
Disk 2 Online 465 GB 1024 KB *
Disk 3 Online 7452 GB 0 B *
Disk 4 Online 238 GB 0 B

DISKPART> select disk 4

Disk 4 is now the selected disk.

DISKPART> detail disk

SanDisk Extreme Pro USB Device
Disk ID: DC727760
Type : USB
Status : Online
Path : 0
Target : 0
LUN ID : 0
Location Path : UNAVAILABLE
Current Read-only State : No
Read-only : No
Boot Disk : No
Pagefile Disk : No
Hibernation File Disk : No
Crashdump Disk : No
Clustered Disk : No

Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 7 Z My Software NTFS Removable 238 GB Healthy
C:\MountPoints\My Software\

6) When you determine the correct disk, run the commands below while you are still in diskpart. In this example, I have determined that disk 4 is my flash drive. Be sure to select the correct disk number because everything on that disk will be erased!

clean
convert mbr
create partition primary size=1000
active
format fs=fat32 label=FLASH1 quick
assign
create partition primary
format fs=ntfs label=FLASH2 quick
assign
exit

NOTE: The assign commands will assign the next available drive letter. If you want to assign a specific drives letter, for example E:, use the command "assign letter=E" rather than just "assign" by itself. Please also note that we are assigning the label "FLASH1" to the first partition, and "FLASH2" to the second partition. The only reason we are doing this is to make these partitions easy to identify when you look at them in File Explorer. You can use any label you like. Just be aware that you are limited to 11 characters for FAT32 (the first partition) and 32 characters for NTFS (the second partition).

In the next step, we will copy files from the source to the FAT32 and NTFS partitions on the thumb drive. To be clear, all the files and folders that you are being asked to copy come from your ISO image that you mounted in step 1. You are copying them to either the FAT32 partition (the one labeled "FLASH1") or to the NTFS partition (the one labeled "FLASH2") on your flash drive.

7) Follow these steps to copy files to your thumb drive:

⦁ Copy all files and folders EXCEPT the \sources folder to the FAT32 partition.

⦁ Create a folder called sources on the FAT32 partition.

⦁ Copy the file \sources\boot.wim to the FAT32 partition \sources folder.

⦁ Create a folder called sources on the NTFS partition.

⦁ Copy all files and folders from the \sources folder EXCEPT boot.wim to the \sources folder on the NTFS partition.

At this point, you should have a bootable thumb drive that can be booted from both BIOS and UEFI based systems.

8) To finish, in File Explorer, right click the drive letter for the ISO image that you mounted in step 1 and choose "Eject". This will unmount the image, much like ejecting a DVD from its drive.

NOTE: When booting on some UEFI based systems, you may be presented with an option to boot either the FAT32 or the NTFS partition. Choose the FAT32 partition.

END OF PROCEDURE

Batch File
======

Batch:
@echo off
setlocal enabledelayedexpansion
setlocal enableextensions
cd /d %~dp0

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This batch file will allow you to create a Windows installation disk. This can be a flash drive or a HD.  ::
:: It is designed to create a drive that will boot on either a BIOS or UEFI based system and it is perfectly ::
:: fine for any files in the installation media to be larger than 4 GB.                                      ::
::                                                                                                           ::
:: Note that Windows 11 is only available in 64-bit editions, while Windows 10 is available in both 32-bit   ::
:: and 64-bit editions. Since this batch file is perfectly capable of creating dual architecture media it is ::
:: perfectly suitable for the creation of both Windows 10 and Windows 11 boot media.                         ::
::                                                                                                           ::
:: Originally created December 2020 by HSehestedt and Ztruker                                                ::
:: Last updated May 31, 2022                                                                                 ::
::                                                                                                           ::
:: Version 1.23.05                                                                                           ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Explanation of User Customizable Settings ::                                                                   ::
:::::::::::::::::::::::::::::::::::::::::::::::                                                                   ::
:: Set the variables below to customize the behavior of the batch file.                                           ::
::                                                                                                                ::
:: Important: Values are case sensitive.                                                                          ::
::                                                                                                                ::
:: HideDetails - Set to "Y" to hide the details of every file being copied. Set to "N" or anything other than     ::
::    "Y" to show the detailed copy status. May be helpful for troubleshooting.                                   ::
::                                                                                                                ::
:: Partition1Size - This specifies the size in MB to create the first FAT32 partition. Suggestion: 1000 MB        ::
::    (roughly 1GB) should be a good value for most situations. Use a number only (no MB after the number). If    ::
::    use a customized image with many Windows editions, it's possible that you may need to increase the size of  ::
::    this partition.                                                                                             ::
::                                                                                                                ::
:: Part2SizeLimit - Set to either "N" or a numerical value. If you set this to "N", the size of the 2nd           ::
::    partition will be unlimited and will be created with all the remaining space not used by partition 1. If    ::
::    you would like to limit the size of the partition, specify a size in MB to create this partition.           ::
::    Note: 1 GB would be 1000 and 1 TB would be 1000000 (DON'T USE A COMMA IN VALUE!). Limiting the size is      ::
::    useful if you want to add other partitions to the drive. For example, I have a flash drive that I can       ::
::    install Windows from, but it also has another partition that is BitLocker protected with all my software    ::
::    applications, personal documents, etc.                                                                      ::
::                                                                                                                ::
:: Part2FS - This sets the filesystem type to use on the 2nd partition. Either exFAT or NTFS can be specified.    ::
::    Set this value to either "NTFS" or "exFAT". CAUTION: This IS case sensitive.                                ::
::                                                                                                                ::
:: Partition1Name - This is the volume label to give the first partition. Since this is a FAT32 partition, the    ::
::    volume label is limited to 11 characters.                                                                   ::
::                                                                                                                ::
:: Partition2Name - This is the volume label to give the second partition. If you choose to use exFAT you are     ::
::    limited to 11 characters. With NTFS you have up to 32 characters.                                           ::
::                                                                                                                ::
:: PartType - Set to either MBR or GPT. Normally, leave this set to MBR. An MBR partition type will allow for the ::
::    greatest compatibility with both BIOS and UEFI based systems. However, it is limited to disks with up to    ::
::    2TB in size. If you plan to use a disk larger than 2TB you must specify a GPT partition type. Please be     ::
::    aware that doing this will limit compatibility so that it will not work on BIOS based systems.              ::
::                                                                                                                ::
:: AutoDismount - Set this to Y if you want the source ISO image to be automatically dismounted by this batch     ::
::    file when it is done running. If you do NOT want the image dismounted, set this to N. NOTE: Technically,    ::
::    the image will be dismounted when set to anything other than N.                                             ::
::    IMPORTANT: Set this to Y only if the source is an ISO image. If you are pointing to a folder on a drive,    ::
::    then this should be set to N.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

set HideDetails=N
set Partition1Size=1000
set Part2SizeLimit=N
set Part2FS=NTFS
set Partition1Name=PAR-1-FAT32
set Partition2Name=PAR-2-%Part2FS%
set PartType=MBR
set AutoDismount=N

:start

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If the user wants to hide the details of files being copied, we append a "/nfl /ndl" to the end     ::
:: of robocopy commands. By setting a flag to either nothing or to "/nfl /ndl" we can use the same     ::
:: commands and the variable "flag" at the end of each command will determine how the command behaves. ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if %HideDetails%==Y (
set flag=/nfl /ndl
) ELSE (
set flag=
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Check to see if this batch file is being run as Administrator. If it is not, then rerun the batch file ::
:: automatically as admin and terminate the intial instance of the batch file.                            ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

(Fsutil Dirty Query %SystemDrive%>Nul)||(PowerShell start """%~f0""" -verb RunAs & Exit /B)

::::::::::::::::::::::::::::::::::::::::::::::::
:: End Routine to check if being run as Admin ::
::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: We reach this point once the batch file is run as admin ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Change the console mode to 120 columns wide by 25 lines high ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

mode con: cols=120 lines=25

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Ask user for location of mounted ISO image or the directory containing the Windows files ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
echo Introduction
echo ============
echo.
echo This batch file will create a bootable flash drive from a mounted Windows ISO image or an image extracted to disk.
echo If you are using an ISO image, mount it before you continue by double-clicking the ISO image and note the drive
echo letter to which it is mounted.
echo.
echo You will be asked if you want to wipe the destination disk or perform a refresh operation. If this is the first
echo time preparing the disk, use the WIPE option. Be aware that this will destroy ALL data currently on the disk^^!
echo.
echo If you choose the REFRESH option, you will be asked for the drive letter of the two partitions previously
echo created on the disk. We will then replace the files on these partitions with those from the source that you
echo specify. This is especially helpful if you create additional partitions on the disk because it will leave
echo those partitions intact.
echo.
pause
cls
echo Do you want to perform a WIPE operation or a REFRESH operation?
echo.
choice /C WR /N /M "Press W or R to respond:"
if errorlevel 2 set WipeRefresh=REFRESH & goto GetSourcePath
if errorlevel 1 set WipeRefresh=WIPE & goto GetSourcePath

:GetSourcePath

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Get the path to the Windows source files.                           ::
:: Tip: The path can end with or without a backslash (\). For example, ::
:: either D:, D:\, D:\ISO_Files, D:\ISO_Files\ are all valid paths.    ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
echo Enter the path to the SOURCE where your Windows files are located below. Example: E:\
echo.
:GetSourcePath
set /p SourcePath="Enter source path: "

:: Add a trailing backslash (\) if one does not exist

IF NOT "%SourcePath:~-1%"=="\" (
set SourcePath=%SourcePath%\
)

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Any valid Windows boot media will have a file called "boot\bootfix.bin" on the drive. This is true for both ::
:: single architecture images (x64 or x86) or for images with dual architectures. We will do a simple check to ::
:: see if such a file exists as a basic test for a valid source image location.                                ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if NOT EXIST %SourcePath%boot\bootfix.bin (
cls
echo The location that you specified does not contain a valid Windows image. Please try another location.
echo If you are specifying a location on disk, please be sure to specify the location to the root of the
echo Windows image. If you are using an ISO image, you should double-click the ISO image to mount it and
echo note the drive letter to which it was mounted.
echo.
goto GetSourcePath
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The directory structure for a dual architecture image (one that has BOTH x64 and x86 images) will include    ::
:: \x64 and \x86 folders. In order for us to properly handle this, we need to determine if the source specified ::
:: is a single of dual architecture image. To do so, we will simply check for the existance on a \x64 folder.   ::
:: The variable Architecture will be set to either SINGLE or DUAL.                                              ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if exist %SourcePath%\x64 (
set Architecture=DUAL
) ELSE (
set Architecture=SINGLE
)

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If a refresh operation was selected, then we need to ask the user for the drive letter associated ::
:: with the partitions. Otherwise, we need to identify what disk will be wiped.                      ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

If %WipeRefresh%==WIPE goto GetDiskNum

:GetPar1Letter

cls
echo Please enter the drive letter of the FIRST partition (the FAT32 partition) on the disk that we will refresh. Please
echo enter a drive letter only with no colon (:).
echo.
set /P Partition1="Drive letter of FIRST partition: "

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: As a safety check, verify that the first partition has a file \boot\bootfix.bin ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if exist %Partition1%:\boot\bootfix.bin goto GetPar2Letter
cls
echo ERROR! Either the drive letter you specified does not exist or it does not seem to contain a previously
echo created partition with suitable Windows installation files.
echo.
echo Please verify that you have specified the correct drive letter.
echo.
pause
goto GetPar1Letter

:GetPar2Letter

cls
echo Please enter the drive letter of the SECOND partition (the exFAT or NTFS partition) on the disk that we will
echo refresh. Please enter a drive letter only with no colon (:).
echo.
set /P Partition2="Drive letter of SECOND partition: "

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: As a safety check, verify that the second partition has either a \Sources or a \x64 folder ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if exist %Partition2%:\Sources goto Par2Valid
if exist %Partition2%:\x64 goto Par2Valid

cls
echo ERROR! Either the drive letter you specified does not exist or it does not seem to contain a previously
echo created partition with suitable Windows installation files.
echo.
echo Please verify that you have specified the correct drive letter.
echo.
pause
goto GetPar2Letter

:Par2Valid

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Since we are performing a refresh operation, there is no need for us to get a disk number. We will ::
:: skip that and proceed to the summary screen.                                                       ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

goto Summary

:GetDiskNum

:::::::::::::::::::::::::::::::::::::::::::::::::
:: Display a list of disks seen by the system. ::
:::::::::::::::::::::::::::::::::::::::::::::::::

cls
(echo list disk
echo exit
) | diskpart

echo.
echo Above is a list of disks connected to your system. Scroll up if the list is too long.
echo CAUTION: *MAKE SURE* that you specify the correct disk because it will be erased. Press CTRL-C to abort.
echo.
set /p DiskID="Enter the disk number for the DESTINATION disk (Enter only the number and press ENTER): "

if [%DiskID%] EQU [] Goto GetDiskNum

:Summary

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Display a summary of options that will be used and get confirmation ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
echo Summary of options you have selected:
echo.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: These summary items apply to both WIPE and REFRESH operations ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

echo Path for the source files: %SourcePath%

if %HideDetails%==Y (
echo File copy status details WILL NOT be displayed
) ELSE (
echo File copy status details WILL be displayed
)

if %AutoDismount%==Y (
echo The ISO image will be automatically dismounted when we are done with it
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The summary items below apply only to WIPE operations, so if a ::
:: REFRESH is being performed, skip this section                  ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if %WipeRefresh%==REFRESH goto RefreshSummary

echo Drive number to make bootable: %DiskID%
echo Partition type: %PartType%
echo Partition 1 size: %Partition1Size% MB
echo Partition 2 filesystem type: %Part2FS%

if NOT %Part2SizeLimit%==N (
echo Partition 2 size: %Part2SizeLimit% MB
) ELSE (
echo Partition 2 size: Use all remaining space
)

echo Partition 1 volume label: %Partition1Name%
echo Partition 2 volume label: %Partition2Name%

goto GetConfirmation

:RefreshSummary

::::::::::::::::::::::::::::::::::::::::::::::::::::
:: These items apply only to a REFRESH operation. ::
::::::::::::::::::::::::::::::::::::::::::::::::::::

echo Drive letter of FIRST partition to refresh: %Partition1%:
echo Drive letter of SECOND partition to refresh: %Partition2%:

:GetConfirmation

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Time to get final confirmation from user. If the user does not confirm ::
:: that everything is correct, show some possible resolutions.            ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

echo.
choice /C YN /N /M "Is this correct? (Press Y or N to respond):"
if errorlevel 2 (
cls
echo.
echo        Symptom                                            Corrective Action
echo        =======                                            =================
echo Source path is wrong:                 Run the program again and respond with the correct path
echo Wrong drive number for a WIPE:        Run the program again and respond with the correct drive number
echo Wrong drive letters for a REFRESH:    Run the program again and respond with the correct drive letters
echo File copy status display incorrect:   Change the setting of "HideDetails" at start of program
echo Wrong partition sizes:                Change the setting of "Partition1Size" or "Part2SizeLimit" at start of program
echo Wrong volume labels for a WIPE:       Change the setting of "Partition1Name" or "Partition2Name" at start of program
echo Wrong partition type:                 Change the setting of "PartType" at start of program
echo.
pause
exit
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: We are creating 2 partions. A FAT32 partition and an exFAT or NTFS partition. We only need the sources   ::
:: folder on the exFAT or NTFS partition. On the FAT32 partition, we want everything else. We also want the ::
:: single file called BOOT.WIM in the sources folder on the FAT32 partition.                                ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
if %WipeRefresh%==WIPE echo We are performing the initial partitioning the destination drive to free up any used drive letters.
if %WipeRefresh%==REFRESH echo We are formatting drives %Partition1%: and %Partition2%:    and copying files. Other partitions will be left alone.
echo Please be patient^^! This can take a while if your drive is slow.
echo.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If we are performing a REFRESH, then there are a lot of steps that we can skip. ::
:: As a result, we will skip to the CopyOperations section.                        ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if %WipeRefresh%==REFRESH goto CopyOperations

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: We will first wipe the selected disk. This will free up any drive letters currently used by that disk. ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: NOTE: A problem has been observed recently where the CLEAN command run within DiskPart will fail the first
::       time that it is run. It often succeeds the 2nd time, but not always. However, this problem only
::       happens when the disk is MBR, not GPT. As a result, we first perform a clean and convert to GPT twice
::       and only then do we finally set the disk to the correct type (MBR or GPT) based on user preference.

(echo select disk %DiskID%
echo clean
echo convert gpt
echo clean
echo convert gpt
echo clean
echo convert %PartType%
echo rescan
echo exit
) | diskpart > nul

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Ask user for drive letters to assign to the partitions on the destination drive ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:GetPar1DriveLetter

cls
echo Please enter the drive letter to assign to the FIRST partition (the FAT32 partition). Please enter
echo a drive letter only with no colon (:).
echo.
set /p Partition1="Enter the drive letter to assign to Partition #1: "

if exist %Partition1%: (
echo.
echo That drive letter is already in use. Please choose another.
echo.
pause
goto GetPar1DriveLetter
)

:GetPar2DriveLetter

cls
echo Please enter the drive letter to assign to the SECOND partition (the NTFS partition). Please enter
echo a drive letter only with no colon (:).
echo.
set /p Partition2="Enter the drive letter to assign to Partition #2: "

if exist %Partition2%: (
echo.
echo That drive letter is already in use. Please choose another.
echo.
pause
goto GetPar2DriveLetter
)

:::::::::::::::::::::::::::::::::
:: Prepare the first partition ::
:::::::::::::::::::::::::::::::::

cls
echo The first partition will be assigned drive letter %Partition1%: and will be formatted with FAT32.

(echo select disk %DiskID%
echo create partition primary size=%Partition1Size%
echo format fs=fat32 quick
echo assign letter=%Partition1%
echo active
echo rescan
echo exit
) | diskpart > nul

::::::::::::::::::::::::::::::::::
:: Prepare the second partition ::
::::::::::::::::::::::::::::::::::

echo The second partition will be assigned drive letter %Partition2%: and will be formatted with %Part2FS%.
echo.

if %Part2SizeLimit%==N goto NoSizeLimit

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: User has elected to create the second partition with a specific size ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

(echo select disk %DiskID%
echo create partition primary size=%Part2SizeLimit%
echo format fs=%Part2FS% quick
echo assign letter=%Partition2%
echo rescan
echo exit
) | diskpart > nul

goto PartitionsCreated

:NoSizeLimit

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: User has elected create the second partition with all remaining space ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

(echo select disk %DiskID%
echo create partition primary
echo format fs=%Part2FS% quick
echo assign letter=%Partition2%
echo rescan
echo exit
) | diskpart > NUL

:PartitionsCreated

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Set volume labels on the two partitions that we just created. ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

label %Partition1%:%Partition1Name%
label %Partition2%:%Partition2Name%

:CopyOperations

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This section is for the copy operations from SOURCE to DESTINATION ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Technical Notes:                                                                                                 ::
::                                                                                                                  ::
:: Some flash drives present themselves as a fixed disk and as a result they my have a recyle bin folder on them.   ::
:: We are excluding the system folders which includes the recycle bin from the following operation. The /njh and    ::
:: /njs switches prevent robocopy from displaying the header and summary information. If you want to stop robocopy  ::
:: from displaying file copy progress just add a /nfl /ndl (No File Listing and No Directory Listing) to each       ::
:: robocopy command. Note that if the user elected to hide details of the copy operation, then the variable "flag"  ::
:: will be set to "/nfl /ndl" which will hide the directory and file listings.                                      ::
::                                                                                                                  ::
:: For reasons unknown to me, sometimes a path enclosed in quotes does not work in robocopy unless you add a        ::
:: trailing space. In the below commands I found this to be true only on the first robocopy command but I've added  ::
:: the space to all commands for consistency. We need the quotes just in case a path with spaces in the name is     ::
:: specified.                                                                                                       ::
::                                                                                                                  ::
:: It was previously necessary to create a file named ei.cfg in the \Sources foler. Technically, this file is only  ::
:: needed if you are NOT using an AUTOUNATTEND.XML answer file, but it won't hurt to have it there anyway. However, ::
:: in my testing, it seems that this file is no longer necessary. As a result, the code to create that file is      ::
:: commented out below but I have not removed it just in case it is needed again.                                   ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if %Architecture%==DUAL goto DualArchitecture

:: Copying files to the FAT32 partition

robocopy "%SourcePath% " %Partition1%:\ /mir /xd sources "system volume information" $recycle.bin /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1
robocopy "%SourcePath%sources " %Partition1%:\sources boot.wim /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1

:: Copying files to the exFAT or NTFS partition

robocopy "%SourcePath%sources " %Partition2%:\sources /mir /njh /njs /xf boot.wim %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2
robocopy %Partition1%:\ %Partition2%:\ /mov autounattend*.xml %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Technical note: It was previously necessary to create a file named ei.cfg in the \Sources foler. Technically,  ::
:: this file is only needed if you are NOT using an AUTOUNATTEND.XML answer file, but it won't hurt to have it    ::
:: there anyway. However, in my testing, it seems that this file is no longer necessary. As a result, the code to ::
:: create that file is commented out below but I have not removed it just in case it is needed again.             ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: echo [CHANNEL] > %Partition2%:\sources\ei.cfg
:: echo Retail >> %Partition2%:\sources\ei.cfg

goto DoneCopying

:DualArchitecture

:: Copying files to the FAT32 partition

robocopy "%SourcePath% " %Partition1%:\ /mir /xd sources x64 x86 "system volume information" $recycle.bin /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1
robocopy "%SourcePath%x64\sources " %Partition1%:\x64\sources boot.wim /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1
robocopy "%SourcePath%x86\sources " %Partition1%:\x86\sources boot.wim /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1

:: Copying files to the exFAT or NTFS partition

robocopy "%SourcePath%x64\sources " %Partition2%:\x64\sources /mir /njh /njs /xf boot.wim %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2
robocopy "%SourcePath%x86\sources " %Partition2%:\x86\sources /mir /njh /njs /xf boot.wim %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2
robocopy %Partition1%:\ %Partition2%:\ /mov autounattend*.xml %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Technical note: It was previously necessary to create a file named ei.cfg in the \Sources foler. Technically,  ::
:: this file is only needed if you are NOT using an AUTOUNATTEND.XML answer file, but it won't hurt to have it    ::
:: there anyway. However, in my testing, it seems that this file is no longer necessary. As a result, the code to ::
:: create that file is commented out below but I have not removed it just in case it is needed again.             ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: echo [CHANNEL] > %Partition2%:\x64\sources\ei.cfg
:: echo Retail >> %Partition2%:\x64\sources\ei.cfg

:: echo [CHANNEL] > %Partition2%:\x86\sources\ei.cfg
:: echo Retail >> %Partition2%:\x86\sources\ei.cfg

:DoneCopying

:::::::::::::::::::::::::::::
:: Dismount the disk image ::
:::::::::::::::::::::::::::::

IF %AutoDismount%==N goto DismountDone

:: Strip the backslash from the path
IF "!SourcePath:~-1!"=="\" SET SourcePath=!SourcePath:~,-1!

:: Dismount the image
powershell.exe -command "Dismount-DiskImage -DevicePath \\.\%SourcePath%" > NUL

:DismountDone

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Inform the user that we are done. Also, as a precaution, check to see if an ::
:: unattended setupanswer file is present and warn the user if it is.          ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
echo All operations have been completed.
echo.

if exist %Partition2%:\autounattend.xml (
echo ^^!CAUTION^^! An unattended setup file ^(autounattend.xml^) is present on the 2nd partition.
echo As a result, if you boot from this disk, an unattended installation will begin. This has
echo the potential to wipe out the contents of disks attached to your system without warning.
echo.
echo It might be a wise idea to carefully label the bootable media to reflect this situation.
echo As an alternative, consider temporarily renaming the autounattend.xml to something else.
echo.
)
pause

:END

exit


:::::::::::::::::::::::::::::
:: Error Handling Routines ::
:::::::::::::::::::::::::::::

:ErrorHandler1
cls
echo There was an error copying files to partition #1. Please verify that partition #1 has sufficient space available.
echo Please correct the situation and run the script again. If you are changing the partition sizes, then you will
echo need to use the WIPE operation to create new partitions with the newly specified sizes.
echo.
pause
goto END

:ErrorHandler2
cls
echo There was an error copying files to partition #2. Please verify that partition #2 has sufficient space available.
echo Please correct the situation and run the script again. If you are changing the partition sizes, then you will
echo need to use the WIPE operation to create new partitions with the newly specified sizes.
echo.
pause
goto END
 

My Computers

System One System Two

  • OS
    Windows 11 21H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Built
    CPU
    Intel i7-11700K
    Motherboard
    ASUS Prime Z590-A
    Memory
    128GB Crucial Ballistix 3200MHz DRAM
    Graphics Card(s)
    No GPU - CPU graphics only (for now)
    Sound Card
    Realtek (on motherboard)
    Monitor(s) Displays
    HP Envy 32
    Screen Resolution
    2560 x 1440
    Hard Drives
    1 x 1TB NVMe Gen 4 x 4 SSD
    1 x 2TB NVMe Gen 3 x 4 SSD
    2 x 512GB 2.5" SSDs
    2 x 8TB HD
    PSU
    Corsair HX850i
    Case
    Corsair iCue 5000X RGB
    Cooling
    Noctua NH-D15 chromax.black cooler + 10 case fans
    Keyboard
    CODE backlit mechanical keyboard
    Mouse
    Logitech MX Master 3
    Internet Speed
    300Mb down / 20Mb up
    Browser
    Chromium Edge
    Antivirus
    Windows Defender
    Other Info
    Additional options installed:
    WiFi 6E PCIe adapter
    ASUS ThunderboltEX 4 PCIe adapter
  • Operating System
    Windows 11 21H2
    Computer type
    Laptop
    Manufacturer/Model
    HP Spectre x360 15-BL012DX
    CPU
    Intel i7-7500U
    Memory
    32GB
    Graphics card(s)
    Dual Intel HD 620 and Nvidia GeForce 940MX
    Sound Card
    Built-in Realtek HD Audio
    Monitor(s) Displays
    4k 15-inch
    Screen Resolution
    4k (3840 x 2160)
    Hard Drives
    1TB Seagate FireCuda 510 NVMe SSD
    Internet Speed
    300Mb down / 20Mb up
    Browser
    Chromium Edge
    Antivirus
    Windows Defender
    Other Info
    RAM Upgraded from 16GB to 32GB WiFi Upgraded from WiFi 5 to WiFi 6 SSD upgraded from 512GB NVMe SSD to 1TB Seagate FireCuda 510 NVMe SSD

SIW2

Well-known member
Member
VIP
Local time
4:38 PM
Posts
422
OS
Win7
You could do that. Setup.exe will search all drives for sources folder on the root and if it finds what it needs inside it will proceed.

That could be another partition on the same usb stick. Or a separate usb stick you have plugged in, or any other drive that setup will be able to see when booted .

This is why it is so easy to create a recovery partition for example. Copy the sources folder from installation media onto the root of a partition.

Then when winre.wim is booted, type x:\setup

Adventurous types can put their own install.wim into that sources folder instead of the standard one from the installation media

I have been doing it for many years with win7.
 

My Computer

System One

  • OS
    Win7
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    ga b75m ds3h
    Memory
    2x8gb 3200mhz
    Graphics Card(s)
    no thanks
    Hard Drives
    yes
    PSU
    bequiet pure power 11 400CM
    Case
    some old thing
    Cooling
    cryorig m9i

Alexey2912

Well-known member
Member
Thread Starter
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home
For any who may be interested, there is a method to create a bootable flash drive, HDD, or SSD from which Windows can be installed that offers a number of advantages:

1) File size doesn't matter. Your Windows image file could be any size at all and this method will work.

2) Normally, to allow for files of any size, you need to use NTFS rather than FAT32. However, the BIOS on some systems will not allow for boot from a flash drive formatted with NTFS. This method uses a hybrid approach, booting initially from a small FAT32 partition and then transitioning to an NTFS partition. This gives you the best of both worlds - unlimited file sizes and compatibility with systems that don't like booting from NTFS flash drives.

3) This method is also compatible with everything - BIOS or UEFI based systems, x86 (for Windows 10) and x64 based systems, large files on the media, NTFS boot intolerant systems.

Below, you will find two items. The text below tells you step-by-step how to create the media yourself while the batch file does all the work for you, creating the media completely on its own, after prompting for a few simple pieces of information.

Please note the following:

1) If you are not interested in what the batch file does or don't want to perform the procedure manually yourself, then simply ignore the text of the "Procedure" section below.

2) For the batch file, there are some behaviors that you can customize. Look at the start of the batch file which has a section called "Explanation of User Customizable Settings" if this interests you. However, the defaults should be just fine.

3) The batch file has some advanced features. For example, I like to use large flash drives, like 256 GB. When creating Windows boot media there is a LOT of extra space so I create a very large additional partition on which I can carry a bunch of software, docs, etc. The batch file has a "Refresh" feature that allows you to update the bootable Windows image while at the same time leaving any additional partitions alone.

Procedure
======

This is an explanation of what the batch file does and provides instructions to allow you to create your own boot media using this method.

I've seen some rare circumstances, such as when a flash drive was configured for GPT, where the media creation tool did not yield a working flash drive. I like this procedure because I have NEVER seen this not work. You will be able to boot it on any system whether that system is BIOS based or UEFI based. In addition, there is no issue with having files that are greater than 4GB in size. I just keep this procedure handy in case I have any difficulties with any other method of creating the boot disk. It may be easier to use Rufus or the Media Creation Tool, but this is still a good reference to keep on hand.

Here is the procedure:

1) Begin by having your Windows ISO image available. Double-click that file. That should "mount" the ISO image. This means that the ISO image is opened and assigned a drive letter, much like inserting a DVD in a drive. Take note of the drive letter that File Explorer shows for the image.

2) Plug in your flash drive if it is not already plugged in.

3) Press WinLogoKey +R, type in "diskpart" (without the quotes), press <ENTER>.

4) From the DISKPART> prompt, run this command:

list disk

5) From the size of the disks, try to determine which disk your thumb drive is and note the drive number. If that is not enough information, run these commands to get more detail on any disk. In this example, I want more info on disk 4:

select disk 4
detail disk

Here is some sample output:

DISKPART> list disk

Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 476 GB 0 B *
Disk 1 Online 3726 GB 0 B *
Disk 2 Online 465 GB 1024 KB *
Disk 3 Online 7452 GB 0 B *
Disk 4 Online 238 GB 0 B

DISKPART> select disk 4

Disk 4 is now the selected disk.

DISKPART> detail disk

SanDisk Extreme Pro USB Device
Disk ID: DC727760
Type : USB
Status : Online
Path : 0
Target : 0
LUN ID : 0
Location Path : UNAVAILABLE
Current Read-only State : No
Read-only : No
Boot Disk : No
Pagefile Disk : No
Hibernation File Disk : No
Crashdump Disk : No
Clustered Disk : No

Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 7 Z My Software NTFS Removable 238 GB Healthy
C:\MountPoints\My Software\

6) When you determine the correct disk, run the commands below while you are still in diskpart. In this example, I have determined that disk 4 is my flash drive. Be sure to select the correct disk number because everything on that disk will be erased!

clean
convert mbr
create partition primary size=1000
active
format fs=fat32 label=FLASH1 quick
assign
create partition primary
format fs=ntfs label=FLASH2 quick
assign
exit

NOTE: The assign commands will assign the next available drive letter. If you want to assign a specific drives letter, for example E:, use the command "assign letter=E" rather than just "assign" by itself. Please also note that we are assigning the label "FLASH1" to the first partition, and "FLASH2" to the second partition. The only reason we are doing this is to make these partitions easy to identify when you look at them in File Explorer. You can use any label you like. Just be aware that you are limited to 11 characters for FAT32 (the first partition) and 32 characters for NTFS (the second partition).

In the next step, we will copy files from the source to the FAT32 and NTFS partitions on the thumb drive. To be clear, all the files and folders that you are being asked to copy come from your ISO image that you mounted in step 1. You are copying them to either the FAT32 partition (the one labeled "FLASH1") or to the NTFS partition (the one labeled "FLASH2") on your flash drive.

7) Follow these steps to copy files to your thumb drive:

⦁ Copy all files and folders EXCEPT the \sources folder to the FAT32 partition.

⦁ Create a folder called sources on the FAT32 partition.

⦁ Copy the file \sources\boot.wim to the FAT32 partition \sources folder.

⦁ Create a folder called sources on the NTFS partition.

⦁ Copy all files and folders from the \sources folder EXCEPT boot.wim to the \sources folder on the NTFS partition.

At this point, you should have a bootable thumb drive that can be booted from both BIOS and UEFI based systems.

8) To finish, in File Explorer, right click the drive letter for the ISO image that you mounted in step 1 and choose "Eject". This will unmount the image, much like ejecting a DVD from its drive.

NOTE: When booting on some UEFI based systems, you may be presented with an option to boot either the FAT32 or the NTFS partition. Choose the FAT32 partition.

END OF PROCEDURE

Batch File
======

Batch:
@echo off
setlocal enabledelayedexpansion
setlocal enableextensions
cd /d %~dp0

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This batch file will allow you to create a Windows installation disk. This can be a flash drive or a HD.  ::
:: It is designed to create a drive that will boot on either a BIOS or UEFI based system and it is perfectly ::
:: fine for any files in the installation media to be larger than 4 GB.                                      ::
::                                                                                                           ::
:: Note that Windows 11 is only available in 64-bit editions, while Windows 10 is available in both 32-bit   ::
:: and 64-bit editions. Since this batch file is perfectly capable of creating dual architecture media it is ::
:: perfectly suitable for the creation of both Windows 10 and Windows 11 boot media.                         ::
::                                                                                                           ::
:: Originally created December 2020 by HSehestedt and Ztruker                                                ::
:: Last updated May 31, 2022                                                                                 ::
::                                                                                                           ::
:: Version 1.23.05                                                                                           ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Explanation of User Customizable Settings ::                                                                   ::
:::::::::::::::::::::::::::::::::::::::::::::::                                                                   ::
:: Set the variables below to customize the behavior of the batch file.                                           ::
::                                                                                                                ::
:: Important: Values are case sensitive.                                                                          ::
::                                                                                                                ::
:: HideDetails - Set to "Y" to hide the details of every file being copied. Set to "N" or anything other than     ::
::    "Y" to show the detailed copy status. May be helpful for troubleshooting.                                   ::
::                                                                                                                ::
:: Partition1Size - This specifies the size in MB to create the first FAT32 partition. Suggestion: 1000 MB        ::
::    (roughly 1GB) should be a good value for most situations. Use a number only (no MB after the number). If    ::
::    use a customized image with many Windows editions, it's possible that you may need to increase the size of  ::
::    this partition.                                                                                             ::
::                                                                                                                ::
:: Part2SizeLimit - Set to either "N" or a numerical value. If you set this to "N", the size of the 2nd           ::
::    partition will be unlimited and will be created with all the remaining space not used by partition 1. If    ::
::    you would like to limit the size of the partition, specify a size in MB to create this partition.           ::
::    Note: 1 GB would be 1000 and 1 TB would be 1000000 (DON'T USE A COMMA IN VALUE!). Limiting the size is      ::
::    useful if you want to add other partitions to the drive. For example, I have a flash drive that I can       ::
::    install Windows from, but it also has another partition that is BitLocker protected with all my software    ::
::    applications, personal documents, etc.                                                                      ::
::                                                                                                                ::
:: Part2FS - This sets the filesystem type to use on the 2nd partition. Either exFAT or NTFS can be specified.    ::
::    Set this value to either "NTFS" or "exFAT". CAUTION: This IS case sensitive.                                ::
::                                                                                                                ::
:: Partition1Name - This is the volume label to give the first partition. Since this is a FAT32 partition, the    ::
::    volume label is limited to 11 characters.                                                                   ::
::                                                                                                                ::
:: Partition2Name - This is the volume label to give the second partition. If you choose to use exFAT you are     ::
::    limited to 11 characters. With NTFS you have up to 32 characters.                                           ::
::                                                                                                                ::
:: PartType - Set to either MBR or GPT. Normally, leave this set to MBR. An MBR partition type will allow for the ::
::    greatest compatibility with both BIOS and UEFI based systems. However, it is limited to disks with up to    ::
::    2TB in size. If you plan to use a disk larger than 2TB you must specify a GPT partition type. Please be     ::
::    aware that doing this will limit compatibility so that it will not work on BIOS based systems.              ::
::                                                                                                                ::
:: AutoDismount - Set this to Y if you want the source ISO image to be automatically dismounted by this batch     ::
::    file when it is done running. If you do NOT want the image dismounted, set this to N. NOTE: Technically,    ::
::    the image will be dismounted when set to anything other than N.                                             ::
::    IMPORTANT: Set this to Y only if the source is an ISO image. If you are pointing to a folder on a drive,    ::
::    then this should be set to N.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

set HideDetails=N
set Partition1Size=1000
set Part2SizeLimit=N
set Part2FS=NTFS
set Partition1Name=PAR-1-FAT32
set Partition2Name=PAR-2-%Part2FS%
set PartType=MBR
set AutoDismount=N

:start

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If the user wants to hide the details of files being copied, we append a "/nfl /ndl" to the end     ::
:: of robocopy commands. By setting a flag to either nothing or to "/nfl /ndl" we can use the same     ::
:: commands and the variable "flag" at the end of each command will determine how the command behaves. ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if %HideDetails%==Y (
set flag=/nfl /ndl
) ELSE (
set flag=
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Check to see if this batch file is being run as Administrator. If it is not, then rerun the batch file ::
:: automatically as admin and terminate the intial instance of the batch file.                            ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

(Fsutil Dirty Query %SystemDrive%>Nul)||(PowerShell start """%~f0""" -verb RunAs & Exit /B)

::::::::::::::::::::::::::::::::::::::::::::::::
:: End Routine to check if being run as Admin ::
::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: We reach this point once the batch file is run as admin ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Change the console mode to 120 columns wide by 25 lines high ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

mode con: cols=120 lines=25

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Ask user for location of mounted ISO image or the directory containing the Windows files ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
echo Introduction
echo ============
echo.
echo This batch file will create a bootable flash drive from a mounted Windows ISO image or an image extracted to disk.
echo If you are using an ISO image, mount it before you continue by double-clicking the ISO image and note the drive
echo letter to which it is mounted.
echo.
echo You will be asked if you want to wipe the destination disk or perform a refresh operation. If this is the first
echo time preparing the disk, use the WIPE option. Be aware that this will destroy ALL data currently on the disk^^!
echo.
echo If you choose the REFRESH option, you will be asked for the drive letter of the two partitions previously
echo created on the disk. We will then replace the files on these partitions with those from the source that you
echo specify. This is especially helpful if you create additional partitions on the disk because it will leave
echo those partitions intact.
echo.
pause
cls
echo Do you want to perform a WIPE operation or a REFRESH operation?
echo.
choice /C WR /N /M "Press W or R to respond:"
if errorlevel 2 set WipeRefresh=REFRESH & goto GetSourcePath
if errorlevel 1 set WipeRefresh=WIPE & goto GetSourcePath

:GetSourcePath

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Get the path to the Windows source files.                           ::
:: Tip: The path can end with or without a backslash (\). For example, ::
:: either D:, D:\, D:\ISO_Files, D:\ISO_Files\ are all valid paths.    ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
echo Enter the path to the SOURCE where your Windows files are located below. Example: E:\
echo.
:GetSourcePath
set /p SourcePath="Enter source path: "

:: Add a trailing backslash (\) if one does not exist

IF NOT "%SourcePath:~-1%"=="\" (
set SourcePath=%SourcePath%\
)

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Any valid Windows boot media will have a file called "boot\bootfix.bin" on the drive. This is true for both ::
:: single architecture images (x64 or x86) or for images with dual architectures. We will do a simple check to ::
:: see if such a file exists as a basic test for a valid source image location.                                ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if NOT EXIST %SourcePath%boot\bootfix.bin (
cls
echo The location that you specified does not contain a valid Windows image. Please try another location.
echo If you are specifying a location on disk, please be sure to specify the location to the root of the
echo Windows image. If you are using an ISO image, you should double-click the ISO image to mount it and
echo note the drive letter to which it was mounted.
echo.
goto GetSourcePath
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The directory structure for a dual architecture image (one that has BOTH x64 and x86 images) will include    ::
:: \x64 and \x86 folders. In order for us to properly handle this, we need to determine if the source specified ::
:: is a single of dual architecture image. To do so, we will simply check for the existance on a \x64 folder.   ::
:: The variable Architecture will be set to either SINGLE or DUAL.                                              ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if exist %SourcePath%\x64 (
set Architecture=DUAL
) ELSE (
set Architecture=SINGLE
)

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If a refresh operation was selected, then we need to ask the user for the drive letter associated ::
:: with the partitions. Otherwise, we need to identify what disk will be wiped.                      ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

If %WipeRefresh%==WIPE goto GetDiskNum

:GetPar1Letter

cls
echo Please enter the drive letter of the FIRST partition (the FAT32 partition) on the disk that we will refresh. Please
echo enter a drive letter only with no colon (:).
echo.
set /P Partition1="Drive letter of FIRST partition: "

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: As a safety check, verify that the first partition has a file \boot\bootfix.bin ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if exist %Partition1%:\boot\bootfix.bin goto GetPar2Letter
cls
echo ERROR! Either the drive letter you specified does not exist or it does not seem to contain a previously
echo created partition with suitable Windows installation files.
echo.
echo Please verify that you have specified the correct drive letter.
echo.
pause
goto GetPar1Letter

:GetPar2Letter

cls
echo Please enter the drive letter of the SECOND partition (the exFAT or NTFS partition) on the disk that we will
echo refresh. Please enter a drive letter only with no colon (:).
echo.
set /P Partition2="Drive letter of SECOND partition: "

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: As a safety check, verify that the second partition has either a \Sources or a \x64 folder ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if exist %Partition2%:\Sources goto Par2Valid
if exist %Partition2%:\x64 goto Par2Valid

cls
echo ERROR! Either the drive letter you specified does not exist or it does not seem to contain a previously
echo created partition with suitable Windows installation files.
echo.
echo Please verify that you have specified the correct drive letter.
echo.
pause
goto GetPar2Letter

:Par2Valid

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Since we are performing a refresh operation, there is no need for us to get a disk number. We will ::
:: skip that and proceed to the summary screen.                                                       ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

goto Summary

:GetDiskNum

:::::::::::::::::::::::::::::::::::::::::::::::::
:: Display a list of disks seen by the system. ::
:::::::::::::::::::::::::::::::::::::::::::::::::

cls
(echo list disk
echo exit
) | diskpart

echo.
echo Above is a list of disks connected to your system. Scroll up if the list is too long.
echo CAUTION: *MAKE SURE* that you specify the correct disk because it will be erased. Press CTRL-C to abort.
echo.
set /p DiskID="Enter the disk number for the DESTINATION disk (Enter only the number and press ENTER): "

if [%DiskID%] EQU [] Goto GetDiskNum

:Summary

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Display a summary of options that will be used and get confirmation ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
echo Summary of options you have selected:
echo.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: These summary items apply to both WIPE and REFRESH operations ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

echo Path for the source files: %SourcePath%

if %HideDetails%==Y (
echo File copy status details WILL NOT be displayed
) ELSE (
echo File copy status details WILL be displayed
)

if %AutoDismount%==Y (
echo The ISO image will be automatically dismounted when we are done with it
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The summary items below apply only to WIPE operations, so if a ::
:: REFRESH is being performed, skip this section                  ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if %WipeRefresh%==REFRESH goto RefreshSummary

echo Drive number to make bootable: %DiskID%
echo Partition type: %PartType%
echo Partition 1 size: %Partition1Size% MB
echo Partition 2 filesystem type: %Part2FS%

if NOT %Part2SizeLimit%==N (
echo Partition 2 size: %Part2SizeLimit% MB
) ELSE (
echo Partition 2 size: Use all remaining space
)

echo Partition 1 volume label: %Partition1Name%
echo Partition 2 volume label: %Partition2Name%

goto GetConfirmation

:RefreshSummary

::::::::::::::::::::::::::::::::::::::::::::::::::::
:: These items apply only to a REFRESH operation. ::
::::::::::::::::::::::::::::::::::::::::::::::::::::

echo Drive letter of FIRST partition to refresh: %Partition1%:
echo Drive letter of SECOND partition to refresh: %Partition2%:

:GetConfirmation

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Time to get final confirmation from user. If the user does not confirm ::
:: that everything is correct, show some possible resolutions.            ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

echo.
choice /C YN /N /M "Is this correct? (Press Y or N to respond):"
if errorlevel 2 (
cls
echo.
echo        Symptom                                            Corrective Action
echo        =======                                            =================
echo Source path is wrong:                 Run the program again and respond with the correct path
echo Wrong drive number for a WIPE:        Run the program again and respond with the correct drive number
echo Wrong drive letters for a REFRESH:    Run the program again and respond with the correct drive letters
echo File copy status display incorrect:   Change the setting of "HideDetails" at start of program
echo Wrong partition sizes:                Change the setting of "Partition1Size" or "Part2SizeLimit" at start of program
echo Wrong volume labels for a WIPE:       Change the setting of "Partition1Name" or "Partition2Name" at start of program
echo Wrong partition type:                 Change the setting of "PartType" at start of program
echo.
pause
exit
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: We are creating 2 partions. A FAT32 partition and an exFAT or NTFS partition. We only need the sources   ::
:: folder on the exFAT or NTFS partition. On the FAT32 partition, we want everything else. We also want the ::
:: single file called BOOT.WIM in the sources folder on the FAT32 partition.                                ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
if %WipeRefresh%==WIPE echo We are performing the initial partitioning the destination drive to free up any used drive letters.
if %WipeRefresh%==REFRESH echo We are formatting drives %Partition1%: and %Partition2%:    and copying files. Other partitions will be left alone.
echo Please be patient^^! This can take a while if your drive is slow.
echo.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If we are performing a REFRESH, then there are a lot of steps that we can skip. ::
:: As a result, we will skip to the CopyOperations section.                        ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if %WipeRefresh%==REFRESH goto CopyOperations

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: We will first wipe the selected disk. This will free up any drive letters currently used by that disk. ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: NOTE: A problem has been observed recently where the CLEAN command run within DiskPart will fail the first
::       time that it is run. It often succeeds the 2nd time, but not always. However, this problem only
::       happens when the disk is MBR, not GPT. As a result, we first perform a clean and convert to GPT twice
::       and only then do we finally set the disk to the correct type (MBR or GPT) based on user preference.

(echo select disk %DiskID%
echo clean
echo convert gpt
echo clean
echo convert gpt
echo clean
echo convert %PartType%
echo rescan
echo exit
) | diskpart > nul

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Ask user for drive letters to assign to the partitions on the destination drive ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:GetPar1DriveLetter

cls
echo Please enter the drive letter to assign to the FIRST partition (the FAT32 partition). Please enter
echo a drive letter only with no colon (:).
echo.
set /p Partition1="Enter the drive letter to assign to Partition #1: "

if exist %Partition1%: (
echo.
echo That drive letter is already in use. Please choose another.
echo.
pause
goto GetPar1DriveLetter
)

:GetPar2DriveLetter

cls
echo Please enter the drive letter to assign to the SECOND partition (the NTFS partition). Please enter
echo a drive letter only with no colon (:).
echo.
set /p Partition2="Enter the drive letter to assign to Partition #2: "

if exist %Partition2%: (
echo.
echo That drive letter is already in use. Please choose another.
echo.
pause
goto GetPar2DriveLetter
)

:::::::::::::::::::::::::::::::::
:: Prepare the first partition ::
:::::::::::::::::::::::::::::::::

cls
echo The first partition will be assigned drive letter %Partition1%: and will be formatted with FAT32.

(echo select disk %DiskID%
echo create partition primary size=%Partition1Size%
echo format fs=fat32 quick
echo assign letter=%Partition1%
echo active
echo rescan
echo exit
) | diskpart > nul

::::::::::::::::::::::::::::::::::
:: Prepare the second partition ::
::::::::::::::::::::::::::::::::::

echo The second partition will be assigned drive letter %Partition2%: and will be formatted with %Part2FS%.
echo.

if %Part2SizeLimit%==N goto NoSizeLimit

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: User has elected to create the second partition with a specific size ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

(echo select disk %DiskID%
echo create partition primary size=%Part2SizeLimit%
echo format fs=%Part2FS% quick
echo assign letter=%Partition2%
echo rescan
echo exit
) | diskpart > nul

goto PartitionsCreated

:NoSizeLimit

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: User has elected create the second partition with all remaining space ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

(echo select disk %DiskID%
echo create partition primary
echo format fs=%Part2FS% quick
echo assign letter=%Partition2%
echo rescan
echo exit
) | diskpart > NUL

:PartitionsCreated

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Set volume labels on the two partitions that we just created. ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

label %Partition1%:%Partition1Name%
label %Partition2%:%Partition2Name%

:CopyOperations

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This section is for the copy operations from SOURCE to DESTINATION ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Technical Notes:                                                                                                 ::
::                                                                                                                  ::
:: Some flash drives present themselves as a fixed disk and as a result they my have a recyle bin folder on them.   ::
:: We are excluding the system folders which includes the recycle bin from the following operation. The /njh and    ::
:: /njs switches prevent robocopy from displaying the header and summary information. If you want to stop robocopy  ::
:: from displaying file copy progress just add a /nfl /ndl (No File Listing and No Directory Listing) to each       ::
:: robocopy command. Note that if the user elected to hide details of the copy operation, then the variable "flag"  ::
:: will be set to "/nfl /ndl" which will hide the directory and file listings.                                      ::
::                                                                                                                  ::
:: For reasons unknown to me, sometimes a path enclosed in quotes does not work in robocopy unless you add a        ::
:: trailing space. In the below commands I found this to be true only on the first robocopy command but I've added  ::
:: the space to all commands for consistency. We need the quotes just in case a path with spaces in the name is     ::
:: specified.                                                                                                       ::
::                                                                                                                  ::
:: It was previously necessary to create a file named ei.cfg in the \Sources foler. Technically, this file is only  ::
:: needed if you are NOT using an AUTOUNATTEND.XML answer file, but it won't hurt to have it there anyway. However, ::
:: in my testing, it seems that this file is no longer necessary. As a result, the code to create that file is      ::
:: commented out below but I have not removed it just in case it is needed again.                                   ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if %Architecture%==DUAL goto DualArchitecture

:: Copying files to the FAT32 partition

robocopy "%SourcePath% " %Partition1%:\ /mir /xd sources "system volume information" $recycle.bin /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1
robocopy "%SourcePath%sources " %Partition1%:\sources boot.wim /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1

:: Copying files to the exFAT or NTFS partition

robocopy "%SourcePath%sources " %Partition2%:\sources /mir /njh /njs /xf boot.wim %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2
robocopy %Partition1%:\ %Partition2%:\ /mov autounattend*.xml %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Technical note: It was previously necessary to create a file named ei.cfg in the \Sources foler. Technically,  ::
:: this file is only needed if you are NOT using an AUTOUNATTEND.XML answer file, but it won't hurt to have it    ::
:: there anyway. However, in my testing, it seems that this file is no longer necessary. As a result, the code to ::
:: create that file is commented out below but I have not removed it just in case it is needed again.             ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: echo [CHANNEL] > %Partition2%:\sources\ei.cfg
:: echo Retail >> %Partition2%:\sources\ei.cfg

goto DoneCopying

:DualArchitecture

:: Copying files to the FAT32 partition

robocopy "%SourcePath% " %Partition1%:\ /mir /xd sources x64 x86 "system volume information" $recycle.bin /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1
robocopy "%SourcePath%x64\sources " %Partition1%:\x64\sources boot.wim /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1
robocopy "%SourcePath%x86\sources " %Partition1%:\x86\sources boot.wim /njh /njs %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler1

:: Copying files to the exFAT or NTFS partition

robocopy "%SourcePath%x64\sources " %Partition2%:\x64\sources /mir /njh /njs /xf boot.wim %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2
robocopy "%SourcePath%x86\sources " %Partition2%:\x86\sources /mir /njh /njs /xf boot.wim %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2
robocopy %Partition1%:\ %Partition2%:\ /mov autounattend*.xml %flag%
if %ERRORLEVEL% gtr 3 goto ErrorHandler2

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Technical note: It was previously necessary to create a file named ei.cfg in the \Sources foler. Technically,  ::
:: this file is only needed if you are NOT using an AUTOUNATTEND.XML answer file, but it won't hurt to have it    ::
:: there anyway. However, in my testing, it seems that this file is no longer necessary. As a result, the code to ::
:: create that file is commented out below but I have not removed it just in case it is needed again.             ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: echo [CHANNEL] > %Partition2%:\x64\sources\ei.cfg
:: echo Retail >> %Partition2%:\x64\sources\ei.cfg

:: echo [CHANNEL] > %Partition2%:\x86\sources\ei.cfg
:: echo Retail >> %Partition2%:\x86\sources\ei.cfg

:DoneCopying

:::::::::::::::::::::::::::::
:: Dismount the disk image ::
:::::::::::::::::::::::::::::

IF %AutoDismount%==N goto DismountDone

:: Strip the backslash from the path
IF "!SourcePath:~-1!"=="\" SET SourcePath=!SourcePath:~,-1!

:: Dismount the image
powershell.exe -command "Dismount-DiskImage -DevicePath \\.\%SourcePath%" > NUL

:DismountDone

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Inform the user that we are done. Also, as a precaution, check to see if an ::
:: unattended setupanswer file is present and warn the user if it is.          ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cls
echo All operations have been completed.
echo.

if exist %Partition2%:\autounattend.xml (
echo ^^!CAUTION^^! An unattended setup file ^(autounattend.xml^) is present on the 2nd partition.
echo As a result, if you boot from this disk, an unattended installation will begin. This has
echo the potential to wipe out the contents of disks attached to your system without warning.
echo.
echo It might be a wise idea to carefully label the bootable media to reflect this situation.
echo As an alternative, consider temporarily renaming the autounattend.xml to something else.
echo.
)
pause

:END

exit


:::::::::::::::::::::::::::::
:: Error Handling Routines ::
:::::::::::::::::::::::::::::

:ErrorHandler1
cls
echo There was an error copying files to partition #1. Please verify that partition #1 has sufficient space available.
echo Please correct the situation and run the script again. If you are changing the partition sizes, then you will
echo need to use the WIPE operation to create new partitions with the newly specified sizes.
echo.
pause
goto END

:ErrorHandler2
cls
echo There was an error copying files to partition #2. Please verify that partition #2 has sufficient space available.
echo Please correct the situation and run the script again. If you are changing the partition sizes, then you will
echo need to use the WIPE operation to create new partitions with the newly specified sizes.
echo.
pause
goto END
Thanks @hsehestedt , for the expert detailed explanation and taking the time to explain explicitly.
Appreciate it.
 

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD

hsehestedt

Well-known member
Power User
VIP
Local time
10:38 AM
Posts
986
Location
Texas, USA
OS
Windows 11 21H2

My Computers

System One System Two

  • OS
    Windows 11 21H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Built
    CPU
    Intel i7-11700K
    Motherboard
    ASUS Prime Z590-A
    Memory
    128GB Crucial Ballistix 3200MHz DRAM
    Graphics Card(s)
    No GPU - CPU graphics only (for now)
    Sound Card
    Realtek (on motherboard)
    Monitor(s) Displays
    HP Envy 32
    Screen Resolution
    2560 x 1440
    Hard Drives
    1 x 1TB NVMe Gen 4 x 4 SSD
    1 x 2TB NVMe Gen 3 x 4 SSD
    2 x 512GB 2.5" SSDs
    2 x 8TB HD
    PSU
    Corsair HX850i
    Case
    Corsair iCue 5000X RGB
    Cooling
    Noctua NH-D15 chromax.black cooler + 10 case fans
    Keyboard
    CODE backlit mechanical keyboard
    Mouse
    Logitech MX Master 3
    Internet Speed
    300Mb down / 20Mb up
    Browser
    Chromium Edge
    Antivirus
    Windows Defender
    Other Info
    Additional options installed:
    WiFi 6E PCIe adapter
    ASUS ThunderboltEX 4 PCIe adapter
  • Operating System
    Windows 11 21H2
    Computer type
    Laptop
    Manufacturer/Model
    HP Spectre x360 15-BL012DX
    CPU
    Intel i7-7500U
    Memory
    32GB
    Graphics card(s)
    Dual Intel HD 620 and Nvidia GeForce 940MX
    Sound Card
    Built-in Realtek HD Audio
    Monitor(s) Displays
    4k 15-inch
    Screen Resolution
    4k (3840 x 2160)
    Hard Drives
    1TB Seagate FireCuda 510 NVMe SSD
    Internet Speed
    300Mb down / 20Mb up
    Browser
    Chromium Edge
    Antivirus
    Windows Defender
    Other Info
    RAM Upgraded from 16GB to 32GB WiFi Upgraded from WiFi 5 to WiFi 6 SSD upgraded from 512GB NVMe SSD to 1TB Seagate FireCuda 510 NVMe SSD

Alexey2912

Well-known member
Member
Thread Starter
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home
Thanks for taking the time to comment. Very kind of you.

Highly appreciate your modesty and humbleness! :-)

Added:

Your system specs are mind blowing and your expertise simply brilliant!
 

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD

Ed Tittel

Well-known member
MVP
Member
VIP
Local time
10:38 AM
Posts
217
OS
Windows 11

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo X380 Yoga
    CPU
    i7-8650U (8th Gen/Kaby Lake)
    Motherboard
    20LH000MUS (U3E1)
    Memory
    16 GB
    Graphics Card(s)
    Intel UHD Graphics 620
    Sound Card
    Integrated Conexant SmartAudio HD
    Monitor(s) Displays
    FlexView Display
    Screen Resolution
    1920x1080
    Hard Drives
    Toshiba 1 TB PCIe x3 NVMe SSD
    external 5TB Seagate USB-C attached HDD
    PSU
    Lenovo integrated 65W power brick
    Case
    Laptop
    Cooling
    Laptop
    Keyboard
    Integrated Lenovo ThinkPad keyboard
    Mouse
    touchscreen, touchpad
    Internet Speed
    GbE (Spectrum/Charter)
    Browser
    all of em
    Antivirus
    Defender
    Other Info
    Purchased early 2019 as Windows Insider test PC

imanlien2020

EternalSoul
Member
Local time
10:38 AM
Posts
243
Location
USA
OS
Windows 11 Pro Version 21H2(OS Build 22000.795)
Another great clean download site is TechBench Site
And as far as creating a bootable iso using NTFS and UEFI
I use Rufus. Download Iso file to your desktop Plug in your USB Pen,
Have rufus downloaded into your desktop, open Rufus and all you have to do
is click browse to the iso file and click start and it will do ALL the legwork for you in a minute or two
youll have a bootable USB. And Rufus is Free. This post is merely my opinion. Good Luck
 

My Computer

System One

  • OS
    Windows 11 Pro Version 21H2(OS Build 22000.795)
    Computer type
    PC/Desktop
    Manufacturer/Model
    AMD
    CPU
    AMD Ryzen 7 5800X 8 Core
    Motherboard
    Gigabyte X570 Aorus Pro WiFi
    Memory
    32 GB
    Graphics Card(s)
    PCI Express 3.0 x16: PowerColor RX Vega 56 Red Dragon
    Sound Card
    Realtek ALC1220 and AMD Greenland - High Definition Audio Controller
    Monitor(s) Displays
    2 - 27 inch Westinghouse
    Screen Resolution
    1920 x 1080
    Hard Drives
    2 SSD - 2 TB each
    1 HDD - 2 TB
    Keyboard
    logitech
    Mouse
    logitech
    Internet Speed
    1 GB
    Browser
    Microsoft Edge
    Antivirus
    Avast Premium

Alexey2912

Well-known member
Member
Thread Starter
Local time
5:38 AM
Posts
1,420
Location
Aiea, Honolulu HI
OS
Windows 11 Home

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Dell Inspirion 5510
    CPU
    core 17 11th gen
    Memory
    16 GB DDR4 @3200 MHz
    Hard Drives
    1 TB SSD M.2 NVMe
    Keyboard
    Dell Premier Multi-Device Wireless Keyboard and Mouse – KM7321W
    Browser
    Brave.
    Other Info
    Edifier speakers. (Thanks to @Edwin).
  • Operating System
    W11
    Computer type
    PC/Desktop
    Manufacturer/Model
    XPS Special Edition
    CPU
    11th Gen Intel® Core i7-11700 processor
    Memory
    32 GB, 2 x 16 GB, DDR4, 2933 MHz, dual channel
    Graphics card(s)
    NVIDIA GeForce RTX 3060 12GB GDDR6
    Hard Drives
    2TB M.2 PCIe NVMe SSD
Top Bottom