Archive

Archive for December 17, 2012

Detecting Boot Camp partitions with Casper

December 17, 2012 Leave a comment

I was recently tasked with reporting on how many Boot Camp installs of Windows we had on our Macs. Boot Camp is something we normally do on a as-needed basis, so it’s not on every machine. However, I did need something that worked consistently across the various flavors of OS X that we have.

In this case, I was asked to just verify the existence of a Boot Camp partition and was not tasked with identifying the version of Windows that was installed on the partition. With a little help from this thread on JAMF Nation, I was able to come up with the following script for use as a Casper Extension Attribute:


#!/bin/sh

#
# Using diskutil list to check for 
# disk partitions reporting as 
# "Microsoft Basic Data"
#

BOOTCAMP_DETECT=$( /usr/sbin/diskutil list | grep -c "Microsoft Basic Data" )

#
# If Microsoft Basic Data partition is
# reported by diskutil, script reports
# "Yes". If no Microsoft Basic Data partition
# is reported by diskutil, script reports "No".
# 

if [[ "${BOOTCAMP_DETECT}" == "1" ]]; then
      result=Yes
   else
      result=No
fi
echo "<result>$result</result>"

exit 0

This script uses the diskutil list command to check for disk partitions reporting as being Microsoft Basic Data. I chose not to look for NTFS volumes, as that could pick up false positives from non-Boot Camp NTFS drives.

If a Microsoft Basic Data partition is reported by diskutil, the script reports Yes. If there is not a Microsoft Basic Data partition on the Mac, the script reports No.

For those interested, the script is available on my GitHub repo:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/Casper_Extension_Attributes/detect_bootcamp_partition

Categories: Bash scripting, Casper
Follow

Get every new post delivered to your Inbox.

Join 126 other followers

%d bloggers like this: