Script help/suggestions

johnnasset
Contributor

A number of our newer Macs are unable to Netboot (seems like any that shipped with Lion or higher). We have gone through the iphelper stuff but no luck. That said, I wrote a down and dirty script to repartition the disk, install the Recovery OS, reboot to said OS and reimage. Yes, I know it's not very pretty but does what I need it to (mostly):

#!/bin/sh
diskutil resizeVolume /dev/disk0s2 219G hfsx Restore 30G
killall Finder
jamf mount -server server.address.here -share CasperShare -type afp -username casperadmin -password somepassword
asr restore --source /Volumes/CasperShare/Packages/CasperRestore.dmg --target /Volumes/Restore --erase --noprompt
diskutil rename disk0s3 Restore
chflags hidden /Volumes/"Restore"
killall Finder
jamf unmountServer -mountPoint /Volumes/CasperShare

The intial test device was a Macbook with no recovery partition so disk0s3 is the correct designation for the newly created Restore partition. On a newer Macbook pro, there is already an apple recovery partition so the newly created partition would be disk0s4. Is there a way I could modify this portion of the script to pick the right disk identifier?

Also with the diskutil portion:

diskutil resizeVolume /dev/disk0s2 219G hfsx Restore 30G

How would I go about setting a 30G restore partition and setting disk0s2 to whatever space was left as we have multiple HD sizes?

2 REPLIES 2

andrew_stenehje
Contributor

I use the following to find a Windows partition, which is named "W7HD", and set the next boot to be from this partition:

#!/bin/sh

#####################################################
# Script to boot to Windows Partition if it exists
#####################################################

    # Find Windows Partition number
    W7HD=`diskutil list | grep "W7HD" | cut -c 69-75`

        echo Windows Partition is "$W7HD"


    # Checking to see if Windows partition exists
    if [ "$W7HD" != "" ]; then

            echo "Windows Partition exists, setting boot..."

            # Set boot to Windows
            /usr/sbin/bless --device /dev/"$W7HD" --setBoot --legacy

            echo "Blessed system to boot from Windows partition"

        else

            echo "No Windows partition exists... bye bye"

    fi

barnesaw
Contributor III

Alternate check for a bootcamp partition:

#!/bin/bash

# Get disk_s_ address of BOOTCAMP
bcamp=`diskutil list | grep BOOTCAMP | sed -e 's/^.*(disk.*$)/1/'`

We use this to dynamically detect windows partition and update bootpicker config.

It should be possible to use

diskutil list | grep 'Recovery HD' | sed -e 's/^.*(disk.*$)/1/'

to detect the Recovery partition.

Edited to correct script parts.