Creating a Bootable USB for Windows 10 and 11 on Linux

Creating a bootable USB drive is often necessary when you want to install or repair an operating system. This guide provides detailed steps on how to create a bootable USB drive for Windows 10 or 11 using Linux (both Debian and RPM-based distributions).

Our handy script does all the heavy lifting, making this task a breeze. The script operates by formatting the USB drive, and then copying the ISO file to the USB drive.

In this tutorial you will learn:

  • Creating a Bootable USB for Windows 10
  • Creating a Bootable USB for Windows 11
Creating a Bootable USB for Windows 10 and 11 on Linux
Creating a Bootable USB for Windows 10 and 11 on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Preparations

  1. Download the Windows ISO file: You can download Windows 10 and 11 ISO files directly from Microsoft’s official website. Make sure to save the ISO file in a location you’ll remember as we’ll need the path for the script.
  2. Identify your USB drive: Plug in your USB drive and use the command lsblk to list all block devices. Identify your USB drive’s name (such as /dev/sdc, /dev/sdd, etc).

Please note: All data on this drive will be erased in the process, so make sure to back up any important data before you proceed!

Running the Script

With the ISO file downloaded and your USB drive identified, you can now proceed to use our script.

  1. Download the script: Download our script and save it in a convenient location. Let’s assume it’s saved as create_win_usb.sh.
  2. Make the script executable: Before we can run the script, we need to make it executable. Open a terminal and navigate to where you saved the script. Run the command chmod +x create_win_usb.sh to make it executable.
  3. Run the script: Now you’re ready to run the script! Run it with the command ./create_win_usb.sh /path/to/your/iso /dev/sdX, replacing /path/to/your/iso with the actual path to your ISO file, and /dev/sdX with your actual USB block device. For example:
    ./create_win_usb.sh ~/Downloads/Win11_English_x64.iso /dev/sdc

Creating a Bootable USB for Windows 10 and 11 on Linux script:

#!/bin/bash
# --------------------------------------------------------------
# Create Bootable Windows 10/11 USB in Linux (Debian/RPM-based)
# Version: 1.0
# Author: LinuxConfig.org
# Date: 23-06-2023
# License: GPL-3.0
# --------------------------------------------------------------
# Input parameters: Path to the ISO file and USB block device location
ISO_PATH=$1
USB_BLOCK=$2

echo "ISO Path is: $ISO_PATH"
echo "USB block device is: $USB_BLOCK"

# Check for required commands
REQUIRED_COMMANDS=("rsync" "parted" "wipefs" "mkfs.vfat" "mkfs.ntfs" "udisksctl" "sha256sum" "mount" "umount" "mkdir" "cp" "sync" "mktemp")

echo "Checking for required commands..."
for cmd in "${REQUIRED_COMMANDS[@]}"; do
    if ! command -v $cmd >/dev/null 2>&1; then
        echo "Missing command $cmd. Please install the corresponding package and rerun this script."
        exit 1
    fi
done
echo "All required commands are available."

# 1. Checking ISO file
read -p "Do you want to calculate the ISO file checksum? This could take some time. Press 'y' to continue or any other key to skip: " response
if [[ $response =~ ^[Yy]$ ]]
then
    echo "Calculating ISO file checksum..."
    ISO_CHECKSUM=$(sha256sum $ISO_PATH)
    echo "Checksum is: $ISO_CHECKSUM"
    read -p "Please verify the checksum. Press 'y' to continue: " response

    if [[ ! $response =~ ^[Yy]$ ]]
    then
        echo "Aborting due to user response."
        exit 1
    fi
fi

# Warning about formatting and data loss
echo "WARNING: All data on $USB_BLOCK will be lost!"
read -p "Are you sure you want to continue? [y/N]: " confirm
confirm=${confirm:-N}
if [[ $confirm =~ ^[Yy]$ ]]
then
    # 2. Formatting the USB drive
    echo "Formatting USB drive..."
    wipefs -a $USB_BLOCK

    parted $USB_BLOCK mklabel gpt
    parted $USB_BLOCK mkpart BOOT fat32 0% 1GiB
    parted $USB_BLOCK mkpart INSTALL ntfs 1GiB 100%
    parted $USB_BLOCK unit B print

    # Create temporary directories for mounting
    ISO_MOUNT=$(mktemp -d)
    VFAT_MOUNT=$(mktemp -d)
    NTFS_MOUNT=$(mktemp -d)

    # 3. Mounting the ISO
    echo "Mounting ISO..."
    mount $ISO_PATH $ISO_MOUNT

    # 4. Formatting and copying to the USB
    echo "Copying to USB..."
    mkfs.vfat -n BOOT ${USB_BLOCK}1
    mount ${USB_BLOCK}1 $VFAT_MOUNT

    rsync -r --progress --exclude sources --delete-before $ISO_MOUNT/ $VFAT_MOUNT/

    mkdir -p $VFAT_MOUNT/sources
    cp $ISO_MOUNT/sources/boot.wim $VFAT_MOUNT/sources/

    mkfs.ntfs --quick -L INSTALL ${USB_BLOCK}2
    mount ${USB_BLOCK}2 $NTFS_MOUNT

    rsync -r --progress --delete-before $ISO_MOUNT/ $NTFS_MOUNT/

    # 5. Unmounting and power off
    echo "Unmounting drives and syncing data... This may take a while, do not disconnect your USB drive."
    umount $NTFS_MOUNT
    umount $VFAT_MOUNT
    umount $ISO_MOUNT
    sync

    # Remove temporary mount directories
    rmdir $ISO_MOUNT $VFAT_MOUNT $NTFS_MOUNT

    udisksctl power-off -b $USB_BLOCK

    echo "Done! You can now safely disconnect your USB drive."
else
    echo "Aborted by user."
    exit 1
fi

During the script execution, it will ask for your permission at different steps. For instance, it will provide you an option to check the checksum of the ISO file (which could be time-consuming depending on your system). Moreover, before formatting the USB drive, it will warn you about data loss. Be sure to respond to these prompts according to your preferences.

Finally, please be patient after the copy operation while the script unmounts the drives and syncs the data. It’s crucial to wait for the “Done” message before disconnecting the USB drive to prevent data corruption.

That’s it! With these steps, you should have a bootable Windows USB drive ready. You can use this to install or repair your Windows operating system. Remember to change your computer’s boot order if you intend to boot from the USB drive.

Conclusion

creating a bootable Windows 10 or 11 USB drive on Linux doesn’t have to be an intimidating task. Our script simplifies the process, making it accessible to both beginner and experienced Linux users. It’s an all-in-one solution that manages everything from formatting the USB drive, checking the ISO’s integrity, to efficiently copying the necessary files. Remember, this process involves data deletion, so always back up any important data on the USB drive before proceeding. With this script, preparing for a Windows installation or repair can be done in no time. Happy Linuxing!



Comments and Discussions
Linux Forum