Index
Projects
Notes
Contact

How to install Windows 7 from an USB disk

In case you don't want to use Rufus or some other tool (maybe because you only run Linux boxes and don't have a Windows installation handy)

You'll need:

Note the procedure will destroy all data on the USB disk.

General outline:

  1. create a MBR partition table on the disk
  2. create a single primary partition with type 0x07
  3. make it active
  4. format it as NTFS
  5. install the NT 6.0 bootloader to the partition's VBR via bootsect.exe /nt60
  6. copy the entire contents of the ISO to the partition

This assumes there is MBR code that dispatches to the VBR of the active partition. This is done automatically if you create the partition table using diskpart. It is not done by Linux fdisk, but is done by diskpart below.

Example fdisk -l dump for a 4 GB USB stick, after doing the procedure:

Disk /dev/sdg: 3.76 GiB, 4039114752 bytes, 7888896 sectors
Disk model: DataTraveler 2.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start     End Sectors  Size Id Type
/dev/sdg1  *      128 7888895 7888768  3.8G  7 HPFS/NTFS/exFAT

Instructions for Windows

NOTE: there is no need to install Windows for this. You can run all programs (diskpart, bootsect) from the Windows 7 ISO recovery tools in a virtual machine.

NOTE: if you do run these commands on a system with other disks with important data, keep in mind the commands below could wipe the file systems if you are not careful. Make really sure that you select the actual USB stick!

C:\>diskpart
list disk                   locate the USB stick; assume X is its number
select disk X
clean                       wipe the disk
create partition primary
select partition 1
active
format fs=NTFS QUICK
assign                      assume diskpart gives X: to the USB partition
exit

C:\>WIN7_ISO:
WIN7_ISO:\>cd boot
WIN7_ISO:\boot>bootsect /nt60 X:

Now copy all files in WIN7_ISO: to X:

WIN7_ISO:\>xcopy /E WIN7_ISO:\ X:\

Using QEMU without USB passthrough

If you are using QEMU and for some reason USB passthrough is not working, then you can still follow the procedure. First, create a raw image file the same exact size as your USB stick:

  $ dd if=/dev/zero of=usb_stick bs=512 count=7888896

(the sector count and size of the USB disk can be found with fdisk -l). Then boot the Windows 7 ISO using QEMU, attaching the image as a virtual USB stick:

  $ qemu-system-x86_64 -accel kvm -m 4096 -machine q35 -usb             \
                       -drive if=none,file=usb_stick,format=raw,id=us0  \
                       -device usb-storage,drive=us0,removable=on       \
                       -cdrom win7.iso -boot d

Follow the procedure above. When finished, write the image file contents to the USB stick using dd (assuming the USB stick is /dev/sdg):

  $ dd if=usb_stick of=/dev/sdg bs=512 count=7888896 status=progress

NOTE: the command above will destroy all data in /dev/sdg, so be absolutely sure it refers to the USB stick!