From 4fe6b6751ca96352ab222d8694393b61d892d6ef Mon Sep 17 00:00:00 2001 From: Gardouille Date: Sun, 25 Oct 2015 02:26:34 +0100 Subject: [PATCH] make_win_usb: Make a USB key with Winchiasse based on a ISO file. --- make_win_usb | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 make_win_usb diff --git a/make_win_usb b/make_win_usb new file mode 100755 index 0000000..3d9651c --- /dev/null +++ b/make_win_usb @@ -0,0 +1,57 @@ +#!/bin/sh + +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