Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get serial number from Mac hard disks?

Tags:

macos

cocoa

Is there an easy way to get the serial number of all the hard disks in a Mac using an API?

Basically, I'm looking for a unique identifier for the hard disk with which I can figure out whether the hard disk has been used (or referred to) by my application or not.

Please let me know if there is any other solution.

Note: I need this solution for 10.4 and above.

like image 653
Girish Kolari Avatar asked Jan 07 '10 09:01

Girish Kolari


People also ask

Does a hard drive have a serial number?

Next to each hard drive, you'll see the drive's serial number. This is the number that the manufacturer has assigned to the drive. That's a quick and easy way to read your hard drive's serial number!


2 Answers

The following will list the serial numbers on the SATA-bus. You don't get to know which device it is as is but you can do it with some scripting/parsing. I've used "sed" to remove all the spaces and "awk" to isolate just the serial in case you are not familiar:

$ system_profiler SPSerialATADataType -detailLevel medium | grep Serial | sed -e 's/[\<\>\"\ ]//g' | -F':' '{print $2}'
like image 128
Robert Jansson Avatar answered Oct 13 '22 12:10

Robert Jansson


From the command line:

ioreg -rd1 -w0 -c AppleAHCIDiskDriver | grep Serial

This gives you the serial number of the built-in hard disk.

like image 30
Matthias Braun Avatar answered Oct 13 '22 14:10

Matthias Braun