From 4d5cdc379e338c1c28f4d7d09226d4167a3f9e1e Mon Sep 17 00:00:00 2001 From: Eric Hameleers Date: Sat, 28 Nov 2015 01:52:06 +0100 Subject: Slackware Live Edition: initial commit. This is Beta 2. Read http://alien.slackbook.org/blog/slackware-live-edition-beta-2 for all the details. --- iso2usb.sh | 312 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 iso2usb.sh (limited to 'iso2usb.sh') diff --git a/iso2usb.sh b/iso2usb.sh new file mode 100644 index 0000000..79cf944 --- /dev/null +++ b/iso2usb.sh @@ -0,0 +1,312 @@ +#!/bin/bash +# $Id: iso2usb.sh,v 1.5 2015/11/22 22:53:01 root Exp root $ +# +# Copyright 2015 Eric Hameleers, Eindhoven, NL +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Be careful: +set -e + +# Set to '1' if the script should not ask any questions: +UNATTENDED=0 + +# By default do not show file operations in detail: +VERBOSE=0 + +# Seconds to add to the initrd as wait-for-root value: +WAIT=5 + +# Define ahead of time, so that cleanup knows about them: +IMGDIR="" +EFIMNT="" +ISOMNT="" +USBMNT="" + +# Clean up in case of failure: +cleanup() { + # Clean up by unmounting our loopmounts, deleting tempfiles: + echo "--- Cleaning up the staging area..." + # During cleanup, do not abort due to non-zero exit code: + set +e + sync + [ -n "${EFIMNT}" ] && ( umount -f ${EFIMNT} ; rmdir $EFIMNT ) + [ -n "${ISOMNT}" ] && ( umount -f ${ISOMNT} ; rmdir $ISOMNT ) + [ -n "${USBMNT}" ] && ( umount -f ${USBMNT} ; rmdir $USBMNT ) + [ -n "${IMGDIR}" ] && ( rm -rf $IMGDIR ) + set -e +} +trap 'echo "*** $0 FAILED at line $LINENO ***"; cleanup; exit 1' ERR INT TERM + +showhelp() { +cat < Full path to the ISO image file +# -o|--outdev The device name of your USB drive +# -u|--unattended Do not ask any questions +# -v|--verbose Show verbose messages +# -w|--wait Pause boot seconds to ititialize USB + +# +# Example: +# +# $(basename $0) -i ~/download/slackware64-live-14.2.iso -o /dev/sdX +# +EOT +} + +# Parse the commandline parameters: +if [ -z "$1" ]; then + showhelp + exit 1 +fi +while [ ! -z "$1" ]; do + case $1 in + -h|--help) + showhelp + exit + ;; + -i|--infile) + SLISO="$(cd $(dirname $2); pwd)/$(basename $2)" + shift 2 + ;; + -o|--outdev) + TARGET="$2" + shift 2 + ;; + -u|--unattended) + UNATTENDED=1 + shift + ;; + -v|--verbose) + VERBOSE=1 + RVERBOSE=" -v --progress " + shift + ;; + -w|--wait) + WAIT="$2" + shift 2 + ;; + *) + echo "*** Unknown parameter '$1'!" + exit 1 + ;; + esac +done + +# Before we start: +[ -x /bin/id ] && CMD_ID="/bin/id" || CMD_ID="/usr/bin/id" +if [ "$($CMD_ID -u)" != "0" ]; then + echo "*** You need to be root to run $(basename $0)." + exit 1 +fi + +# More sanity checks: +if [ -z "$TARGET" -o -z "$SLISO" ]; then + echo "*** You must specify both the Live ISO filename and the USB devicename!" + exit 1 +fi + +if [ ! -f $SLISO ]; then + echo "*** This is not a useable file: '$SLISO' !" + exit 1 +fi + +if [ ! -b $TARGET ]; then + echo "*** Not a block device: '$TARGET' !" + exit 1 +elif [ "$(echo ${TARGET%[0-9]})" != "$TARGET" ]; then + echo "*** You need to point to the USB device, not a partition ($TARGET)!" + exit 1 +fi + +# Are all the required not-so-common add-on tools present? +PROG_MISSING="" +for PROGN in cpio extlinux fdisk mkdosfs sgdisk ; do + if ! which $PROGN 1>/dev/null 2>/dev/null ; then + PROG_MISSING="${PROG_MISSING}-- $PROGN\n" + fi +done +if [ ! -z "$PROG_MISSING" ] ; then + echo "-- Required program(s) not found in PATH!" + echo -e ${PROG_MISSING} + echo "-- Exiting." + exit 1 +fi + +# Confirm wipe: +cat < wait-for-root +echo "--- Compressing the initrd image again:" +chmod 0755 ${IMGDIR} +find . |cpio -o -H newc |gzip > ${USBMNT}/boot/initrd.img +cd - 2>/dev/null + +# Create persistence directory: +mkdir -p ${USBMNT}/persistence + +# Use extlinux to make the USB device bootable: +echo "--- Making the USB drive '$TARGET' bootable using extlinux..." +mv ${USBMNT}/boot/syslinux ${USBMNT}/boot/extlinux +mv ${USBMNT}/boot/extlinux/isolinux.cfg ${USBMNT}/boot/extlinux/extlinux.conf +rm ${USBMNT}/boot/extlinux/isolinux.* +extlinux --install ${USBMNT}/boot/extlinux + +# Unmount/remove stuff: +cleanup + +# Install a GPT compatible MBR record: +if [ -f /usr/share/syslinux/gptmbr.bin ]; then + cat /usr/share/syslinux/gptmbr.bin > ${TARGET} +else + echo "*** Failed to make USB device bootable - 'gptmbr.bin' not found!" + exit 1 +fi + +# THE END + -- cgit v1.2.3