Last active
September 1, 2022 22:39
-
-
Save melissaboiko/960a4e3d6dc03c2632ab7ecd9c69a727 to your computer and use it in GitHub Desktop.
udev rules to create symlinks for specific hard drives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/sh -c 'test -d /dev/hdd || mkdir /dev/hdd'" | |
# some notes: | |
# - you can't use SUBSYSTEM="usb" or you'll symlink to the parent devices (usb bus, hub...) | |
# - otoh, if you symlink only on serial number, you override the symlink when /dev/sd.[0-9] kick in | |
# - so you need both the SUBSYSTEM=="block", and the ENV{PARTN} | |
# - (PARTN seems more reliable than ATTR{MINOR}/$minor, because more subdevices pop up) | |
# - to grab a serial is supposed to be: udevadm info -a /dev/sdb | grep 'ATTRS{serial}' | head -n 1 | |
# - this hasn't really been working for us; the serial returned isn't always what I get | |
# - but this is the same as ENV{ID_SERIAL_SHORT}: smartctl -i /dev/sdb | grep Serial | |
ACTION=="add", SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="BE1234567890", ENV{PARTN}=="", SYMLINK+="hdd/gdrive" | |
ACTION=="add", SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="BE1234567890", ENV{PARTN}!="", SYMLINK+="hdd/gdrive$env{PARTN}" | |
ACTION=="add", SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="7ACAB1312", ENV{PARTN}=="", SYMLINK+="hdd/toshiwhite" | |
ACTION=="add", SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="7ACAB1312", ENV{PARTN}!="", SYMLINK+="hdd/toshiwhite$env{PARTN}" | |
ACTION=="add", SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="0F1337BABE", ENV{PARTN}=="", SYMLINK+="hdd/toshiblack" | |
ACTION=="add", SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="0F1337BABE", ENV{PARTN}!="", SYMLINK+="hdd/toshiblack$env{PARTN}" | |
ACTION=="add", SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="575135461346432183132498", ENV{PARTN}=="", SYMLINK+="hdd/wdred" | |
ACTION=="add", SUBSYSTEM=="block", ENV{ID_SERIAL_SHORT}=="575135461346432183132498", ENV{PARTN}!="", SYMLINK+="hdd/wdred$env{PARTN}" | |
# uncomment to debug | |
# ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/sh -c '(echo ---; env) >> /tmp/udev.env.sh'" | |
# vim: ft=udevrules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment