[smartmontools-support] using smartd to monitor a rotating group of USB drives?

Christian Franke Christian.Franke at t-online.de
Tue Nov 6 22:11:08 CET 2018


Nathan Stratton Treadway wrote:
> On Sun, Nov 04, 2018 at 19:51:32 +0100, Christian Franke wrote:
>> For Linux only, the following less complex enhancement for
>> DEVICESCAN may also work:
>> Add all /dev/disk/by-id/* entries which are symlinks to some
>> /dev/sdX to the scan result. Then add the remaining /dev/sdX to the
>> result.
>>
>> This small script demonstrates the idea:
>> --------------------
>> #!/bin/sh
>>
>> {
>>    ls -dl /dev/disk/by-id/* 2>/dev/null | \
>>     sed -n 's,^.* \(/d[^ ]*\) -> \.\./\.\./\(sd[a-z][a-z]*\)$,\1
>> /dev/\2,p' \
>>    && ls -d /dev/sd[a-z] /dev/sd[a-z][a-z] 2>/dev/null
>> } | awk '
>>    NF == 2 {print $1; used[$2] = 1; next}
>>    !used[$1] {print $1}
>> '
>> --------------------
>> If possible, please test whether the group of USB drives appear as
>> unique symlinks in /dev/disk/by-id.
> Yes, in this case they do... though these particular drives the
> ../by-id/ name is based on the USB bridge and not the drive identifiers.
> (This is under Linux 4.15.0-36-generic x86_64 as found in Ubuntu Bionic.)
>
> I saved the your script to "device_symlink_lists.sh", then ran the
> following command to show both the output of the script and also the
> /dev/ name the links point to:
>
> ====
> root at tumhalad:~/external_usb_drives# for DEV in $(./device_symlink_lists.sh ) ; do echo -n "$DEV -> ";  readlink -f $DEV; done
> /dev/disk/by-id/ata-MB0500GCEHE_WMAYP0H8TMAM -> /dev/sda
> /dev/disk/by-id/ata-MB0500GCEHE_WMAYP0K0W6SM -> /dev/sdc
> /dev/disk/by-id/ata-MB4000GCWLV_P4HLMDTC -> /dev/sdb
> /dev/disk/by-id/ata-MB4000GCWLV_P4HMV9GB -> /dev/sdd
> /dev/disk/by-id/ata-TOSHIBA_MK5059GSX_Z95LF13BS -> /dev/sde
> /dev/disk/by-id/usb-WD_My_Passport_0740_5758423145413146454A4C38-0:0 -> /dev/sdf
> /dev/disk/by-id/usb-WD_My_Passport_0740_575844314539314C464E5737-0:0 -> /dev/sdi
> /dev/disk/by-id/wwn-0x50000392371814b8 -> /dev/sde
> /dev/disk/by-id/wwn-0x5000cca249d68f0e -> /dev/sdb
> /dev/disk/by-id/wwn-0x5000cca249d71d4d -> /dev/sdd
> /dev/disk/by-id/wwn-0x50014ee0041783d7 -> /dev/sda
> /dev/disk/by-id/wwn-0x50014ee05981908d -> /dev/sdc
> ====
>
> So in this case the MB* links, sda through sdd, reference the internal
> SATA-controler-attached drives, sde/TOSHIBA is a random USB drive
> currently plugged in, and the two usb-WD drives are part of the rotating
> group.  (As long as the Toshiba drive is plugged in, the rotating
> up-to-four drives on that 4-port USB hub end up using sdf-sdi.)

Then (with an additional check for duplicate links), the proposed 
heuristics should work to detect whether a new device appears behind 
/dev/sdX.

I possibly will add a modified device scanning for next release.


> There aren't any /dev/sd* devices that are missing symlinks in the
> /dev/disk/by-id/ directory.

These apparently only appear for devices without serial number, e.g. 
some virtual disks.


> I'm not sure off hand why the Toshiba drive maps based on the disk
> itself while the WD drives map based on the USB bridge... but obviously
> the drives that map based on the disk get both a Model/SSN link and a
> WWN link, while USB mapped-drives have only one link.

Does this possibly correlate with different transfer modes (USB vs. UAS) ?

Thanks,
Christian




More information about the Smartmontools-support mailing list