Leopard changed default partition table type breaking makediskimage.sh

Not sure where exacly I found makediskimage.sh, heck probably saw another project using it, but for sure it has saved a lot of hassle back when I was learning how to create disk image files. Unfortunately it doesn't have any author or history so I never knew who to thank :( With the Leopard upgrade it suddenly stopped working. The HFS format step was failing and was just outputing it's help text. Looking at the line just above in the script that generated that output, I noticed that the echo output was not correct:

    ...
        created: /tmp/20096.dmg
        Creating HFS partition Chandler_iosx_debug_0.7.3.dev-r15733 on /tmp/20096.dmg at
        usage: newfs_hfs [-h | -w] [-N] [hfsplus-options] special-device
        options:
    ...

The line that starts "Creating HFS partition..." should end with "at /dev/disk5s1" - what drive the HFS formatting would have happened on. The bash script segment responsible for that is:

    DEVICES=`hdid -nomount $TMPFILE`
    DEVMASTER=`echo $DEVICES| awk '{ print $1 }'`
    DEVHFS=`echo $DEVICES| awk '{ print $5 }'`

    echo Creating HFS partition $NAME on $TMPFILE at $DEVHFS

    newfs_hfs -v "$NAME" $DEVHFS

The line of interest is the output of hdid - up until Leopard it would output something like:

    oliver:~ bear$ hdid -nomount /tmp/bear.dmg
        /dev/disk2                Apple_partition_scheme
        /dev/disk2s1              Apple_partition_map
        /dev/disk2s2              Apple_HFS

Which shows the drive and two partitions, but under Leopard it now outputs:

    imac3:~ bear$ hdid -nomount /tmp/bear.dmg
        /dev/disk5                GUID_partition_scheme
        /dev/disk5s1              Apple_HFS

When you pass that to an environment variable (which, remember, removes all line feeds and makes it into a long string) you now get:

DEVHFS=/dev/disk5  GUID_partition_scheme  /dev/disk5s1  Apple_HFS

Instead of

DEVHFS=/dev/disk2  Apple_partition_scheme  /dev/disk2s1  Apple_partition_map /dev/disk2s2  Apple_HFS

Basically to try and get to an actual point :) - when

awk '{ print $5 }'

is run on the new output there isn't a fifth item so you get nothing back. The fix is to switch to a method that isn't dependent on the layout of the columns and the lines:

DEVHFS=`hdid -nomount $TMPFILE | grep Apple_HFS | awk '{ print $1 }'`

Now we take the raw output, grep for the line we really want and grab the first column of that. With the extra bonus of it working now on all OS X's I could get my hands on to test. Anywho, just wanted to post this in case someone else runs into their makediskimage.sh script suddenly start to fail.


Mentions