Your one stop formatting shop

Update 22 Dec 2016

So I finally got around to creating a new NBI based on 10.12.
When I tried to run this script on 10.12, I found that Apple had changed the output in the diskutil command.

So previously I was searching for the text of either yes or no for the removable media label.
Under 10.12, this is no longer the case, with Apple replacing the word “No” with “fixed”

To combat this, the only thing to do is, of course, use python, for which I have a love hate relationship. So in the interests of just getting it done, I have updated the script replacing the following:

 $(echo "$DISK_INFO" | awk '/Solid State:/ {print $3}') = "No")

with

$(diskutil info -plist $DISK | plutil -convert json -o - - | python -c 'import sys, json; print json.load(sys.stdin)["SolidState"]')

This gets the output from diskutil as a plist, converts it into json and then uses python to print out the value for the key ‘SolidState’ which is returned as a boolean (true/false)

This is much better than parsing text which may change in the future.

Update – 9 Aug 2016

Well so it turns out I made some assumptions in my first draft of the formatting script around how to identify a machine for Fusion Drive. Turns out I also left out what to do if a FileVault enabled disk was discovered. I have updated the script to handle all these cases.

The script should now detect the correct device ID’s for the SSD and HDD if found. It will also check to see if a FileVault disk is locked or unlocked. If it is unlocked, it will proceed to delete the core storage volume. If the FileVault volume is locked, it will throw an error to the user via a CocoaDialog message box.

The script will also now check to ensure that the drives it formats are internal, physical, non removable media disks. As SD cards can often present as internal, physical this could be a complication. Luckily they also show up as removable, so checking this we can avoid formatting any SD cards that may be in the machine.

As I also do a lot of testing with VMware Fusion, I have a check in the script to ensure that VMware disks are formatted correctly as well. This is because VMware fusion disks show up as external, physical disks rather than internal, physical disks.

 

 

 

In my environment I use DeployStudio and Imagr to deploy our “image” to client devices.

Recently I came across an issue with some iMacs that have a Fusion drive.

When I use DeployStudio, I was targeting the restore task to “First drive available”

Screen Shot 2016-06-22 at 10.56.39 AM

This had always worked very well for me in the past, however I noticed that a few of the latest iMacs had failed to complete the image build (via Munki) due to a full HD.

When I checked their computer record in Munki Report it was pretty clear what had happened.

storage

storage2

For some reason, the fusion drive has ‘un-fused’ and DeployStudio has installed our base OS image onto the SSD.

Turns out this is a bit of an issue with DeployStudio. There are quite a few posts on the deploy studio forums about this.

There are a few solutions out there like having a workflow that is for Fusion Drive Mac’s that uses DeployStudio’s Fusion Drive task first and then you can just target the volume name of your new Fusion Drive in the Restore Task

Screen Shot 2016-06-22 at 11.13.10 AM

But I really like to have One Workflow To Rule Them All! So I didn’t like that solution, also users don’t know if their Mac has a fusion drive or not so there is confusion there.

Instead I came up with a script that will check a machine to see if it has a Fusion Drive or atleast the components for a fusion drive i.e. SSD and HDD.

The script will then create a new Fusion Drive, deleting any current FD if it already exists, create a new volume on the Fusion Drive called Macintosh HD.

The script will also be able to tell if the machine does not have a fusion drive, in this case the script will simply locate the internal HDD or SSD and format it and create a volume called Macintosh HD.

So now I simply run this script as the first item in the workflow and ensure that my Restore Task targets my new volume called Macintosh HD whether it be on a Fusion Drive LVG or a regular JHFS+ Partition.

The contents of the script are as below:

 

 

 

 

Advertisements

