#!/bin/sh # Source: http://admincloud.net/116/creer-une-cle-usb-bootable-de-windows-sous-linux/ WIN_HDD=/dev/sdb WIN_USB_MNT_PATH=/mnt/USBW7/ WIN_ISO_FILE="${1}" WIN_ISO_MNT_PATH=/mnt/WIN7/ # Empty MBR sudo dd if=/dev/zero of=${WIN_HDD} bs=446 count=1 # Ensure to have a MS-DOS partition table sudo parted ${WIN_HDD} mklabel msdos # Create one big partition with "boot" flag then format in NFTS sudo parted ${WIN_HDD} mkpart primary 0% 100MS-partition table sudo parted ${WIN_HDD} set 1 boot on sudo mkfs.ntfs ${WIN_HDD}1 --fast --no-indexing # Mount USB key sudo mkdir -p -- "${WIN_USB_MNT_PATH}" sudo mount ${WIN_HDD}1 "${WIN_USB_MNT_PATH}" # Mount ISO file sudo mkdir -p -- "${WIN_ISO_MNT_PATH}" sudo mount "${WIN_ISO_FILE}" "${WIN_ISO_MNT_PATH}" -o loop,ro # Copy all files from ISO to USB sudo cp -rv "${WIN_ISO_MNT_PATH}"* "${WIN_USB_MNT_PATH}" # Umount and remove mount path sudo umount "${WIN_USB_MNT_PATH}" sudo umount "${WIN_ISO_MNT_PATH}" sudo rmdir -- "${WIN_USB_MNT_PATH}" "${WIN_ISO_MNT_PATH}" ## Make the key bootable # Ensure gettext is available sudo aptitude install -y gettext # Ensure to download the last version of ms-sys if [ ! $(command -v ms-sys) ]; then # http://ms-sys.sourceforge.net/#Download wget http://netix.dl.sourceforge.net/project/ms-sys/ms-sys%20development/2.5.0/ms-sys-2.5.0.tar.gz -O /tmp/ms-sys-2.5.0.tar.gz # Extract and install ms-sys cd /tmp tar xzvf /tmp/ms-sys-2.5.0.tar.gz cd /tmp/ms-sys-2.5.0.tar.gz sudo make sudo make install fi # For Win 7/8 sudo ms-sys --mbr7 "${WIN_HDD}" exit 0