Monday, June 10, 2013
There are a ridiculous number of guides on how to create a bootable Windows 7 USB drive from within Linux. However, many of the guides have missing steps, involve using Windows, or use programs not readily available on other Linux distributions. The following guide should work on any Linux distribution to create a bootable Windows 7 USB drive.
Most modern Linux distributions should automount the USB drive. You will need to see what device it is assigned to by running
df -h or
mount. syslog can also be monitored to find the device it is assigned to by running
tail -f /var/log/messages as root in Fedora; other Linux distributions should be similar but Ubuntu uses /var/log/syslog.
Once you have figured out what device the USB drive is assigned to, be sure to unmount it before continuing.
Also, the following steps will erase everything on the USB drive you are using. You are responsible for your own data.
Either fdisk or parted can be used to partition the USB drive. Use whatever command you are more familiar with.
Be aware that changes made using fdisk can be undone as long as those changes have not been written. On the other hand, changes made using parted are applied in real time. In either case be SURE you are making changes to the proper device.
Type p and Enter to print the current partition table. I do this out of habit.
Delete all the current partitions by typing d then Enter for each partition.
Type n and Enter, then type p and Enter, then type 1 and Enter three times to create one new primary partition that uses all available space.
Type t and Enter (Partition 1 is selected because it’s the only partition), then type 7 and Enter to change the type to HPFS/NTFS/exFAT.
Type a and Enter, then type 1 and Enter to turn on the Boot flag.
To verify everything worked, type p and Enter and make sure the Boot column has an * set and the Id column is set to 7.
Type w and Enter to write the changes.
Make SURE you are using parted on the right device. Everything done using parted is applied in real time.
parted /dev/sdX (parted) mklabel msdos (parted) mkpart primary ntfs 1 -1 (parted) set 1 boot on (parted) quit
You will need the Linux NTFS userspace driver installed. On Fedora run
yum install ntfs-3g to install it, or on Ubuntu
apt-get install ntfs-3g.
mkfs.ntfs -f /dev/sdX1
You will need the ms-sys program to write a Master Boot Record (MBR) to the USB drive.
Download the latest 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.3.0.tar.gz cd ms-sys-2.3.0
Compile and install the binary:
make make install
ms-sys -7 /dev/sdX
mkdir -p /mnt/flash mount /dev/sdX1 /mnt/flash
mkdir -p /mnt/iso mount -o loop /root/en_windows_7_professional_x64_dvd_X15-65805.iso /mnt/iso
cp -av /mnt/iso/* /mnt/flash/
I encountered several instances where the copy command finished before all I/O was written to the USB drive. Because of this, the unmount command below will stall until all I/O is finished. I/O can be watched in real time by installing iotop.
Plugin the USB drive to the computer you want to install Windows on and boot to USB-HDD or USB-ZIP. There could be instances where you have to boot to USB-FDD or USB-CDROM instead.
For example, on a Gigabyte GA-MA74GM-S2 motherboard, booting to USB-HDD did not work, I had to boot to USB-ZIP, but on a Lenovo ThinkPad X220 I booted to USB-HDD.