udev rules exclude device

4

1

is it possible to use udev rules to excluce a single device from the rule?

for instance if I have 5 harddisk plugged in and I want to create custom names for all harddisk except for a single one? is it Possible?

Also, kernel names disks after sdz are named with 2 characters. sdaa,sdab, sdqr etc. I have a problem with it since I dont want to include the partition in sda1, sdb2 etc. can I wildcard all characters but not all numbers?

example:

KERNEL=="sd??",  NAME="test/Disk%n",  ATTRS{ID_SERIAL_SHORT}!="xxxx"

John Smith

Posted 2014-03-23T13:00:06.473

Reputation: 185

Answers

3

for instance if I have 5 harddisk plugged in and I want to create custom names for all harddisk except for a single one? is it Possible?

  • You can use GOTO to skip rules:

    ENV{ID_SERIAL_SHORT}=="xxxx|yyyy|zzzz", GOTO="custom_names_end"
    ENV{ID_MODEL}=="blahblah", GOTO="custom_names_end"
    
    KERNEL=="sd*", ENV{DEVTYPE}=="disk", SYMLINK+="test/Disk%n"
    
    LABEL="custom_names_end"
    
  • Note that ID_SERIAL_SHORT is not an attribute; it's an udev "environment" variable, so you need to use ENV{} or ENVS{} to match it. Attributes are read from sysfs directly.

  • Also note that recent udev versions forbid renaming devices; you can only add custom symlinks.

Also, kernel names disks after sdz are named with 2 characters. sdaa,sdab, sdqr etc. I have a problem with it since I dont want to include the partition in sda1, sdb2 etc. can I wildcard all characters but not all numbers?

  • You're using the wrong approach. If you want to match disks but not partitions, then do exactly that:

    KERNEL=="sd*", ENV{DEVTYPE}=="disk", …

    The DEVTYPE values can be seen in udevadm info /dev/sda and udevadm info /dev/sda1.

user1686

Posted 2014-03-23T13:00:06.473

Reputation: 283 655

Thank you very much! It triggers, but only on the first disk it finds. so I only have a single symlink in /dev/test Also is it possible to use numbering as the last digit? so the first device it finds is Disk0 then Disk1 etc? – John Smith – 2014-03-23T14:10:35.007

@prgmjunkie: Try manually running it on other devices using udevadm test or udevadm trigger. – user1686 – 2014-03-23T14:11:37.793

it trigger but the %n operator in the symlink declaration seems to not work correctly the device symlink is always called Disk with nothing appended. – John Smith – 2014-03-23T14:15:52.213

If I use %k instead of %n it works. – John Smith – 2014-03-23T14:20:16.510

It could be that udev just doesn't know how to assign numbers to sd* devices... (Personally I think %n is quite useless anyway, as device order is unstable. Better use UUIDs like in /dev/disk/by-uuid/…) – user1686 – 2014-03-23T14:32:09.643