ThorneLabs

Create a Bootable Windows 7 or 10 USB Drive in Linux

• Updated April 1, 2020


There are a lot of guides on the web describing how to create a bootable Windows 7 or 10 USB drive in Linux. However, many of those guides have missing steps, involve using Windows, or use programs not readily available on modern Linux distributions.

The following post will walk you through the necessary steps to create a bootable Windows 7 or 10 USB drive from a modern Linux distribution.

Download the Windows 7 or 10 ISO File

If you do not already have the Windows 7 or 10 ISO file, start by downloading one of them:

Plugin the USB Drive

Next, you need to figure out the device ID of the USB drive.

Most modern Linux distributions should automount the USB drive. If not, you can see what device ID is assigned to the USB drive by running df -h or mount or lsblk.

Additionally, syslog can be monitored to find the device ID.

On Fedora, CentOS, or RHEL, run sudo tail -f /var/log/messages.

On Ubuntu or Debian, run sudo tail -f /var/log/syslog.

Once you figure out the USB drive’s device ID, be sure to unmount it before continuing:

sudo umount /dev/sdX

Partition the USB Drive

Disclaimer: The following steps will erase everything on your USB drive. I am not, nor is anyone else, responsible for any potential data loss.

Either parted or fdisk can be used to partition the USB drive. Use the command you are more familiar with.

Changes made using parted cannot be reverted because they are executed in real time to the device. Changes made using fdisk can be reverted as long as those changes have not yet been written to the device. In either case, make sure you are making changes to the correct device.

Partition the USB Drive with parted

Open the USB drive in parted:

sudo parted /dev/sdX

Once you are in the parted interactive menu, partition the USB drive with the following steps (Make sure you are using parted on the right device ID. Everything done using parted is executed in real time.):

(parted) mklabel msdos
(parted) mkpart primary ntfs 1 -1
(parted) set 1 boot on
(parted) quit

Next, go to the section titled Format the New Partition on the USB Drive as NTFS.

Partition the USB Drive with fdisk

Open the USB drive in fdisk:

sudo fdisk /dev/sdX

Once you are in the fdisk interactive menu, partition the USB drive with the following steps:

  1. Type p and Enter to print the current partition table. I do this out of habit.
  2. Delete all the current partitions by typing d then Enter for each partition.
  3. Type n and Enter. Type p and Enter. Type 1 and then type Enter three times to create one new primary partition that uses all available space.
  4. Type t and Enter (Partition 1 is automatically selected because it’s the only partition). Type 7 and Enter to change the type to HPFS/NTFS/exFAT.
  5. Type a and Enter. Type 1 and Enter to turn on the Boot flag.
  6. To verify everything worked, type p and Enter and make sure the Boot column has an asterisk (*) set and the Id column is set to 7.
  7. Finally, type w and Enter to write the changes.

Next, go to the section titled Format the New Partition on the USB Drive as NTFS.

Format the New Partition on the USB Drive as NTFS

You will need the Linux NTFS userspace driver installed.

To install it on Fedora, CentOS, or RHEL, run sudo yum install ntfs-3g.

To install it on Ubuntu or Debian, run sudo apt-get install ntfs-3g.

Then, format the partition as NTFS:

sudo mkfs.ntfs -f /dev/sdX1

Install ms-sys

You will need program ms-sys to write a Master Boot Record (MBR) to the USB drive.

To compile the source code, install the following packages: gcc, make, and gettext (the package names should be the same on Fedora, CentOS, RHEL, Ubuntu, and Debian).

To install those packages on Fedora, CentOS, or RHEL, run sudo yum install gcc make gettext.

To install those packages on Ubuntu or Debian, run sudo apt-get install gcc make gettext.

Download the latest ms-sys source code from http://ms-sys.sourceforge.net/#Download.

Un-tar the source code and change into the source code directory:

tar xvzf ms-sys-2.6.0.tar.gz

cd ms-sys-2.6.0

Compile and install the binary:

make

sudo make install

ms-sys will install to /usr/local/bin.

If you do not have /usr/local/bin in your shell’s environment path, run the following commands to temporarily add it:

su -

export PATH=$PATH:/usr/local/bin

Write a Master Boot Record (MBR) to the USB Drive

Now that ms-sys is installed, you will use it to write a Windows 7 Master Boot Record to the USB drive. This same command also works if you are creating a bootable Windows 10 USB drive.

sudo ms-sys -7 /dev/sdX

Successful output should be:

Windows 7 master boot record successfully written to /dev/sdX

Write an Extended Boot Record (EBR) to the USB Drive Partition

In addition to the Master Boot Record, you might also need to write an Extended Boot Record. For the lifetime of this post I have not had this step, but I recently added it because I encountered boot problems when trying to boot Windows 10 from a USB drive on a Lenovo X1 Carbon Gen 7. I found this step thanks to a similar post at Wayne Chang’s blog.

sudo  ms-sys -n /dev/sdX1

Successful output should be:

NTFS Windows 7 boot record successfully written to /dev/sdX1

Mount the USB Drive

Create or use an existing directory to mount the USB drive:

sudo mkdir -p /mnt/usb

sudo mount /dev/sdX1 /mnt/usb

Mount the Windows 7 or 10 ISO

Create or use an existing directory to mount the Windows 7 or 10 ISO:

sudo mkdir -p /mnt/iso

sudo mount -o loop /path/to/windows/iso.iso /mnt/iso

Copy the Contents of the Windows 7 or 10 ISO to the USB Drive

Finally, copy the contents of the mounted Windows 7 ISO to the mounted USB drive (this could take some time depending on the speed of the USB drive):

sudo cp -av /mnt/iso/* /mnt/usb/

Unmount the USB Drive

Unmount the USB drive once the cp command is finished.

sudo umount /mnt/usb

On several occasions the cp command completed before all I/O was written to the USB drive. Because of this, sudo umount /mnt/usb stalled until all I/O had been written. As previously mentioned, depending on the speed of your USB drive, it could take sometime for all I/O to finish being written to your USB drive.

Use the iotop command to watch the I/O throughput of the USB drive in real time. Once you no longer see the USB drive at the top of iotop’s output, sudo umount /mnt/usb should successfully exit.

Boot from the USB Drive

Plug the USB drive into the computer you want to install Windows 7 on and boot from it.

Modern laptops and desktop motherboards typically have several USB boot options such as:

  • USB-HDD
  • USB-ZIP
  • USB-FDD
  • USB-CDROM

Use trial and error to figure out the appropriate USB boot option to boot to.

For example, on a Gigabyte GA-MA74GM-S2 motherboard, booting to USB-HDD did not work. I had to boot to USB-ZIP. However, on a Lenovo ThinkPad X220 I had to boot to USB-HDD.