All pastes #904676 Raw Edit

script.sh

public text v1 · immutable
·published 2008-02-15 04:03 UTC
rendered paste body
#!/bin/bash

function status {
    printf "\n$1\n"
}

VOLNAME=$1
PART=`/usr/misc/diskfind "$VOLNAME"`
RAWPART=r$PART
DISK=`echo $PART | sed 's/^\(disk[0-9]*\)s.*$/\1/g'`
RAWDISK=r$DISK
PARTID=`echo $PART | sed 's/^disk[0-9]*s\([0-9]*\)$/\1/g'`

if [ -z "$VOLNAME" ] || [ -z "$PART" ]; then
    echo "Couldn't find specified volume. Exiting."
    exit
elif [ ! -e "/dev/$RAWPART" ] || [ ! -e "/dev/$DISK" ] ||
     [ ! -e "/dev/$RAWDISK" ]; then
    echo "Internal error. Exiting."
    exit
fi

printf "Target volume: $VOLNAME\n"
printf "Target partition: $PART\n\n"

diskutil mount /dev/$PART
diskutil unmount force "/Volumes/$VOLNAME"
if [ $? != 0 ]; then
    echo "Couldn't unmount the specified volume. Exiting."
    exit
fi

diskutil unmountDisk force /dev/$DISK
if [ $? != 0 ]; then
    echo "Couldn't unmount other volumes in disk. MBR may remain unset!"
else
    status "Writing MBR to $DISK."
    dd if=/usr/standalone/i386/boot0 of=/dev/$DISK bs=1 count=446
fi

status "Flagging partition $PART as bootable."
printf "update\nflag $PARTID\nwrite\ny\n" | fdisk -e /dev/$RAWDISK

status "Writing boot block to partition $PART."
dd if=/usr/standalone/i386/boot1h of=/dev/$PART bs=1 count=512

status "Setting HFS+ startup file on $RAWPART."
/usr/misc/startupfiletool /dev/$RAWPART /usr/standalone/i386/boot

status "Blessing (device) partition $PART."
/usr/misc/bless24 -device /dev/$PART -setBoot -verbose

status "Blessing (mount) volume $VOLNAME."
diskutil mount /dev/$PART
/usr/misc/bless24 -mount "/Volumes/$VOLNAME" -setBoot -verbose

status "Done."