[NCLUG] Help w/udev rules

Maxwell Spangler maxlists at maxwellspangler.com
Mon Oct 7 21:21:40 MDT 2013


On Tue, 2013-09-24 at 00:21 -0600, Maxwell Spangler wrote:

> On a backup server I have two external USB docks.  I'm writing scripts
> so a user can install new offsite backup drives and tell the computer to
> make them available to receive backups.  Another script will copy the
> appropriate backup files to the drives.  For the backup script to work
> consistently, I want to present the removable storage in a predictable
> manner.


This turned out to be pretty easy to do.  I made two rules for each dock
and placed them in /etc/udev/rules.d/89-usb-dock.rules.

The first rule matches the USB3 dock as a whole block device, such
as /dev/sdg, when it is powered on.  The rule sets up the symlink
between /dev/sdg and /dev/usb3dock nicely, but it doesn't discover
partitions.  So I wrote a wrapper script called dockprobe which did a
lot of debugging to let me learn and trust the process but essentially
just called partprobe on the main device.  The second rule triggers on
this dock's partitions only and simply makes symlinks.

So, turn the dock on and the kernel sets up /dev/sdh and
partitions /dev/sdh1 and /dev/sdh2.
My two rules setup /dev/usb3dock, /dev/usb3dockp1 and /dev/usb3dockp2.

Goal accomplished, my scripts just look for /dev/usb3dock etc.. 

[maxwell at elite offsite-files]$ l /dev/sdh* /dev/usb3*
brw-rw----. 1 root disk 8, 112 Oct  7 21:17 /dev/sdh
brw-rw----. 1 root disk 8, 113 Oct  7 21:17 /dev/sdh1
brw-rw----. 1 root disk 8, 114 Oct  7 21:17 /dev/sdh2
lrwxrwxrwx. 1 root root      3 Oct  7 21:17 /dev/usb3dock -> sdh
lrwxrwxrwx. 1 root root      4 Oct  7 21:17 /dev/usb3dockp1 -> sdh1
lrwxrwxrwx. 1 root root      4 Oct  7 21:17 /dev/usb3dockp2 -> sdh2


# USB3 dock, whole storage device.
KERNEL=="sd*[!0-9]", SUBSYSTEMS=="usb", \
  ATTRS{product}=="MassStorage Device", \
  ATTRS{idVendor}=="1759", \
  ATTRS{idProduct}=="5100", \
  SYMLINK+="usb3dock%n", \
  RUN="/sbin/partprobe $kernel"
  #RUN="/etc/dockprobe usb3dock device $kernel $number"

# USB3 dock, individual partitions
KERNEL=="sd*[0-9]", SUBSYSTEMS=="usb", \
  ATTRS{product}=="MassStorage Device", \
  ATTRS{idVendor}=="1759", \
  ATTRS{idProduct}=="5100", \
  SYMLINK+="usb3dockp%n", \
  # nor partprobe nor dockprobe are required for partitions
  #RUN="/etc/dockprobe usb3dock partition $kernel $number"


-- 
Maxwell Spangler
========================================================================
Linux System Administration / Virtualization / Development / Computing
Services
Photography / Graphics Design / Writing
Fort Collins, Colorado
http://www.maxwellspangler.com


More information about the NCLUG mailing list