Hard Drive Speed / Type Extension Attribute

smb_samba
New Contributor III

Hey All,

I did a bit of searching through the forums but I couldn't find exactly what I was looking for. I'm looking for a way via an extension attribute to find machines that either have a SSD or rotational drive. I don't necessarily need specifics, just if it's rotational or SSD.

I know you could do something like, system_profiler | grep "Medium Type" but I was wondering if anybody had expanded on that.

Thanks in advance for any help.

25 REPLIES 25

stevewood
Honored Contributor II
Honored Contributor II

I would stay away from the system_profiler command, only because it is too intensive for what you need. Like using a sledgehammer to kill a fly. It takes too long to generate the report, and thus your recons will take forever too.

I would look at using diskutil to do this. You can use the info function of diskutil to grab the info of a drive. This would get you the info you need:

diskutil info disk1 | grep "Media Name"

The caveat to that is that you are assuming disk1 is the only drive in the system and that is your main drive, which in my system is true. However, in a system that is encrypted with FileVault, disk0 is the drive that holds the info about media type, and disk1 does not have that info.

You could make an assumption (not a good idea), and look at disk0 and disk1 info and use either an if/then or case statement or something like that to cycle through the responses. Something like this might work (thrown together so please test):

#!/bin/sh

disk0=`diskutil info disk0 | grep "Media Name" | awk '{ print $6 }'`
disk1=`diskutil info disk1 | grep "Media Name" | awk '{ print $6 }'`

if [[ $disk0 == "SSD" ]]; then

    echo "<result>disk0 is SSD</result>"
    exit 0

elif [[ $disk1 == "SSD" ]]; then

    echo "<result>disk1 is SSD</result>"
    exit 0

fi

echo "<result>No SSD Drives</result>"

exit 0

In my mind, however, you'd want to devise a way to list the drives that are installed, and then cycle through those. Could do this with an ls of the /dev folder and grab only diskx items. I'm sure there's a better way, that's just me spit balling off the top of my head.

HTH, and if it doesn't make sense, just ask away.

Not applicable

Agree with Steve that diskutil is probably a better solution, but if you do use system_profiler you should be sure to specify ```
system_profiler SPStorageDataType
``` - save a lot of extra time and wasted effort.

dcpeterson
New Contributor

Building off of what Steve said, you could use the following if you just want to see if it is a SSD or not.

#!/bin/sh

disk0=`diskutil info disk0 | grep "Solid State" | awk '{ print $3 }'`
disk1=`diskutil info disk1 | grep "Solid State" | awk '{ print $3 }'`

if [[ $disk0 == "Yes" ]]; then

   echo "<result>disk0 is SSD</result>"
   exit 0

elif [[ $disk1 == "Yes" ]]; then

   echo "<result>disk1 is SSD</result>"
   exit 0

fi

echo "<result>No SSD Drives</result>"

exit 0

mm2270
Legendary Contributor III
diskutil info /

will pull information on the boot volume, regardless of whether FileVault 2 encryption is on (meaning there is a CoreStorage volume) or not.

So using that, we can do something like:

#!/bin/sh

MediaType=$(diskutil info / | awk '/Media Type/{print $NF}')

echo "<result>$MediaType</result>"

On my 13" MBP that pulls: "Generic" (whatever that means). I haven't tested the above beyond my own Mac, but I assume on a MBA or other Mac with an SSD, it would report as "SSD" or something along those lines.

smb_samba
New Contributor III

Sorry - should have specified one more key fact. We have been replacing standard rotational Apple drives with 3rd party SSDs. This causes issues with @stevewood's original script. @dcpeterson's modification seems to do the trick (will do a bit more testing and report back). Thanks everyone!

stevewood
Honored Contributor II
Honored Contributor II

Actually @mm2270, that won't pull the drive info. That pulls the partition info. So when I run that on my MBA with an SSD in it, Media Type is also Generic for me, and there is no mention of what type of hard drive is in the system.

@dcpeterson great catch on the Solid State flag. I missed that when I did my first pass at that.

mm2270
Legendary Contributor III

Ah, yes, I see now. My mistake. I think I was looking at some other lines in the output.

