You are not logged in.

#1 2014-05-03 12:35:42

Ploppz
Member
Registered: 2013-09-14
Posts: 311

udev rules don't work

I am on my laptop, where I am trying to write some udev rules.

Firstly, as a test I tried to make a symlink when connecting my ext hd.

$ udevadm info /dev/sdb

[...]
E: ID_PART_TABLE_UUID=ea04843c-526e-45bf-9d45-beba1b180285
[...]

$ cat /etc/udev/rules.d/61-rules.rules

ENV{ID_PART_TABLE}=="ea04843c-526e-45bf-9d45-beba1b180285" NAME="lilalum"

And well, nothing happens (there is no lilalum in /dev) when I plug in my ext hd.

Secondly, my low bat rule doesn't work.

$ cat /etc/udev/rules.d/99-lowbat.rules

SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="10", RUN+="/usr/bin/systemctl suspend"
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="9", RUN+="/usr/bin/systemctl suspend"
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="8", RUN+="/usr/bin/systemctl suspend"

It just doesn't do anything when the battery gets that low, and no the battery did not skip both 10, 9 and 8 percent.

Last edited by Ploppz (2014-05-03 12:41:02)

Offline

#2 2014-05-03 13:37:43

ukhippo
Member
From: Non-paged pool
Registered: 2014-02-21
Posts: 366

Re: udev rules don't work

To create a symlink you use SYMLINK="...", not NAME. You're trying to set the name of the device which is only allowed for network interfaces.

Can't help with your battery problem, but a search of this forum indicates that battery charge changes don't send events, so your better off using a cron job to periodically check.

Offline

#3 2014-05-03 13:50:09

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,771
Website

Re: udev rules don't work

Ploppz wrote:

Secondly, my low bat rule doesn't work.

$ cat /etc/udev/rules.d/99-lowbat.rules

SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="10", RUN+="/usr/bin/systemctl suspend"
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="9", RUN+="/usr/bin/systemctl suspend"
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="8", RUN+="/usr/bin/systemctl suspend"

It just doesn't do anything when the battery gets that low, and no the battery did not skip both 10, 9 and 8 percent.

The udev rule described in the wiki only has an effect when there is a change in the battery state --- if you have the laptop plugged in when its at 8, 9 or 10%, then unplug it the laptop will suspend...
Basically, its useless wink

Offline

#4 2014-05-03 16:15:44

Ploppz
Member
Registered: 2013-09-14
Posts: 311

Re: udev rules don't work

ukhippo wrote:

To create a symlink you use SYMLINK="...", not NAME. You're trying to set the name of the device which is only allowed for network interfaces.

Ah.. I used SYMLINK+= (isn't it '+=' instead of '='?) earlier and supposedly just switched to NAME to test it (and forgot to switch back). But switching to SYMLINK now does not have any effect either - neither += or =.

$  udevadm test /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1.2/3-1.2:1.0/host7/target7:0:0/7:0:0:0/block/sdb
^ pretty much the same output with += as =.

Edit: Bonus question: does RUN+="" accept several commands, separated by ;?

Last edited by Ploppz (2014-05-03 16:22:05)

Offline

#5 2014-05-03 18:11:22

ukhippo
Member
From: Non-paged pool
Registered: 2014-02-21
Posts: 366

Re: udev rules don't work

Ploppz wrote:
ukhippo wrote:

To create a symlink you use SYMLINK="...", not NAME. You're trying to set the name of the device which is only allowed for network interfaces.

Ah.. I used SYMLINK+= (isn't it '+=' instead of '='?) earlier and supposedly just switched to NAME to test it (and forgot to switch back). But switching to SYMLINK now does not have any effect either - neither += or =.

$  udevadm test /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1.2/3-1.2:1.0/host7/target7:0:0/7:0:0:0/block/sdb
^ pretty much the same output with += as =.

You're right it should be +=
I guess the “ENV{ID_PART_TABLE}” in your post instead of “ENV{ID_PART_TABLE_UUID}” is another typo, and the *_UUID doesn't work?
Since you're in the add action, the environment may not have all those set up yet. Try rewriting your rule using ATTRSs instead. Use the “-a” switch to see them:

udevadm info -a /dev/sdb

You can only use the attributes from one of the parents in addition to the attributes of the device. I suggest using some attributes from the parent that includes “ATTRS{serial}” as those are more likely to uniquely identify the device.
You may also want to use KERNEL=="sd?" as part of your rule so that it doesn't overwrite the symlink to point to the last partition on the disk. Unless you do want it to point to the first partition, in which case use KERNEL=="sd?1".
Additionally, you might also want to limit the rule to ACTION=="add".

As for your bonus Q, I don't think that works. You could of course have multiple RUN+="...", or just put all the commands into a script.

Last edited by ukhippo (2014-05-03 18:23:19)

Offline

#6 2014-05-03 19:09:36

Ploppz
Member
Registered: 2013-09-14
Posts: 311

Re: udev rules don't work

That's weird, I'm sure I fixed both those errors yesterday.. But okay, I tried this:
$ cat 61-rules.rules

KERNEL=="sd?" ATTRS{serial}=="00000000155facd03099" SYMLINK+="lilalum"

It did not work, then I tried this:

KERNEL=="sdb" SYMLINK+="lilalum"

And that did not work either. (ls /dev)

Offline

#7 2014-05-03 19:44:36

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: udev rules don't work

Head_on_a_Stick wrote:
Ploppz wrote:

Secondly, my low bat rule doesn't work.

$ cat /etc/udev/rules.d/99-lowbat.rules

SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="10", RUN+="/usr/bin/systemctl suspend"
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="9", RUN+="/usr/bin/systemctl suspend"
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="8", RUN+="/usr/bin/systemctl suspend"

It just doesn't do anything when the battery gets that low, and no the battery did not skip both 10, 9 and 8 percent.

The udev rule described in the wiki only has an effect when there is a change in the battery state --- if you have the laptop plugged in when its at 8, 9 or 10%, then unplug it the laptop will suspend...
Basically, its useless wink

I cannot confirm this. For me the laptop suspends even without (un)plugging the laptop. However, this rule does not work for every laptop. Not all laptops send acpi signals on discharge.

Offline

#8 2014-05-03 21:36:15

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: udev rules don't work

Ploppz, your rules are missing *commas*.

Offline

#9 2014-05-06 18:12:09

Ploppz
Member
Registered: 2013-09-14
Posts: 311

Re: udev rules don't work

Ah... thanks, it works now!

One more small issue... I tried writing a test to detect when the charger of my laptop gets plugged in or out, I put it in 61-rules.rules

SUBSYSTEM=="power_supply", RUN+="/usr/bin/touch /home/ploppz/charger"

The battery does send signals to udev:

$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

# Plugging out:
KERNEL[944.333548] change   /devices/platform/ACPI0003:00/power_supply/AC (power_supply)
UDEV  [944.340228] change   /devices/platform/ACPI0003:00/power_supply/AC (power_supply)
KERNEL[944.426599] change   /devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV  [944.428599] change   /devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
KERNEL[944.470830] change   /devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV  [944.472781] change   /devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
# Plugging in:
KERNEL[950.317263] change   /devices/platform/ACPI0003:00/power_supply/AC (power_supply)
KERNEL[950.331752] change   /devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV  [950.332023] change   /devices/platform/ACPI0003:00/power_supply/AC (power_supply)
KERNEL[950.332576] change   /devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV  [950.333609] change   /devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV  [950.334891] change   /devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0 (power_supply)

I also tried putting it in 99-lowbat.rules, stilll no luck. I'm also wondering whether udev reads all the rules every time an event happens, or if it caches them such that when I write a rule, I'll have to either wait a bit or do some action to update the rules cache?

Offline

#10 2014-05-06 18:29:09

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: udev rules don't work

To reload rules:

udevadm control --reload

Offline

#11 2014-05-06 18:39:48

Ploppz
Member
Registered: 2013-09-14
Posts: 311

Re: udev rules don't work

Still doesn't work. It's normal to put different rules into the same file, right? The file looks like this:

# Ext lilalum
KERNEL=="sd?", ATTRS{serial}=="00000000155facd03099", SYMLINK+="lilalum"

# Backlight
SUBSYSTEM=="backlight", ACTION=="add", KERNEL=="acpi_video0", ATTR{brightness}="1"

# Send information if charger state changes
SUBSYSTEM=="power_supply", RUN+="/usr/bin/touch /home/ploppz/charger"

Offline

#12 2014-05-07 05:13:31

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: udev rules don't work

@Ploppz

I would put the rules into separate files if they treat different devices as shown in your case.

Offline

Board footer

Powered by FluxBB