Situation: You have a Windows DVD (or ISO), but like any sane person in 2013 you don’t have a DVD drive on the computer. You want to convert the Windows DVD into a bootable USB key. There are many recipes for this online, but they all require another Windows machine and of course cannot be automated.
- I am not going to support this script. You will need to read the script, look up the commands in the guestfish man page, and understand what it does. Any requests for help will be deleted unread.
- You need to edit the USB key device before using the script.
- You need libguestfs ≥ 1.21 with SYSLINUX support compiled in.
#!/bin/bash - guestfish <<'EOF' trace on add-ro en_microsoft_hyper-v_server_2012_x64_dvd_915600.iso # NB: The next line MUST be changed to your USB drive. # ANYTHING ON THIS DRIVE WILL BE OVERWRITTEN WITHOUT WARNING. add /dev/sdX run # Inside the appliance, /dev/sda = DVD, /dev/sdb = USB. # THESE ARE NOT RELATED TO HOST DISK NAMES. echo "Partitioning the USB disk ..." part-init /dev/sdb mbr part-add /dev/sdb p 63 -1 part-set-mbr-id /dev/sdb 1 0xb part-set-bootable /dev/sdb 1 true mkfs vfat /dev/sdb1 echo "Copying the contents of the DVD to the USB key ..." mkmountpoint /cd mkmountpoint /usb mount /dev/sda /cd mount /dev/sdb1 /usb # XXX We should add cp-r command XXX debug sh "cp -rP /sysroot/cd/* /sysroot/usb" #glob cp-a /cd/* /usb umount /cd umount /usb rmmountpoint /cd rmmountpoint /usb echo "Making the USB key bootable using SYSLINUX ..." syslinux /dev/sdb1 mount /dev/sdb1 / upload /usr/share/syslinux/chain.c32 /chain.c32 write /syslinux.cfg "DEFAULT windows\n\nLABEL windows\nCOM32 chain.c32\nAPPEND fs ntldr=/bootmgr\n" umount /dev/sdb1 upload /usr/share/syslinux/mbr.bin /dev/sdb echo "Finished." EOF