Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

1 votes
0 answers
108 views
sysfs missing CPU thermal_throttle information
**Background Information:** I'm running Ubuntu 24.04.1 LTS (Noble Numbat, kernel 6.8.0-51-generic) on an AMD Ryzen 9 7950X3D, and I'm investigating some odd behavior where the CPU governor/driver will ***lower*** the CPU frequency when under full load. Using the `performance` governor and the `amd-p...
**Background Information:** I'm running Ubuntu 24.04.1 LTS (Noble Numbat, kernel 6.8.0-51-generic) on an AMD Ryzen 9 7950X3D, and I'm investigating some odd behavior where the CPU governor/driver will ***lower*** the CPU frequency when under full load. Using the performance governor and the amd-pstate driver, here's what I'm seeing: | Load | 15 min Load Avg | CPU Temp | CPU Frequency | | | ---- | :-------------- | -------- | ---------------: | -------- | | Idle | 1.12 | 40.8 C | 5,759,000,000 Hz | 5.76 GHz | | Full | 33.02 | 58.5 C | 4,827,047,000 Hz | 4.83 GHz | I'm fairly confident that 58.5C isn't hot enough to cause thermal throttling on the CPU, but I'd like to be sure so that I know how to direct my investigation: - If it's thermal throttling, I'll get a better cooling system. - If it's not thermal throttling, I'll keep looking into configuration options [This post](https://unix.stackexchange.com/questions/477088/cpu-thermal-throttle-counters?newreg=280449e8db7b4d9395891d3e0fe2fa4a) suggests that I should be able to see throttling information in /sys/devices/system/cpu/cpu*/thermal_throttle/, however the thermal_throttle directory is missing:
/sys/devices/system/cpu/cpu0 $ file *
acpi_cppc:        directory
cache:            directory
cpufreq:          symbolic link to ../cpufreq/policy0
cpuidle:          directory
crash_notes:      regular file, no read permission
crash_notes_size: regular file, no read permission
driver:           symbolic link to ../../../../bus/cpu/drivers/processor
firmware_node:    symbolic link to ../../../LNXSYSTM:00/LNXSYBUS:00/ACPI0010:00/ACPI0007:00
hotplug:          directory
microcode:        directory
node0:            symbolic link to ../../node/node0
power:            directory
subsystem:        symbolic link to ../../../../bus/cpu
topology:         directory
uevent:           ASCII text, with very long lines (1212)
**The Question:** Why is this missing from sysfs, and how can I get the CPU throttling information?
JimXugle (11 rep)
Jan 16, 2025, 11:24 PM • Last activity: Jun 16, 2025, 12:37 PM
1 votes
2 answers
3353 views
Permission denied on sysfs files
I'm messing around with my raspberry pi, and currently I'm trying to change the color of one of the LEDs on the board executing a shell script and its arguments: pi@raspberrypi:~/morpheus/scripts $ bash ./set-rgb-led.sh level 50 50 50 When inputting above command, I receive following: ./set-rgb-led....
I'm messing around with my raspberry pi, and currently I'm trying to change the color of one of the LEDs on the board executing a shell script and its arguments: pi@raspberrypi:~/morpheus/scripts $ bash ./set-rgb-led.sh level 50 50 50 When inputting above command, I receive following: ./set-rgb-led.sh: line 19: /sys/class/leds/morpheus:level:red/brightness: Permission denied ./set-rgb-led.sh: line 19: /sys/class/leds/morpheus:level:green/brightness: Permission denied ./set-rgb-led.sh: line 19: /sys/class/leds/morpheus:level:blue/brightness: Permission denied To check up on permissions I ran getfacl set-rgb-led.sh, which tells me following information: # file: set-rgb-led.sh # owner: pi # group: pi user::rwx group::--x other::--x I've tryed using the chmod +x command and alike permission changing commands, but I can't seem to gain proper access. What am I missing so I can gain control of the file?
Jon Dier (43 rep)
Mar 6, 2017, 10:57 AM • Last activity: Apr 26, 2025, 08:06 AM
2 votes
1 answers
2003 views
How to add LIRC to ir-keytable protocols?
I'm trying to issue a bash command on infrared remote control button presses. The IR receiver device is an usb device included in the Anysee e30 Combo plus DVB-T tuner, which works perfectly, otherwise. The output of the ir-keytable output: Found /sys/class/rc/rc0/ (/dev/input/event0) with: Driver d...
I'm trying to issue a bash command on infrared remote control button presses. The IR receiver device is an usb device included in the Anysee e30 Combo plus DVB-T tuner, which works perfectly, otherwise. The output of the ir-keytable output: Found /sys/class/rc/rc0/ (/dev/input/event0) with: Driver dvb_usb_anysee, table rc-anysee Supported protocols: NEC Enabled protocols: Name: Anysee bus: 3, vendor/product: 1c73:861f, version: 0x0100 Repeat delay = 500 ms, repeat period = 125 ms When I run ir-keytable -t to test whether the button presses are received, this works and I see scan codes and button labels(KEY_UP etc) showing up. To make a button press fire a bash conmmand, I think my only option is to use LIRC's irexec command. In installed lirc and configured it, then ran irw which is lirc's testing command. No output whatsoever. I checked that lircd is running and that irw can connect to the daemon. Note that LIRC is not under supported protocols of the ir-keytable command. Does this mean I can't use the hardware for this purpose? root@raspberrypi:/home/pi# modprobe ir-lirc-codec root@raspberrypi:/home/pi# ir-keytable -c -p NEC,LIRC Old keytable cleared /sys/class/rc/rc0//protocols: Invalid argument Couldn't change the IR protocols I saw on a few websites that people do this to add lirc as a protocol. I am not surprised this failed for me though, it would be odd that you could add an unsupported protocol by simply echoing it's name to a file. root@raspberrypi:/home/pi# echo lirc > /sys/class/rc/rc0/protocols bash: echo: write error: Invalid argument I am using a Raspberry Pi v2 as system (Debian Wheezy)
Nino van Hooff (169 rep)
Sep 6, 2015, 08:40 AM • Last activity: Apr 22, 2025, 08:03 AM
1 votes
1 answers
57 views
Disconnected block device remains in /sys, is not seen as detected when re-connect
System is Linux Mint 21 based. My USBstick was receiving some files and after message "Do not disconnect" had disappeared I unplugged it. This time though waiting whirl remained in Disks GUI and it remained seen in Nemo. I've tried some naive methods like `rm /dev/sdb` which did not help. Then I not...
System is Linux Mint 21 based. My USBstick was receiving some files and after message "Do not disconnect" had disappeared I unplugged it. This time though waiting whirl remained in Disks GUI and it remained seen in Nemo. I've tried some naive methods like rm /dev/sdb which did not help. Then I noted when I plug it into USB again, nothing seems to happen. Then I've tried web search and found 1) https://www.reddit.com/r/linuxquestions/comments/vxn53j/how_to_undelete_a_device_file_for_example_devsr0/ And done mknod /dev/sdb b 11 0 mknod /dev/sdb1 b 11 0 echo remove | sudo tee /sys/block/sdb/uevent echo add | sudo tee /sys/block/sdb/uevent echo remove | sudo tee /sys/block/sdb1/uevent echo add | sudo tee /sys/block/sdb1/uevent The result of the above (or just some timeouts), the device no longer seen neither in Disks nor Nemo. But lsblk shows sdb and other web results do not help: https://unix.stackexchange.com/questions/405249/disconnected-block-device-remains-in-dev-sync-commands-unkillable : echo 1 | sudo tee /sys/block/sdb/device/delete > tee: /sys/block/sdb/device/delete: Permission denied ll /sys/block/sdb/device/delete ls: cannot access '/sys/block/sdb/device/delete': No such file or directory journalctl does not add relevant entries (only cron) when I plug-unplug the device, there are entries in /sys, e.g. /sys/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host1/target1:0:0/1:0:0:0/block/sdb. What more can I try to get the USBstick working (checked it works in another PC) not to restart the PC? TIA Edit: Before trying out answers: Problematic USBstick and another one do not work in the USB port where the problem appeared. When plugged in another port, Disks GUI does not show them, but lsblk had shown additional sdc, udisksctl mount resulted in Error looking up object for device /dev/sdc1, but sudo mount /dev/sdd1 has worked and the stick can be read and written to. Edit 2 After trying following through the answer by @telcoM: deleting /dev/sdb(1) and re-plugging the stick, then re-creating them mknod with different numbers from the answer: Nothing seems to have changed. Edit 3 I've noted PC wouldn't suspend (maybe because sync hanged up - I run it to physically write all to manually mounted USB stick), then I've lost USB keyboard/mouse connection (connection is loose via a hub and they did not reconnect even in another USB port), so some time later I've restarted the computer. Still proper answer is welcome in case of future similar problems.
Martian2020 (1443 rep)
Mar 30, 2025, 02:01 PM • Last activity: Mar 31, 2025, 04:27 AM
0 votes
1 answers
28 views
Distinguish between configs and logs/debugs/statistics within sysfs (/sys)
> sysfs is a feature of the Linux kernel that allows kernel code to > export information to user processes via an in-memory filesystem. The > organization of the filesystem directory hierarchy is strict, and > based the internal organization of kernel data structures. The files > that are created in...
> sysfs is a feature of the Linux kernel that allows kernel code to > export information to user processes via an in-memory filesystem. The > organization of the filesystem directory hierarchy is strict, and > based the internal organization of kernel data structures. The files > that are created in the filesystem are (mostly) ASCII files with > (usually) one value per file Is there a way in which I can differentiate between modifiable configs and logs/debugs/statistics/infos within the /sys filesystem? Use case is to build a profiling tool which can identify the runtime configurations of a system. Could it be that read-only files correspond to logs/debugs/statistics/information and read-write files are tunable parameters always? For example: /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor is relevant for profiling as it indicates the value of CPU frequency scaling governor and is modifiable. However, /sys/devices/system/cpu/cpu0/topology/core_cpus is just the internal kernel map of CPUs within the same core and is unmodifiable.
Kenzo (3 rep)
Mar 20, 2025, 11:27 AM • Last activity: Mar 20, 2025, 11:55 AM
5 votes
4 answers
4126 views
How to attach a listener to sysfs files?
How to watch for `sysfs` file changes (like `/sys/class/net/eth0/statistics/operstate`) and execute a command on content change? - `inotify` does not work on `sysfs` - I don't want to poll. I want to set a listener with a callback routine once
How to watch for sysfs file changes (like /sys/class/net/eth0/statistics/operstate) and execute a command on content change? - inotify does not work on sysfs - I don't want to poll. I want to set a listener with a callback routine once
Zeta.Investigator (1190 rep)
Jul 2, 2021, 01:10 PM • Last activity: Mar 14, 2025, 12:16 PM
0 votes
0 answers
144 views
How to re-enable a USB port after disabling it in sysfs?
I have disabled a USB (2.0) port on a production Linux system with this command: ``` echo 1 > /sys/bus/usb/devices/usb2/2-1/2-1.8/port/disable ``` It successfully disabled the 8th USB port on hub #1. Devices plugged in this port are no longer enumerated. But now, I want to re-enable it (without rese...
I have disabled a USB (2.0) port on a production Linux system with this command:
echo 1 > /sys/bus/usb/devices/usb2/2-1/2-1.8/port/disable
It successfully disabled the 8th USB port on hub #1. Devices plugged in this port are no longer enumerated. But now, I want to re-enable it (without resetting the controller or rebooting the system). I could not find the solution in documentation for the kernel. The folder 2-1.8 is gone, and also command echo "2-1.8" > /sys/bus/usb/devices/usb2/2-1/subsystem/drivers/usb/bind fails with No such device error.
How can I re-enable it?
melonfsck - she her (150 rep)
Jan 19, 2025, 10:05 AM
12 votes
4 answers
19755 views
How to find out easily whether a block device (or a part of it) is mounted somehow
I want to know what the easiest way is to determine (without root privilege) whether a block device (say `sdb`) or any part of it is mounted (and which part of it). Checking `/proc/mounts` for sdb is not enough because `sdb` or one of its partitions may be used by LVM. You can check `/sys/block/sdb/...
I want to know what the easiest way is to determine (without root privilege) whether a block device (say sdb) or any part of it is mounted (and which part of it). Checking /proc/mounts for sdb is not enough because sdb or one of its partitions may be used by LVM. You can check /sys/block/sdb/sdb*/holders/ but you get dm-x entries which have to be resolved to /dev/mapper names in order to check /proc/mounts. Possible but if there is an easier solution... (which should not require root privilege)
Hauke Laging (93688 rep)
Jan 31, 2014, 01:40 AM • Last activity: Jan 13, 2025, 09:22 PM
1 votes
1 answers
232 views
Udev rule for syfs class/device attribute ownership
This was originally asked on [Stack Overflow](https://stackoverflow.com/questions/79329706/udev-rule-for-syfs-class-device-attributes), but it was closed for being off-topic. Hopefully this is the right forum for the question. I'm writing a character device driver that exposes class and device attri...
This was originally asked on [Stack Overflow](https://stackoverflow.com/questions/79329706/udev-rule-for-syfs-class-device-attributes) , but it was closed for being off-topic. Hopefully this is the right forum for the question. I'm writing a character device driver that exposes class and device attributes under sysfs. I'm using udev to make the devices that appear in /dev read/writable by a certain group, but I can't figure out how to make the sysfs attributes writable by the same group without a shell script.
$ ls -l /dev/foobar
crw-rw---- 1 root my_group 241, 0 Jan  4 21:57 /dev/foobar # ownership applied by udev
$ ls -l /sys/class/my_class/wo_attribute
--w--w---- 1 root root 4096 Jan  4 22:02 wo_attribute # still in root group :/
$ ls -l /sys/class/my_class/my_device/rw_attribute
-rw-rw-r-- 1 root root 4096 Jan  4 22:13 rw_attribute # ditto
I've tried using udevadm info to match the KERNEL and SUBSYSTEM keys of the sysfs path to no effect. I've also found the udev_event and get_ownership fields of struct class; I haven't had luck with the former and the latter works for device attributes, but I have to hard code my_group's gid which is not ideal. Here's an example of trying to find the right match keys for the class:
$ udevadm info -a /sys/class/my_module
 looking at device '/class/my_class':
    KERNEL=="my_class"
    SUBSYSTEM=="subsystem"
    DRIVER==""
    ATTR{wo_attribute}=="(not readable)"

  looking at parent device '/class':
    KERNELS=="class"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{devcoredump/disabled}=="0"
    ATTRS{drm/version}=="drm 1.1.0 20060810"
    ATTRS{firmware/timeout}=="60"
    ATTRS{gpio/export}=="(not readable)"
    ATTRS{gpio/unexport}=="(not readable)"
    ATTRS{my_class/wo_attribute}=="(not readable)"
But the udev rule KERNEL=="my_class", GROUP="my_group" doesn't work. Does udev only work with devices under /dev, or is there a way to apply the rules to sysfs attributes?
olishmollie (13 rep)
Jan 7, 2025, 06:08 PM • Last activity: Jan 7, 2025, 07:51 PM
3 votes
1 answers
2218 views
is there any tool to show hierarchy of devices in Linux?
I want to see a tree-like structure of all devices in Linux. In Windows, I can use [Device Manager][1] with "show by connection". BSD systems report such data to [dmesg][2] in format "child at parent" and have utilities such as [`devinfo`][3], so it is easy to understand relations between devices. I...
I want to see a tree-like structure of all devices in Linux. In Windows, I can use Device Manager with "show by connection". BSD systems report such data to dmesg in format "child at parent" and have utilities such as devinfo , so it is easy to understand relations between devices. In Linux this information is stored in `/sys`, but its format is not user friendly. I can query each bus with `lspci, lsusb, lsscsi etc, but is there something I can use to recreate full device hierarchy? lshw` shows bus information but not devices.
user996142 (702 rep)
Feb 21, 2019, 10:54 PM • Last activity: Nov 26, 2024, 06:20 AM
0 votes
0 answers
185 views
ERROR in file_io_posix.cc, trying to locate scaling_cur_freq and scaling_max_freq and couldn't find it
I'm trying to execute a container based on Ubuntu 20.04 and some additional dependencies. It ended up in an error where the project (something external) is looking for files/programs, as shown below. Error message: [ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_fr...
I'm trying to execute a container based on Ubuntu 20.04 and some additional dependencies. It ended up in an error where the project (something external) is looking for files/programs, as shown below. Error message: [ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2) [ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2) I tried looking for the installation of these modules but couldn't find them anywhere. Can someone help me out here? This error will come once I start some of the proprietary Docker containers. I couldn't determine if this is from Docker or the Linux machine I'm working on. I tried looking in other places on the stack overflow, but no solution was available.
V B (1 rep)
Oct 23, 2024, 04:04 AM • Last activity: Oct 23, 2024, 04:36 AM
1 votes
0 answers
88 views
How to run samples/rpmsg_client_sample in Linux?
I am learning RPMSG in Linux, and I found there is a `samples/rpmsg_client_sample.c`. I built it into a kernel module, but I don't know how to make its `probe` function to be called? And is there any other examples/demos on RPMSG in Linux for my reference?
I am learning RPMSG in Linux, and I found there is a samples/rpmsg_client_sample.c. I built it into a kernel module, but I don't know how to make its probe function to be called? And is there any other examples/demos on RPMSG in Linux for my reference?
wangt13 (631 rep)
Aug 19, 2024, 12:52 PM
0 votes
1 answers
150 views
Where to create symlinks to sysfs iio files
I wrote a driver that exposes I2C registers via an IIO device, this device operates in direct mode (read/write directly to files in sysfs), the files are correctly created in sysfs and work fine. I would like to expose these files in a user-friendly way, I was thinking of creating symlinks to the sy...
I wrote a driver that exposes I2C registers via an IIO device, this device operates in direct mode (read/write directly to files in sysfs), the files are correctly created in sysfs and work fine. I would like to expose these files in a user-friendly way, I was thinking of creating symlinks to the sysfs files with a udev rule so that instead of having to read /sys/bus/i2c/devices/5-0042/iio\:device1/in_pressure_raw the user can read from a file like /run/the_tank/pressure. What's the best place for such files? /dev? /run?
Pedru (101 rep)
Aug 6, 2024, 11:52 AM • Last activity: Aug 6, 2024, 12:47 PM
0 votes
0 answers
38 views
Replicating 'udisks power-off' behavior (without udisks)
`udisks` exists for regular users, root must (and is) able to live without it, I need help figuring out how. The goal is to do exactly what ``` udisks power-off /dev/sdX ``` does without `udisks`. `hdparm` is out of question, as it is assumed that UAS (https://linux-sunxi.org/USB/UAS) is in use and...
udisks exists for regular users, root must (and is) able to live without it, I need help figuring out how. The goal is to do exactly what
udisks power-off /dev/sdX
does without udisks. hdparm is out of question, as it is assumed that UAS (https://linux-sunxi.org/USB/UAS) is in use and ATA pass-through is broken, which is the case for many external drives (i.e. all Seagate enclosures, see https://www.smartmontools.org/wiki/SAT-with-UAS-Linux) . To physically stop the drive from spinning I have successfully employed
scsi_stop /dev/sdX
which is a part of the sg3-utils (Debian and derivatives) package. Then, to remove the drive from the system, I used
echo 1 > /sys/block/sdX/device/delete
These two steps do most of, but not all the work. The block device itself is removed and is not visible anymore, however, the drive is still visible as a USB device through lsusb, which is not the case with udisks power-off. So how do I finish it?
EmErAJID (26 rep)
Aug 1, 2024, 05:54 PM
0 votes
1 answers
194 views
where to enable /sys/fs/cgroup/memory/0/memory.usage_in_bytes?
I try to count total memory usage in linux via /sys/fs For this I've found /sys/fs/cgroup/memory/0/memory.usage_in_bytes in https://docs.kernel.org/admin-guide/cgroup-v1/memory.html#user-interface i've enabled CONFIG_CGROUPS and CONFIG_MEMCG options export CONFIG_MEMCG=true export CONFIG_CGROUPS=tru...
I try to count total memory usage in linux via /sys/fs For this I've found /sys/fs/cgroup/memory/0/memory.usage_in_bytes in https://docs.kernel.org/admin-guide/cgroup-v1/memory.html#user-interface i've enabled CONFIG_CGROUPS and CONFIG_MEMCG options export CONFIG_MEMCG=true export CONFIG_CGROUPS=true Prepared cgroups mount -t tmpfs none /sys/fs/cgroup mkdir /sys/fs/cgroup/memory mount -t cgroup none /sys/fs/cgroup/memory -o memory But doesn't see /sys/fs/cgroup/memory/0/memory.usage_in_bytes in files. Where to enable CONFIG_CGROUPS and CONFIG_MEMCG options to show /sys/fs/cgroup/memory/0/memory.usage_in_bytes? How to enable /sys/fs/cgroup/memory/0/memory.usage_in_bytes OS: Ubuntu 22.04.3 LTS - List item
Irina (139 rep)
Jul 15, 2024, 10:47 AM • Last activity: Jul 15, 2024, 11:51 AM
0 votes
1 answers
560 views
structure /sys/fs/cgroup/memory.stat
What is the structure of linux memory via /sys/fs/cgroup/memory.stat? what is the anon memory? What is the file memory? [![enter image description here][1]][1] how to get the full used memory via /sys/fs? [1]: https://i.sstatic.net/51XhjFaH.png
What is the structure of linux memory via /sys/fs/cgroup/memory.stat? what is the anon memory? What is the file memory? enter image description here how to get the full used memory via /sys/fs?
Irina (139 rep)
Jul 15, 2024, 06:23 AM • Last activity: Jul 15, 2024, 06:31 AM
1 votes
0 answers
247 views
Does udev have an issue with the 'hwmon' subsystem?
I have a temp/humidity sensor connected to the `i2c-0` interface on a Raspberry Pi: Rpi OS ver 'bookworm'. It works fine, and I can read sensor values from the files in `/sys/class/hwmon/hwmon2` (or equivalently in `/sys/bus/i2c/devices/0-0044/hwmon/hwmon2` or `/sys/devices/platform/soc/3f205000.i2c...
I have a temp/humidity sensor connected to the i2c-0 interface on a Raspberry Pi: Rpi OS ver 'bookworm'. It works fine, and I can read sensor values from the files in /sys/class/hwmon/hwmon2 (or equivalently in /sys/bus/i2c/devices/0-0044/hwmon/hwmon2 or /sys/devices/platform/soc/3f205000.i2c/i2c-0/0-0044/hwmon/hwmon2) using a bash script:
#!/usr/bin/bash
dev_folder='/sys/class/hwmon/hwmon2'
humid_r=$(To minimize the risk of breaking users of sysfs, which are in most cases low-level userspace applications, with a new kernel release, the users of sysfs must follow some rules to use an as-abstract-as-possible way to access this filesystem. The current udev and HAL programs already implement this and users are encouraged to plug, if possible, into the abstractions these programs provide instead of accessing sysfs directly.

I take this to mean that instead of accessing the sensor data directly from sysfs - as I'm currently doing in my bash script - I should be using udev.  

I've also read a bit on udev. *My current understanding of udev* is that **one way** udev might help me is to *"translate"* the **variable** sysfs folder name into a **fixed** one (or at least a fixed symlink). This is apparently done on the basis of .rule files that contain a series of *device attributes* used as *filters* (aka **match keys**), followed by a *command* (aka **assignment key**). The *device attributes* I used were selected from the [output of this command](https://pastebin.com/VGLxA5vp) :
bash udevadm info --attribute-walk --path=/sys/bus/i2c/devices/0-0044/hwmon/hwmon2
I created the following udev *rule file*:
# filename: /etc/udev/rules.d/80-local.rules ACTION=="add", SUBSYSTEM=="hwmon", ATTR{name}=="sht3x", KERNELS=="0-0044", SUBSYSTEMS=="i2c", NAME="sht30", SYMLINK+="i2c_sht3x"
This rule was derived from a variety of sources, and guesswork using a *trial-and-error* approach. The *filtering* part of the rule seems to work: I've tested the rule using a script to create a /tmp file. However, the NAME="sht30" and SYMLINK+="i2c_sht3x" fails to create a corresponding entry in my /dev folder as I expected (hoped) it would. 

I've also tried *variants* of this rule that attempted to create a symlink in sysfs; i.e. /sys/class/hwmon/hwmon_sht3x. But this didn't work either - it seems the symlinks are restricted to the /dev folder?? And I've looked at man udevadm for something I overlooked, but found nothing that helped me. 

Persistence often pays, and so I modified the above rule as follows:
# filename: /etc/udev/rules.d/80-local.rules ACTION=="add", SUBSYSTEM=="hwmon", ATTR{name}=="sht3x", KERNELS=="0-0044", SUBSYSTEMS=="i2c", RUN+="/bin/sh -c 'ln -s /sys$devpath /dev/hwmon_sht3x'" ``` And this rule actually works! (so far at least): It creates the symlink /dev/hwmon_sht3x to /sys/devices/platform/soc/3f205000.i2c/i2c-0/0-0044/hwmon/hwmon2 - **OR** to the folder currently assigned by the kernel. I've tested it several times by forcing a change to hwmonX, and it (so far) hasn't failed. So, the question is: #### Why will the matching rule not create the SYMLINK+="i2c_sht3x"?
Seamus (3772 rep)
Jun 6, 2024, 11:50 PM • Last activity: Jun 7, 2024, 05:43 PM
7 votes
1 answers
12177 views
Getting information from sysfs
I'm creating a script for polling information about network interfaces. For this I get some data from `/sysfs`. Everything went fine until I wanted to clarify all possible states of an interface (Which are they btw? I'm aware for now only about `up`, `down` and `unknown`). I went through `/usr/src/l...
I'm creating a script for polling information about network interfaces. For this I get some data from /sysfs. Everything went fine until I wanted to clarify all possible states of an interface (Which are they btw? I'm aware for now only about up, down and unknown). I went through /usr/src/linux/Documentation/sysfs-rules.txt and found this: > Accessing /sys/class/net/eth0/device is a bug in the application Is there a reason for this? Could someone explain me if I'm doing something wrong by getting information from /sysfs? I don't iterate through all interfaces in /sysfs but get all network interfaces with getifaddrs(3). Perhaps there is another method to get iface status? Thanks.
UVV (3128 rep)
Aug 14, 2014, 08:29 AM • Last activity: Jun 3, 2024, 06:35 AM
2 votes
1 answers
89 views
Why is this folder duplicated in `sysfs`?
I have a Raspberry Pi that is running the 'bookworm' version of the OS; the 64-bit version of the OS if that makes any difference. I've installed one of the SHT3X temperature & humidity sensors, and it is apparently working fine. It's connected via I2C interface (channel 0, `/dev/i2c-0` I believe)....
I have a Raspberry Pi that is running the 'bookworm' version of the OS; the 64-bit version of the OS if that makes any difference. I've installed one of the SHT3X temperature & humidity sensors, and it is apparently working fine. It's connected via I2C interface (channel 0, /dev/i2c-0 I believe). I can read temp & humidity from the files in sysfs; I believe the sensor is working correctly. I have found that there are two identical folders in sysfs that contain the same output and control files for the SHT3X device: ### folder 1: /sys/devices/platform/soc/3f205000.i2c/i2c-0/0-0044/hwmon/hwmon2
$ ls -l
total 0
lrwxrwxrwx 1 root root    0 Jun  2 21:55 device -> ../../../0-0044
-rw-r--r-- 1 root root 4096 Jun  2 21:55 heater_enable
-r--r--r-- 1 root root 4096 Jun  2 21:55 humidity1_alarm
-r--r--r-- 1 root root 4096 Jun  2 21:55 humidity1_input
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_max
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_max_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_min
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_min_hyst
-r--r--r-- 1 root root 4096 Jun  2 21:55 name
lrwxrwxrwx 1 root root    0 Jun  2 21:55 of_node -> ../../../../../../../../firmware/devicetree/base/soc/i2c@7e205000/sht3x@44
drwxr-xr-x 2 root root    0 Jun  2 21:55 power
-rw-r--r-- 1 root root 4096 Jun  2 21:55 repeatability
lrwxrwxrwx 1 root root    0 Jun  2 21:55 subsystem -> ../../../../../../../../class/hwmon
-r--r--r-- 1 root root 4096 Jun  2 21:55 temp1_alarm
-r--r--r-- 1 root root 4096 Jun  2 21:55 temp1_input
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_max
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_max_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_min
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_min_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:52 uevent
-rw-r--r-- 1 root root 4096 Jun  2 21:55 update_interval
### folder 2: /sys/class/hwmon/hwmon2
$ ls -l
total 0
lrwxrwxrwx 1 root root    0 Jun  2 21:55 device -> ../../../0-0044
-rw-r--r-- 1 root root 4096 Jun  2 21:55 heater_enable
-r--r--r-- 1 root root 4096 Jun  2 21:55 humidity1_alarm
-r--r--r-- 1 root root 4096 Jun  2 21:55 humidity1_input
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_max
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_max_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_min
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_min_hyst
-r--r--r-- 1 root root 4096 Jun  2 21:55 name
lrwxrwxrwx 1 root root    0 Jun  2 21:55 of_node -> ../../../../../../../../firmware/devicetree/base/soc/i2c@7e205000/sht3x@44
drwxr-xr-x 2 root root    0 Jun  2 21:55 power
-rw-r--r-- 1 root root 4096 Jun  2 21:55 repeatability
lrwxrwxrwx 1 root root    0 Jun  2 21:55 subsystem -> ../../../../../../../../class/hwmon
-r--r--r-- 1 root root 4096 Jun  2 21:55 temp1_alarm
-r--r--r-- 1 root root 4096 Jun  2 21:55 temp1_input
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_max
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_max_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_min
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_min_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:52 uevent
-rw-r--r-- 1 root root 4096 Jun  2 21:55 update_interval
And there's more; e.g.: ### folder 3: /sys/devices/platform/soc/3f205000.i2c/i2c-0/0-0044/hwmon/hwmon2/subsystem/hwmon2 I realize there are symlinks involved, but is there a *true/immutable* location for these files in sysfs? I've read some references on sysfs (https://thelinuxcode.com/linux-sysfs-file-system/) , (https://www.kernel.org/doc/html/latest/admin-guide/sysfs-rules.html) , but found no explanation for this apparent duplication. Can someone explain the apparent redundancy, and if there is an immutable location for the files?
Seamus (3772 rep)
Jun 3, 2024, 04:56 AM • Last activity: Jun 3, 2024, 05:33 AM
0 votes
1 answers
397 views
Watching for /sys/class/net file changes using systemd
I'm trying to get a systemd service to restart when some ethernet cable gets plugged in, by monitoring changes to the `/sys/class/net/eth0/carrier_up_count` system file. I tried creating a systemd path service: ``` [Path] PathModified=/sys/class/net/eth0/carrier_up_count Unit=restart-other-service.s...
I'm trying to get a systemd service to restart when some ethernet cable gets plugged in, by monitoring changes to the /sys/class/net/eth0/carrier_up_count system file. I tried creating a systemd path service:
[Path]
PathModified=/sys/class/net/eth0/carrier_up_count
Unit=restart-other-service.service
but, while I can see that the carrier_up_count indeed changes when I plug the cable in, this path service never gets triggered. I assume this happens because systemd path services actually monitors when files are open and closed for writing, and the /sys/ files are always open (I can see that the last modified timestamp of the file doesn't change even though the contents of the file does). I also tried using a systemd socket service with ListenSpecial=/sys/class/net/eth0/carrier_up_count, but the service failed:
Got unexpected poll event (0x9) on socket.
Failed with result 'resources'.
Is there a way to get systemd to monitor changes on the files in /sys/ ? I guess I could just create a cronjob that reads the target file periodically but it feels like there should be a better way.
Quentin (25 rep)
May 19, 2024, 08:19 PM • Last activity: May 19, 2024, 08:49 PM
Showing page 1 of 20 total questions