In that case, what @dcpeterson][/url][/url wrote up is going to be the best bet. 'Solid State' will tell the tale.

tlarkin
Honored Contributor

Hey Everyone,

I do not have an SSD drive, but I think we could build an array of device nodes by doing this:

$ diskutil list | awk '/dev/ { print $1 }'
/dev/disk0
/dev/disk1

Using awk to print out the first column of the output of `diskutil list` command, we can pattern match anything with the word 'dev' in it. This gives me the following output I posted above this.

Now I do not have a SSD to test this, but I just whipped this up together based on what this thread has given me:

#!/bin/bash

# create array of device nodes of mounted volumes

diskList=$(diskutil list | awk '/dev/ { print $1 }')

for i in ${diskList[@]} ; do

echo "<result>$(diskutil info $i | awk '/Media Type/ { print $NF }')</result>"
done

exit 0

Here is the output of my script:

$ bash -x ssd_check.sh 
++ diskutil list
++ awk '/dev/ { print $1 }'
+ diskList='/dev/disk0
/dev/disk1'
+ for i in '${diskList[@]}'
++ diskutil info /dev/disk0
++ awk '/Media Type/ { print $NF }'
+ echo '<result>Generic</result>'
<result>Generic</result>
+ for i in '${diskList[@]}'
++ diskutil info /dev/disk1
++ awk '/Media Type/ { print $NF }'
+ echo '<result>Generic</result>'
<result>Generic</result>

Please test and modify if need be to ensure it detects SSD and repost here. If it puts Solid State in the output you can then run advanced reports or create smart groups based on any Mac that has the output "Solid State," in that extension attribute in Casper.

Thanks,
Tom

mm2270
Legendary Contributor III

I didn't reply back to this again yesterday, but I seriously don't think its necessary to know the disk identifier, since we're talking about an Extension Attribute, which can only run while the Mac is booted from the internal boot volume. Different story if we needed to do this while in an imaging workflow.
The line:

diskutil info / | awk '/Solid State/{print $NF}'

returns a "Yes" or "No". The / identifier returns the same results as using something like "disk1", etc because its all coming from the same boot volume. I don't think there's any need to try to figure out the specific volume identifier.

tlarkin
Honored Contributor

Mike,

I agree with you that will most likely work. However, I know some people who have two drives in their Mac laptop, as they have opted to remove their optical drive. Some configurations are a combo of SSD/nonSSD drives. Also, in the older Mac Pros, you could have multiple drives. The end user could be booted off of any drive. I only wrote my code to try to encompass all the possibilities of different models and different configurations. I also know people that often boot to thunderbolt drives, or have a Mac Mini that is connected to a hardware TB array of disks.

My method just detects the model type, then you would sort out smart groups or advanced searches based on the output of that. Furthermore it would allow you to easily and quickly compare how many platter hard drives versus how many solid state hard drives you have in your entire deployment.

Personally, I think this should be a feature request, and just automatically collected and easily reportable in the device record of each Mac in the JSS. I would suggest someone post that in our Feature Request section. I think running a script is a bit of an overkill for this.

Thanks,
Tom

mm2270
Legendary Contributor III

OK, I can see how a more complicated setup of a Mac Pro with multiple drives, perhaps more than one with a bootable OS on them could get tricky. Fair enough.
I would agree that the drive type should be captured natively in the Casper Suite since almost all other data about any drives installed or attached are captured. Even stuff like the serial number and Revision, so why not the drive type (SSD vs spinning platter) Definitely should be a native item captured.

tlarkin
Honored Contributor

I went ahead an added it as an internal feature request in our system. If any of you feel that this is something you would like to see, please post it on JAMF Nation and vote it up.

Thanks,
Tom

Kevin
Contributor II

Tell me what I'm doing wrong here…

If I run this script on a Mac, I get a correct response–yes or no–if a solid state drive is present or not. It works.

#!/bin/sh
SSD=diskutil info / | awk '/Solid State/{print $NF}'
if [ $SSD == "Yes" ];then echo "Yes"
else echo "No"
fi
exit 0

If I paste this in an extension attribute trying to get a result, nothing is returned when I recon a system.

I know I am overlooking something super-simple (and probably dumb) here. What?

mm2270
Legendary Contributor III

@Kevin- you forgot to add the <result></result> tags around the echo lines. That's why its not returning anything.

Kevin
Contributor II

DOH…Told ya!

Thank you!

donmontalvo
Esteemed Contributor III

Sorry for jumping into this thread late, we actually have a need to show computers that have SSD boot drives.

Any of our Macs that have SSD would have Apple branded, not third party.

It looks like JSS gathers Storage > Model info, which shows SSD if exists.

The JSS database already has the info we need, I'll open a ticket with JAMF to see if they have a way to display that info in a report/search.

Don

--
https://donmontalvo.com

GabeShack
Valued Contributor III

@donmontalvo Don did you ever get a response from Jamf on this?

I would love access to that info as well.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

bpavlov
Honored Contributor

Won't help you now, but you should vote this up and make a comment on gathering this information as well (assuming it's not already in the DB):
https://jamfnation.jamfsoftware.com/featureRequest.html?id=2837

donmontalvo
Esteemed Contributor III

@gshackney I actually didn't get a chance, other stuff came up.

--
https://donmontalvo.com

saucio
New Contributor

I'm working to implement this and created an Extension Attribute with Data Type String and Input Type Script

The full Script is

!/bin/sh

SSD=diskutil info / | awk '/Solid State/{print $NF}'
if [ $SSD == "Yes" ];then echo "<result>Yes</result>"
else echo "<result>No</result>"
fi
exit 0

I see the Attribute Extension in Hardware reporting, but no values are being populated. Anyone know what I'm doing wrong?

tuinte
Contributor III

Have the machines you're looking at done an update inventory since the EA went live? The JSS won't have the info for a machine until that machine has had an inventory update.

boanes
New Contributor III

I've tested Saucio's EA and I've forced my machine to report to the JSS and the JSS doesn't show any info in the field.

Ideas?

mm2270
Legendary Contributor III

@boanes If you copied and pasted saucio's script as it appears above, I can assure you it won't work since it's not a valid script as it's shown. It likely was valid, originally, but the forum will mess up script formatting if it's not wrapped in the script tags to retain the format.

Try the following, which is essentially the same script, but with formatting intact.

#!/bin/sh

SSD=$(diskutil info / | awk '/Solid State/{print $NF}')

if [ $SSD == "Yes" ]; then
    echo "<result>Yes</result>"
else
    echo "<result>No</result>"
fi

exit 0

Tested against my MBPr and it correctly shows a Yes result since it has an SSD drive as the main boot disk.

boanes
New Contributor III

That did it! Thanks @mm2270!

kevin_v
Contributor

2021 Update - this script is not working - have confirmed some SSDs were not reported correctly for macOS 10.15

#!/bin/sh

SSD=$(diskutil info / | awk '/SSD/{print $NF}')

if [ $SSD == "Yes" ]; then
    echo "<result>Yes</result>"
else
    echo "<result>No</result>"
fi

exit 0