diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh
index f4d0855..f92fe2b 100755
--- a/tools/livecd-iso-to-disk.sh
+++ b/tools/livecd-iso-to-disk.sh
@@ -47,21 +47,24 @@ getdisk() {
return
fi
- p=$(udevadm info -q path -n $DEV)
- if [ -e /sys/$p/device ]; then
- device=$(basename /sys/$p)
+ path=$(udevadm info -q path -n $DEV)
+ if [ -e /sys/$path/device ]; then
+ device=$(basename /sys/$path)
else
- device=$(basename $(readlink -f /sys/$p/../))
+ device=$(basename $(readlink -f /sys/$path/../))
fi
if [ ! -e /sys/block/$device -o ! -e /dev/$device ]; then
- echo "Error finding block device of $DEV. Aborting!"
- exitclean
+ echo "Error finding block device of $DEV. Aborting!"
+ exitclean
fi
-
- device="/dev/$device"
+
# FIXME: weird dev names could mess this up I guess
- p=/dev/`basename $p`
- partnum=${p##$device}
+ set $( awk '$4 ~ /'${device#/}'.*[0-9]$/ {print $4}' /proc/partitions )
+ partition=$1
+ path=/dev/$(basename $path)
+ partnum=${path##$device}
+ [[ -z "$partnum" ]] && partnum=${partition##$device}
+ device="/dev/$device"
}
resetMBR() {
@@ -157,16 +160,17 @@ createGPTLayout() {
echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
echo "Press Enter to continue or ctrl-c to abort"
read
- umount ${device}? &> /dev/null
+ umount ${device}* &> /dev/null
/sbin/parted --script $device mklabel gpt
partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit b print" |grep ^$device:)
size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/B$//')
/sbin/parted --script $device unit b mkpart '"EFI System Partition"' fat32 17408 $(($size - 17408)) set 1 boot on
- USBDEV=${device}1
# Sometimes automount can be _really_ annoying.
echo "Waiting for devices to settle..."
/sbin/udevadm settle
sleep 5
+ partnum=$( awk '$4 ~ /'${device#/}'.*[0-9]$/ {print $4}' /proc/partitions )
+ USBDEV=${device}${partnum}
umount $USBDEV &> /dev/null
/sbin/mkdosfs -n LIVE $USBDEV
USBLABEL="UUID=$(/sbin/blkid -s UUID -o value $USBDEV)"
@@ -179,16 +183,17 @@ createMSDOSLayout() {
echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
echo "Press Enter to continue or ctrl-c to abort"
read
- umount ${device}? &> /dev/null
+ umount ${device}* &> /dev/null
/sbin/parted --script $device mklabel msdos
partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit b print" |grep ^$device:)
size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/B$//')
/sbin/parted --script $device unit b mkpart primary fat32 17408 $(($size - 17408)) set 1 boot on
- USBDEV=${device}1
# Sometimes automount can be _really_ annoying.
echo "Waiting for devices to settle..."
/sbin/udevadm settle
sleep 5
+ partnum=$( awk '$4 ~ /'${device#/}'.*[0-9]$/ {print $4}' /proc/partitions )
+ USBDEV=${device}${partnum}
umount $USBDEV &> /dev/null
/sbin/mkdosfs -n LIVE $USBDEV
USBLABEL="UUID=$(/sbin/blkid -s UUID -o value $USBDEV)"