Link GPT ids to hardware devices

Moderators: jhartley, MSR734, nola

Link GPT ids to hardware devices

Post by si-ghan-bi » Sun Nov 11, 2012 6:31 pm

Hello, I would like to write a script that saves periodically HDD values like temperature, free space, etc and some ZFS parameters to a sqlite3 db.
However, I need to relate /dev/diskn to GPT ids used by ZEVO. Is there a command that gives me the GPT id of a disk device?
si-ghan-bi Offline


 
Posts: 145
Joined: Sat Sep 15, 2012 5:55 am

Re: Link GPT ids to hardware devices

Post by grahamperrin » Mon Nov 12, 2012 12:45 am

si-ghan-bi wrote:… Is there a command that gives me the GPT id of a disk device?


At first I recalled Don's viewtopic.php?p=700#p700 then realised, it's the answer to a different question about identification involving GPT (how to identify a disk at the /dev level, when its GPT UUID is already known).

So instead:

Code: Select all
sh-3.2$ ls -l /dev/dsk
lrwxr-xr-x  1 root  wheel  0 11 Nov 03:15 /dev/dsk -> /var/zfs/dsk
sh-3.2$ ls -l /var/zfs/dsk
total 8
lrwxr-xr-x  1 root  wheel  12 11 Nov 03:16 GPTE_71B8BDA2-3EBA-4B91-9E1C-2AE2B1DAAD06 -> /dev/disk2s2
sh-3.2$ sw_vers
ProductName:   Mac OS X
ProductVersion:   10.8.2
BuildVersion:   12C60
sh-3.2$ uname -a
Darwin macbookpro08-centrim.home 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64
sh-3.2$


Loosely:

Code: Select all
sh-3.2$ ioreg -l | grep disk2s2
    | |   |   |             |           |   "BSD Name" = "disk2s2"
sh-3.2$ ioreg -l | grep -B 10 disk2s2
    | |   |   |             |           |   "IOBusyInterest" = "IOCommand is not serializable"
    | |   |   |             |           |   "BSD Minor" = 12
    | |   |   |             |           |   "Content" = "6A898CC3-1DD2-11B2-99A6-080020736631"
    | |   |   |             |           |   "Size" = 615673253888
    | |   |   |             |           |   "ZFS_Single_VDEV" = Yes
    | |   |   |             |           |   "Whole" = No
    | |   |   |             |           |   "Removable" = No
    | |   |   |             |           |   "UUID" = "71B8BDA2-3EBA-4B91-9E1C-2AE2B1DAAD06"
    | |   |   |             |           |   "BSD Unit" = 2
    | |   |   |             |           |   "BSD Major" = 1
    | |   |   |             |           |   "BSD Name" = "disk2s2"
sh-3.2$


Code: Select all
sh-3.2$ zpool status | grep disk2s2
     GPTE_71B8BDA2-3EBA-4B91-9E1C-2AE2B1DAAD06  ONLINE       0     0     0  at disk2s2
sh-3.2$ zpool status | grep disk2s2 | cut -f 3

sh-3.2$ zpool status | grep disk2s2 | cut -f 2
  GPTE_71B8BDA2-3EBA-4B91-9E1C-2AE2B1DAAD06  ONLINE       0     0     0  at disk2s2
sh-3.2$


Food for thought.

Of the three chunks above, the first or third might better starting points than the second, but for the first, be aware of this unresolved question:

ZEVO Wiki Site/Disk Device Names: with or without a symlink?

Someone with good knowledge of command construction (not me) may dive in with something better than all three.

(Like, I really don't know how to use the cut command (and here's not the place to learn)! I love watching people come up with commands. Off-topic from the opening post, but related to ioreg in this post: Can a command with ioreg show the parts of the tree (of the I/O Kit registry in OS X) where UUIDs of volumes are found – with those UUIDs?)

If a gpt command is to be used, be aware of a possible bug:
gpt in OS X 10.8.2 seems to not recognise option -r
– side note under viewtopic.php?p=919#p919
grahamperrin Offline

User avatar
 
Posts: 1596
Joined: Fri Sep 14, 2012 10:21 pm
Location: Brighton and Hove, United Kingdom

show UUID-based alternate device names of ZEVO partitions

Post by grahamperrin » Tue Nov 13, 2012 1:40 am

Maybe ignore all of my previous post! I just remembered, a window that I minimised in Safari a month ago …

Show the UUID of a filesystem or partition

> Show the UUID-based alternate device names of ZEVO-related partitions on Darwin/OS X

– with credit to Don.

si-ghan-bi, please, does the command there give what's needed for your script?
grahamperrin Offline

User avatar
 
Posts: 1596
Joined: Fri Sep 14, 2012 10:21 pm
Location: Brighton and Hove, United Kingdom