8 comments

  1. Hi Calum,

    Thanks for the excellent script , i am using your script and modifying it to use it in a netboot environment and in casper imaging. i noticed that it work wonderfully on 10.11 but now it is not working on 10.12 sierra .

    i narrow down to the function CHECK_FOR_SSD , i am not sure if you are having the same issue ?

    Like

    1. Hi,

      Nope no issues for me on 10.12. I am using imagr though, not casper. Casper Imaging has always been a problem for me, even when I was using Casper at a lot of sites I never bothered using Casper Imaging it never suited my needs and created too many problems.

      perhaps you could upload the log file from the script somewhere and i can take a look

      Like

      1. HI Calum,

        I see that you upgraded the script. Thanks alot it help.

        I updated your script and i found issue with it. Still the same function CHECK_FOR_SSD is causing the problem

        i saw your changes , and did a comparison and make the modification , the core changes are the SSD_STATUS variable and the if [[ “$SSD_STATUS” = “False” ]] && [[ “$REMOVABLE_STATUS” = “False” ]]; statement

        I tested on a fusion drive mac mini , the script ran and when it goes to CHECK_FOR_SSD function,

        It didn’t detect the hard drive properly

        Wed Feb 01 13:31:27 NetBoot758 jamf – Mac Model: Macmini7,1 _may_ have a FUSION DRIVE!
        Wed Feb 01 13:31:27 NetBoot758 jamf
        Wed Feb 01 13:31:27 NetBoot758 jamf – Checking for an Multiple Internal Disks…
        Wed Feb 01 13:31:27 NetBoot758 jamf [OK] Detected 2 internal disks, checking for SSD and HDD..
        Wed Feb 01 13:31:27 NetBoot758 jamf
        Wed Feb 01 13:31:27 NetBoot758 jamf – Checking 2 disks looking for SSD or HDD and Non Removable Media …
        Wed Feb 01 13:31:27 NetBoot758 jamf
        Wed Feb 01 13:31:27 NetBoot758 jamf – Checking /dev/disk0 …
        Wed Feb 01 13:31:27 NetBoot758 jamf [ERROR] Disk /dev/disk0 does not meet our requirements of SSD or HDD and Non Removable Media. Moving on.
        Wed Feb 01 13:31:27 NetBoot758 jamf
        Wed Feb 01 13:31:28 NetBoot758 jamf – Checking /dev/disk1 …
        Wed Feb 01 13:31:29 NetBoot758 jamf [ERROR] Disk /dev/disk1 does not meet our requirements of SSD or HDD and Non Removable Media. Moving on.
        Wed Feb 01 13:31:29 NetBoot758 jamf [ERROR] Did not find a SSD AND HDD!
        Wed Feb 01 13:31:29 NetBoot758 jamf – Checking for CoreStorage Volumes…
        Wed Feb 01 13:31:29 NetBoot758 jamf [OK] – CoreStorage LVG found with ID: 2C0AD3AA-4C19-4E85-95A8-1DA45D8C5C09
        Wed Feb 01 13:31:29 NetBoot758 jamf – Checking for FileVault Encryption ….
        Wed Feb 01 13:31:29 NetBoot758 jamf [OK] FileVault not enabled
        Wed Feb 01 13:31:29 NetBoot758 jamf – Locating CoreStorage LVG …
        Wed Feb 01 13:31:29 NetBoot758 jamf [OK] – Located existing CoreStorage LVG with ID: 2C0AD3AA-4C19-4E85-95A8-1DA45D8C5C09
        Wed Feb 01 13:31:29 NetBoot758 jamf – Removing CoreStorage LVG ID: 2C0AD3AA-4C19-4E85-95A8-1DA45D8C5C09 …

        Background , i am using netboot and the netboot is 10.12.3 Sierra and i am using Casper Imaging

        diskutil list log

        Disk0 is the SSD
        Disk1 is the 1TB HDD

        NetBoot743:~ root# diskutil list
        /dev/disk0 (internal, physical):
        #: TYPE NAME SIZE IDENTIFIER
        0: GUID_partition_scheme *121.3 GB disk0
        1: EFI EFI 209.7 MB disk0s1
        2: Apple_CoreStorage Mac HD 121.0 GB disk0s2
        3: Apple_Boot Boot OS X 134.2 MB disk0s3
        /dev/disk1 (internal, physical):
        #: TYPE NAME SIZE IDENTIFIER
        0: GUID_partition_scheme *1.0 TB disk1
        1: EFI EFI 209.7 MB disk1s1
        2: Apple_CoreStorage Mac HD 999.9 GB disk1s2
        3: Apple_Boot Boot OS X 134.2 MB disk1s3
        /dev/disk2 (external, physical):
        #: TYPE NAME SIZE IDENTIFIER
        0: GUID_partition_scheme *127.8 MB disk2
        1: Apple_HFS Untitled 127.8 MB disk2s1
        /dev/disk3 (disk image):
        #: TYPE NAME SIZE IDENTIFIER
        0: GUID_partition_scheme +9.0 GB disk3
        1: EFI EFI 209.7 MB disk3s1
        2: Apple_HFS NB Apple LS 8.7 GB disk3s2
        /dev/disk4 (disk image):
        #: TYPE NAME SIZE IDENTIFIER
        0: untitled +268.4 MB disk4
        /dev/disk5 (internal, virtual):
        #: TYPE NAME SIZE IDENTIFIER
        0: Apple_HFS Mac HD +1.1 TB disk5
        Logical Volume on disk0s2, disk1s2
        E5860F2F-7E09-49EF-B2C4-363CBEB46CD5
        Unencrypted Fusion Drive

        Like

      2. Get the new script from my github. I’m using this script successfully at 2,000+ sites with 3500+ machines.

        Also ditch casper imaging, its horrible!

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s