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

Christian Franke Christian.Franke at t-online.de
Tue Dec 4 22:02:48 CET 2018


Christian Franke wrote:
> Nathan Stratton Treadway wrote:
>> On Sun, Nov 04, 2018 at 19:51:32 +0100, Christian Franke wrote:
>>> 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/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.

Done in r4847. New scanning could selected with '-d by-id' on Linux. If 
possible, please test:

# smartctl --scan -d by-id

Some debug output could be enabled with '-r ioctl'.

With "DEVICESCAN -d by-id", smartd should no longer behave strange if 
the device behind some /dev/sdX has changed. The old /dev/disk/by-id 
symlink should no longer exist or point to a new /dev/sdY.

Thanks,
Christian




More information about the Smartmontools-support mailing list