Create Windows 7/8/10 bootable USB drive in macOS with command line (MBR partitioning scheme)

In the following procedure we will create a Microsoft Windows bootable USB flash drive in macOS, from scratch with command line. Root privileges are required.

Test environment: macOS 10.13.1
Requirements: syslinux 4.03 and port of syslinux 4.03 to macOS

Warning: All the data on the USB flash drive will be destroyed without warning! Make sure you selected the correct drive or you will destroy a wrong disk!

1. Identify the USB flash drive, in my example the device is /dev/disk2.

diskutil list
/dev/disk0 (internal, physical):
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         121.1 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +121.1 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume SSD 128GB               34.8 GB    disk1s1
   2:                APFS Volume Preboot                 18.5 MB    disk1s2
   3:                APFS Volume Recovery                520.8 MB   disk1s3
   4:                APFS Volume VM                      1.1 GB     disk1s4

/dev/disk2 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *15.5 GB disk2 1: DOS_FAT_32 WINDOWS 15.5 GB disk2s1

2. Erase the /dev/disk2, create one big partition /dev/disk2s1 and format as FAT32 with the label “WINDOWS”. All data on /dev/disk2 will be destroyed!

diskutil partitionDisk /dev/disk2 1 MBR FAT32 WINDOWS R
Started partitioning on disk2
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk2s1 as MS-DOS (FAT32) with name WINDOWS
512 bytes per physical sector
/dev/rdisk2s1: 30248048 sectors in 1890503 FAT32 clusters (8192 bytes/cluster)
bps=512 spc=16 res=32 nft=2 mid=0xf8 spt=32 hds=255 hid=2 drv=0x80 bsec=30277630 bspf=14770 rdcl=2 infs=1 bkbs=6
Mounting disk
Finished partitioning on disk2
/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.5 GB    disk2
   1:                 DOS_FAT_32 WINDOWS                 15.5 GB    disk2s1

3. Download and unpack syslinux 4.03 source code.

curl https://www.kernel.org/pub/linux/utils/boot/syslinux/4.xx/syslinux-4.03.tar.gz -o syslinux-4.03.tar.gz
tar -zxvf syslinux-4.03.tar.gz

4. Download syslinux macOS port and make it executable.

curl https://raw.githubusercontent.com/gkovacs/syslinux-mac/master/mac/syslinux -o syslinux
chmod +x syslinux

5. Unmount and write the bootstrap code (mbr.bin) to the MBR of /dev/disk2.

diskutil unmountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
dd if=syslinux-4.03/mbr/mbr.bin of=/dev/disk2 bs=440 count=1
1+0 records in
1+0 records out
440 bytes transferred in 0.000908 secs (484509 bytes/sec)

6. Install syslinux, this will alter the boot sector and copy ldlinux.sys into the root directory.

./syslinux -i /dev/disk2s1
syslinux for Mac OS X; created by Geza Kovacs for UNetbootin unetbootin.sf.net
"/dev/disk2s1" unmounted successfully.
/dev/disk2s1            DOS_FAT_32                      /Volumes/WINDOWS
mountpoint is /Volumes/WINDOWS
checkpoint1
checkpoint1.5
checkpoint1.6
/Volumes/WINDOWS/ldlinux.sys ldlinuxname
checkpoint2
checkpoint3
"/dev/disk2s1" unmounted successfully.
checkpoint4
checkpoint5
checkpoint6
checkpoint7
checkpoint8
/dev/disk2s1            DOS_FAT_32                      /Volumes/WINDOWS

7. Copy syslinux BIOS modules and create syslinux.cfg.

mkdir /Volumes/WINDOWS/syslinux
cp syslinux-4.03/com32/modules/*.c32 /Volumes/WINDOWS/syslinux
echo -e "default boot\nLABEL boot\nMENU LABEL boot\nCOM32 chain.c32\nAPPEND fs ntldr=/bootmgr" > /Volumes/WINDOWS/syslinux/syslinux.cfg

8. Mount the Microsoft Windows ISO image.

hdiutil mount /example/windows.iso -mountpoint /Volumes/WINSETUP

9. Copy the Windows installation files to the USB flash drive, it might take a few minutes.

cp -Rv /Volumes/WINSETUP/ /Volumes/WINDOWS/

10. Unmount the USB flash drive.

diskutil unmountDisk /dev/disk2

2 Replies to “Create Windows 7/8/10 bootable USB drive in macOS with command line (MBR partitioning scheme)”

Leave a Reply

Your email address will not be published. Required fields are marked *