Created
September 16, 2013 20:42
-
-
Save brycied00d/6586330 to your computer and use it in GitHub Desktop.
Quick script to build a USB bootable stick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Quick script to build a USB bootable stick | |
# Requires syslinux, sfdisk, dosfstools, and looptools | |
# ex: script2.sh /dev/sdd /path/to/overlay | |
USBDEVICE=$1 | |
if [ ! $1 ] | |
then | |
echo You must specify the full path to the USB device, e.g. /dev/sdd | |
exit 1 | |
fi | |
OVERLAY=$2 | |
if [ ! $2 ] | |
then | |
echo You must specify the full path to the OVERLAY directory to use. | |
exit 1 | |
fi | |
base_usb=$(basename "$USBDEVICE") | |
base_overlay=$(basename "$OVERLAY") | |
echo -e '\033k'$base_overlay':'$base_usb'\033\\' | |
# First, try to make sure the device is unmounted first | |
umount $USBDEVICE | |
umount ${USBDEVICE}1 | |
# The new, adaptive way!!! | |
echo "o | |
n | |
p | |
1 | |
t | |
6 | |
a | |
1 | |
w" | fdisk $USBDEVICE | |
if [ ! "x$?" = "x0" ] | |
then | |
echo "Error partitioning device!" | |
exit 1 | |
fi | |
cat /usr/lib/syslinux/mbr.bin > $USBDEVICE | |
if [ ! "x$?" = "x0" ] | |
then | |
echo "Error installing bootloader!" | |
exit 1 | |
fi | |
USBDIR=`mktemp -d` | |
mkdosfs ${USBDEVICE}1 | |
if [ ! "x$?" = "x0" ] | |
then | |
echo "Error formatting partition!" | |
exit 1 | |
fi | |
syslinux ${USBDEVICE}1 | |
if [ ! "x$?" = "x0" ] | |
then | |
echo "Error installing syslinux!" | |
exit 1 | |
fi | |
mount ${USBDEVICE}1 ${USBDIR}/ | |
if [ ! "x$?" = "x0" ] | |
then | |
echo "Error mounting partition!" | |
exit 1 | |
fi | |
#cp -va ${OVERLAY}/* ${USBDIR}/ | |
rsync -rt -vCP --stats --delete --delete-excluded ${OVERLAY}/* ${USBDIR}/ | |
if [ ! "x$?" = "x0" ] | |
then | |
echo "Error copying to device!" | |
exit 1 | |
fi | |
umount ${USBDIR}/ | |
if [ ! "x$?" = "x0" ] | |
then | |
echo "Error unmounting device?!?" | |
exit 1 | |
fi | |
rmdir ${USBDIR} | |
echo -e '\033kDONE\033\\' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment