Skip to content

Commit 24e1540

Browse files
committed
Add udev rules for Linux sysfs power switching to README.md
The udev rules for the sysfs case are a bit more complex than those for the libusb based interface, as udev has built-in support for changing permissions on device files but not for sysfs attributes. Instead we have to use chmod / chown to set permissions and owners. You may notice the " || true" parts in the RUN part of the rules in addition to the -f parameters. These are there to make sure that no error is logged by udev even if the disable attribute does not exist. chmod/chown still return an error exit code even with -f if the requested path does not exist. " || true" makes sure this error is not propagated to udev. Signed-off-by: Leonard Göhrs <[email protected]>
1 parent aa7fc0a commit 24e1540

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,21 @@ Linux USB permissions
212212
=====================
213213

214214
On Linux, you should configure `udev` USB permissions (otherwise you will have to run it as root using `sudo uhubctl`).
215+
216+
Starting with Linux Kernel 6.0 there is a standard interface to turn USB hub ports on or off,
217+
and `uhubctl` will try to use it (instead of `libusb`) to set the port status.
218+
This is why there are additional rules for 6.0+ kernels.
219+
There is no harm in having these rules on systems running older kernel versions.
220+
215221
To fix USB permissions, first run `sudo uhubctl` and note all `vid:pid` for hubs you need to control.
216222
Then, add one or more udev rules like below to file `/etc/udev/rules.d/52-usb.rules` (replace 2001 with your vendor id):
217223

218224
SUBSYSTEM=="usb", ATTR{idVendor}=="2001", MODE="0666"
219225

226+
# Linux 6.0 or later (its ok to have this block present in older Linux):
227+
SUBSYSTEM=="usb", DRIVER=="hub", \
228+
RUN="/bin/sh -c \"chmod -f 666 $sys$devpath/*-port*/disable || true\""
229+
220230
Note that for USB3 hubs, some hubs use different vendor ID for USB2 vs USB3 components of the same chip,
221231
and both need permissions to make uhubctl work properly. E.g. for Raspberry Pi 4B, you need to add these 2 lines:
222232

@@ -227,6 +237,11 @@ If you don't like wide open mode `0666`, you can restrict access by group like t
227237

228238
SUBSYSTEM=="usb", ATTR{idVendor}=="2001", MODE="0664", GROUP="dialout"
229239

240+
# Linux 6.0 or later (its ok to have this block present in older Linux):
241+
SUBSYSTEM=="usb", DRIVER=="hub", \
242+
RUN+="/bin/sh -c \"chown -f root:dialout $sys$devpath/*-port*/disable || true\"" \
243+
RUN+="/bin/sh -c \"chmod -f 660 $sys$devpath/*-port*/disable || true\""
244+
230245
and then add permitted users to `dialout` group:
231246

232247
sudo usermod -a -G dialout $USER

0 commit comments

Comments
 (0)