From 75a4a592e5ccda30715f93563d741b83e0dcf39e Mon Sep 17 00:00:00 2001 From: Patrick J Volkerding Date: Mon, 25 Apr 2011 13:37:00 +0000 Subject: Slackware 13.37 Mon Apr 25 13:37:00 UTC 2011 Slackware 13.37 x86_64 stable is released! Thanks to everyone who pitched in on this release: the Slackware team, the folks producing upstream code, and linuxquestions.org for providing a great forum for collaboration and testing. The ISOs are off to be replicated, a 6 CD-ROM 32-bit set and a dual-sided 32-bit/64-bit x86/x86_64 DVD. Please consider supporting the Slackware project by picking up a copy from store.slackware.com. We're taking pre-orders now, and offer a discount if you sign up for a subscription. As always, thanks to the Slackware community for testing, suggestions, and feedback. :-) Have fun! --- usb-and-pxe-installers/usbimg2disk.sh | 140 +++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 35 deletions(-) (limited to 'usb-and-pxe-installers/usbimg2disk.sh') diff --git a/usb-and-pxe-installers/usbimg2disk.sh b/usb-and-pxe-installers/usbimg2disk.sh index aed32c51b..f806c5ed6 100644 --- a/usb-and-pxe-installers/usbimg2disk.sh +++ b/usb-and-pxe-installers/usbimg2disk.sh @@ -1,7 +1,7 @@ -#!/bin/sh -# $Id: usbimg2disk.sh,v 1.9 2010/04/24 18:21:53 eha Exp eha $ +#!/bin/bash +# $Id: usbimg2disk.sh,v 1.20 2011/04/16 19:11:27 eha Exp eha $ # -# Copyright 2009, 2010 Eric Hameleers, Eindhoven, NL +# Copyright 2009, 2010, 2011 Eric Hameleers, Eindhoven, NL # All rights reserved. # # Redistribution and use of this script, with or without modification, is @@ -24,15 +24,19 @@ # Paranoid as usual: set -e +# Define some variables ahead of time, so that cleanup knows about them: +MNTDIR1="" +MNTDIR2="" +MNTDIR3="" + # Clean up in case of failure: cleanup() { # Clean up by unmounting our loopmounts, deleting tempfiles: echo "--- Cleaning up the staging area..." sync - umount -f ${MNTDIR1} 2>/dev/null || true - umount -f ${MNTDIR2} 2>/dev/null || true - rm -rf ${MNTDIR3} - rmdir $MNTDIR1 $MNTDIR2 + [ ! -z "${MNTDIR1}" ] && ( umount -f ${MNTDIR1} ; rmdir $MNTDIR1 ) + [ ! -z "${MNTDIR2}" ] && ( umount -f ${MNTDIR2} ; rmdir $MNTDIR2 ) + [ ! -z "${MNTDIR3}" ] && rm -rf ${MNTDIR3} || true } trap "echo \"*** $0 FAILED at line $LINENO ***\"; cleanup; exit 1" ERR INT TERM @@ -60,7 +64,7 @@ showhelp() { echo "# -o|--outdev The device name of your USB drive" echo "# -s|--slackdir Use 'dir' as the root of Slackware tree" echo "# -u|--unattended Do not ask any questions" - echo "# -L|--label FAT label when formatting the USB drive" + echo "# -L|--label FAT label when formatting the USB drive" echo "# " echo "# Examples:" @@ -90,6 +94,9 @@ reformat() { # Wipe the MBR: dd if=/dev/zero of=$TOWIPE bs=512 count=1 + # Temporarily accept errors (so that we can examine them): + set +e + # create a FAT32 partition (type 'b') /sbin/fdisk $TOWIPE </dev/null 2>/dev/null ; then echo "*** I fail to find a 'vfat' partition: '$TARGETPART' !" echo "*** If you want to format the USB thumb drive, add the '-f' parameter" exit 1 fi -else - if [ ! -b $TARGET ]; then - echo "*** Not a block device: '$TARGET' !" - exit 1 - fi fi if mount | grep -q $TARGETPART ; then @@ -267,6 +305,11 @@ if [ $UNATTENDED -eq 0 ]; then echo "" echo "# We are going to ${DOFRMT}use this device - '$TARGET':" + echo "# Vendor : $(cat /sys/block/$(basename $TARGET)/device/vendor)" + echo "# Model : $(cat /sys/block/$(basename $TARGET)/device/model)" + echo "# Size : $(( $(cat /sys/block/$(basename $TARGET)/size) / 2048)) MB" + echo "# " + echo "# FDISK OUTPUT:" /sbin/fdisk -l $TARGET | while read LINE ; do echo "# $LINE" ; done echo "" @@ -283,12 +326,37 @@ cat /dev/null > $LOGFILE # If we need to format the USB drive, do it now: if [ $REFORMAT -eq 1 ]; then - echo "--- Formatting $TARGET and creating VFAT partition..." + echo "--- Formatting $TARGET with VFAT partition label '${FATLABEL}'..." if [ $UNATTENDED -eq 0 ]; then echo "--- Last chance! Press CTRL-C to abort!" read -p "Or press ENTER to continue: " JUNK fi ( reformat $TARGET ${FATLABEL} ) 1>>$LOGFILE 2>&1 +else + # We do not format the drive, but apply a FAT label if required. + + # Prepare for using mlabel to change the FAT label: + MTOOLSRCFILE=$(mktemp -p /tmp -t mtoolsrc.XXXXXX) + echo "drive s: file=\"$TARGETPART\"" > $MTOOLSRCFILE + + if [ -n "$CUSTOMLABEL" ]; then + # User gave us a FAT label to use, so we will force that upon the drive: + echo "--- Setting FAT partition label to '$FATLABEL'" + MTOOLSRC=$MTOOLSRCFILE mlabel s:${FATLABEL} + elif [ -n "$(/sbin/blkid -t TYPE=vfat -s LABEL -o export $TARGETPART)" ] ; then + # User did not care, but the USB stick has a FAT label that we will use: + eval $(/sbin/blkid -t TYPE=vfat -s LABEL -o export $TARGETPART) + FATLABEL=$LABEL + echo "--- Using current FAT partition label '$FATLABEL'" + unset LABEL + else + # No user-supplied label, nor a drive label present. We apply our default: + echo "--- Setting FAT partition label to '$FATLABEL'" + MTOOLSRC=$MTOOLSRCFILE mlabel s:${FATLABEL} + fi + + # Cleanup: + rm -f $MTOOLSRCFILE fi # Create a temporary mount point for the image file: @@ -298,7 +366,7 @@ if [ ! -d $MNTDIR1 ]; then echo "*** Failed to create a temporary mount point for the image!" exit 1 else - chmod 700 $MNTDIR1 + chmod 711 $MNTDIR1 fi # Create a temporary mount point for the USB thumb drive partition: @@ -307,7 +375,7 @@ if [ ! -d $MNTDIR2 ]; then echo "*** Failed to create a temporary mount point for the usb thumb drive!" exit 1 else - chmod 700 $MNTDIR2 + chmod 711 $MNTDIR2 fi # Create a temporary directory to extract the initrd if needed: @@ -316,7 +384,7 @@ if [ ! -d $MNTDIR3 ]; then echo "*** Failed to create a temporary directory to extract the initrd!" exit 1 else - chmod 700 $MNTDIR3 + chmod 711 $MNTDIR3 fi # Mount the image file: @@ -369,7 +437,7 @@ fi # Copy boot image files to the USB disk in its own subdirectory '/syslinux': echo "--- Copying boot files to the USB drive..." mkdir -p $MNTDIR2/syslinux -cp -a $MNTDIR1/* $MNTDIR2/syslinux/ +cp -R $MNTDIR1/* $MNTDIR2/syslinux/ rm -f $MNTDIR2/syslinux/ldlinux.sys # If we are creating a full Slackware installer, there is a lot more to do: @@ -389,10 +457,13 @@ if [ "$FULLINSTALLER" = "yes" ]; then # Adapt the dialogs so that pressing [OK] will be all there is to it: sed -i -e 's# --menu# --default-item 6 --menu#' usr/lib/setup/SeTmedia sed -i -e "s# 2> \$TMP/sourcedir# /usbinstall/$(basename $REPOSROOT)/$PKGDIR 2> \$TMP/sourcedir#" usr/lib/setup/INSdir + FIXF=$(find usr/lib/setup -name SeTp*media) + sed -i -e 's# --menu# --default-item 3 --menu#' $FIXF ) 2>>$LOGFILE # Recreate the initrd: echo "--- Gzipping the initrd image again:" + chmod 0755 ${MNTDIR3} ( cd ${MNTDIR3}/ find . |cpio -o -H newc |gzip > ${MNTDIR2}/syslinux/initrd.img ) 2>>$LOGFILE @@ -400,11 +471,10 @@ if [ "$FULLINSTALLER" = "yes" ]; then # Copy Slackware package tree (no sources) to the USB disk - # we already made sure that ${REPOSROOT} does not end with a '/' echo "--- Copying Slackware package tree to the USB drive..." - rsync -rptHDL $EXCLUDES $REPOSROOT $MNTDIR2/ + rsync -rpthDL --delete $EXCLUDES $REPOSROOT $MNTDIR2/ fi # Unmount/remove stuff: -sync cleanup # Run syslinux and write a good MBR: -- cgit v1.2.3