在 Linux 上创建适用于 Windows 10 和 11 的可启动 USB在 Linux 上创建适用于 Windows 10 和 11 的可启动 USB在 Linux 上创建适用于 Windows 10 和 11 的可启动 USB在 Linux 上创建适用于 Windows 10 和 11 的可启动 USB
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

在 Linux 上创建适用于 Windows 10 和 11 的可启动 USB

当您想要安装或修复操作系统时,通常需要创建可启动 USB 驱动器。本指南提供了如何使用 Linux(Debian 和基于 RPM 的发行版)为 Windows 10 或 11 创建可启动 USB 驱动器的详细步骤。

我们方便的脚本完成了所有繁重的工作,使这项任务变得轻而易举。该脚本的运行方式是格式化 USB 驱动器,然后将 ISO 文件复制到 USB 驱动器。

在本教程中您将学习:

  • 创建适用于 Windows 10 的可启动 USB

  • 为 Windows 11 创建可启动 USB

准备工作

  1. 下载Windows ISO文件:您可以直接从微软官网下载Windows 10和11 ISO文件。确保将 ISO 文件保存在您记得的位置,因为我们需要脚本的路径。

  2. 识别您的 USB 驱动器:插入 USB 驱动器并使用命令 lsblk 列出所有块设备。识别您的 USB 驱动器的名称(例如 /dev/sdc、/dev/sdd 等)。

请注意:此过程中该驱动器上的所有数据都将被删除,因此请务必在继续之前备份所有重要数据!

运行脚本

下载 ISO 文件并识别您的 USB 驱动器后,您现在可以继续使用我们的脚本。

  1. 下载脚本:下载我们的脚本并将其保存在方便的位置。假设它保存为 create_win_usb.sh。

  2. 使脚本可执行:在运行脚本之前,我们需要使其可执行。打开终端并导航到保存脚本的位置。运行命令 chmod +x create_win_usb.sh 使其可执行。

  3. 运行脚本:现在您可以运行脚本了!使用命令 ./create_win_usb.sh /path/to/your/iso /dev/sdX 运行它,将 /path/to/your/iso 替换为实际路径到您的 ISO 文件,以及 /dev/sdX 到您的实际 USB 块设备。例如:

    ./create_win_usb.sh ~/Downloads/Win11_English_x64.iso /dev/sdc

在 Linux 上创建适用于 Windows 10 和 11 的可启动 USB 脚本:

#!/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

在脚本执行过程中,它会在不同的步骤请求您的许可。例如,它将为您提供一个检查 ISO 文件校验和的选项(这可能会很耗时,具体取决于您的系统)。此外,在格式化 USB 驱动器之前,它会警告您数据丢失。请务必根据您的喜好响应这些提示。

最后,复制操作完成后,脚本会卸载驱动器并同步数据,请耐心等待。在断开 USB 驱动器之前等待“完成”消息至关重要,以防止数据损坏。

就是这样!通过这些步骤,您应该准备好可启动的 Windows USB 驱动器。您可以使用它来安装或修复 Windows 操作系统。如果您打算从 USB 驱动器启动,请记住更改计算机的启动顺序。

结论

在 Linux 上创建可启动的 Windows 10 或 11 USB 驱动器并不一定是一项艰巨的任务。我们的脚本简化了该过程,使初学者和经验丰富的 Linux 用户都可以使用它。它是一款一体化解决方案,可管理从格式化 USB 驱动器、检查 ISO 完整性到高效复制必要文件的所有事务。请记住,此过程涉及数据删除,因此请务必先备份 USB 驱动器上的所有重要数据,然后再继续。使用此脚本,可以立即完成 Windows 安装或修复的准备工作。祝 Linux 使用愉快!

©2015-2025 艾丽卡 support@alaica.com