2015-10-25 02:26:34 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-10-25 19:15:14 +01:00
|
|
|
# Source: http://admincloud.net/116/creer-une-cle-usb-bootable-de-windows-sous-linux/
|
|
|
|
|
2015-11-17 22:06:17 +01:00
|
|
|
WIN_USB="${1}"
|
2015-10-25 02:26:34 +01:00
|
|
|
WIN_USB_MNT_PATH=/mnt/USBW7/
|
2015-11-17 21:58:55 +01:00
|
|
|
WIN_ISO_FILE="${2}"
|
2015-10-25 02:26:34 +01:00
|
|
|
WIN_ISO_MNT_PATH=/mnt/WIN7/
|
|
|
|
|
2015-11-17 22:06:17 +01:00
|
|
|
# Test if args exists
|
|
|
|
for file in "${WIN_USB}" "${WIN_ISO_FILE}"; do
|
|
|
|
if [ ! -e "${file}" ]; then
|
|
|
|
printf '%b' "${file} doesn't exists. Please check your args.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-10-25 02:26:34 +01:00
|
|
|
# Empty MBR
|
2015-11-17 22:06:17 +01:00
|
|
|
sudo dd if=/dev/zero of=${WIN_USB} bs=446 count=1
|
2015-10-25 02:26:34 +01:00
|
|
|
|
|
|
|
# Ensure to have a MS-DOS partition table
|
2015-11-17 22:06:17 +01:00
|
|
|
sudo parted ${WIN_USB} mklabel msdos
|
2015-10-25 02:26:34 +01:00
|
|
|
|
|
|
|
# Create one big partition with "boot" flag then format in NFTS
|
2015-11-17 22:06:17 +01:00
|
|
|
sudo parted ${WIN_USB} mkpart primary 0% 100MS-partition table
|
|
|
|
sudo parted ${WIN_USB} set 1 boot on
|
|
|
|
sudo mkfs.ntfs ${WIN_USB}1 --fast --no-indexing
|
2015-10-25 02:26:34 +01:00
|
|
|
|
2015-11-17 22:12:43 +01:00
|
|
|
# Mount first partition of the USB key
|
2015-10-25 02:26:34 +01:00
|
|
|
sudo mkdir -p -- "${WIN_USB_MNT_PATH}"
|
2015-11-17 22:06:17 +01:00
|
|
|
sudo mount ${WIN_USB}1 "${WIN_USB_MNT_PATH}"
|
2015-10-25 02:26:34 +01:00
|
|
|
|
|
|
|
# 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
|
2015-11-17 22:12:43 +01:00
|
|
|
sudo cp -rv -- "${WIN_ISO_MNT_PATH}"* "${WIN_USB_MNT_PATH}"
|
2015-10-25 02:26:34 +01:00
|
|
|
|
|
|
|
# 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
|
2015-11-17 22:06:17 +01:00
|
|
|
sudo ms-sys --mbr7 "${WIN_USB}"
|
2015-10-25 02:26:34 +01:00
|
|
|
|
2015-11-17 22:12:43 +01:00
|
|
|
# For Win XP/2000/2003
|
|
|
|
#sudo ms-sys --mbr "${WIN_USB}"
|
|
|
|
|
|
|
|
# For Win Vista
|
|
|
|
#sudo ms-sys --mbrvista "${WIN_USB}"
|
|
|
|
|
2015-10-25 02:26:34 +01:00
|
|
|
exit 0
|