Re: Link GPT ids to hardware devices

Post by si-ghan-bi » Tue Nov 13, 2012 5:03 am

I will try this evening, thanks!
si-ghan-bi Offline


 
Posts: 145
Joined: Sat Sep 15, 2012 5:55 am

Re: Link GPT ids to hardware devices

Post by si-ghan-bi » Tue Nov 13, 2012 6:52 pm

I tried, but I noticed I hadn't thought it through and there many more variables than I expected.

I can associate physical drives to /dev/diskn if they support SMART using smartctl and the serial number and model. However, some external drives don't support SMART and I even have one of them. Maybe I can just exclude them.
If "diskutil list /dev/diskn" shows a ZFS partition on a disk, I have to link it to a pool/datasets. GPT are needed to have some constant value between reboots to put in the DB. I can use "zpool status" for this. "zdb -l /dev/diskn" could also link GPT to /dev/diskn, sure, but it's complex and it even requires sudo. The manual also states that the output may change without notice and that some knowledge of the internal of ZFS is expected: the output is not obvious and, for example, the same /dev/diskn gets associated with multiple GPT values. zpool is better and easily passed to regexps.
Once I get the link between pools and /dev/diskn I can save some parameters with "diskutil info" and such. I haven't decided what to do with datasets yet.
If the partition is Apple_HFS then I can simply use diskutil.

Something I yet don't know is how to exclude external USB flash drives. In my experience they don't support SMART and that could be a solution, as written above, especially because I care about tracking hardware parameters and link them to usage: the same script will track all temperatures and fan speeds.

Do you have suggestions or additional ideas? For the time being, thanks for the time you dedicated to the topic.
si-ghan-bi Offline


 
Posts: 145
Joined: Sat Sep 15, 2012 5:55 am

Re: Link GPT ids to hardware devices

Post by grahamperrin » Tue Nov 13, 2012 9:35 pm

Back to the opening post. With just a little more detail, this could be a good question for Super User. (Commonly used tags there include command-line and script.)

si-ghan-bi wrote:… I would like to write a script that saves periodically HDD values like temperature, free space, etc and some ZFS parameters to a sqlite3 db. …


Are the values to include the disk of the HFS Plus startup volume, which in most cases should not have a ZFS slice?
grahamperrin Offline

User avatar
 
Posts: 1596
Joined: Fri Sep 14, 2012 10:21 pm
Location: Brighton and Hove, United Kingdom

Re: Link GPT ids to hardware devices

Post by si-ghan-bi » Wed Nov 14, 2012 5:00 am

grahamperrin wrote:Are the values to include the disk of the HFS Plus startup volume, which in most cases should not have a ZFS slice?


Yes, of course: if I perform monitoring, I do it for as many devices as I can, few bytes more in a sqlite3 DB won't slow things down.
Moreover, the boot disk is an internal SSD and it may be interesting to check in the future how the wear leveling and other parameters change in time. It's a couple of months old and I have "wear leveling count" = 6 already.
Moreover, the disk I use for Time machine is also HFS (it's the external one that doesn't support SMARTI). This disk is HFS+ because I also want to boot from it (ensured by an additional CCC clone on it).

Concerning Superuser, I haven't thought about it, but even if I did, I wouldn't know where exactly: there are too many websites in the Stack Exchange network. Super User? Stack Overflow? Unix and linux? Server fault?
si-ghan-bi Offline


 
Posts: 145
Joined: Sat Sep 15, 2012 5:55 am

Super User, I reckon

Post by grahamperrin » Wed Nov 14, 2012 5:41 am

For this, I think Super User is a good fit. Don't worry too much about placement. If it's later thought that good answers will be more likely in a different part of the network, the move will occur naturally and without breakage to links etc.. If you do post a question in Stack Exchange, add cross-links (from here to there and vice versa) and I'll follow with interest.
grahamperrin Offline

User avatar
 
Posts: 1596
Joined: Fri Sep 14, 2012 10:21 pm
Location: Brighton and Hove, United Kingdom

Re: Link GPT ids to hardware devices

Post by dbrady » Wed Nov 14, 2012 8:10 am

si-ghan-bi wrote:However, I need to relate /dev/diskn to GPT ids used by ZEVO. Is there a command that gives me the GPT id of a disk device?


This works to get a GPT path given the generic /dev/diskNsn path (in bash):

$ sudo zdb -l /dev/disk1s2 | grep "path:" | uniq
path: '/dev/dsk/GPTE_2A5DE9F2-F0FD-4B80-A0D9-76BF6796DB47'


where disk1s2 is a ZFS vdev in this case.
dbrady Offline


 
Posts: 67
Joined: Wed Sep 12, 2012 12:43 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron