date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,697,182,102,000
Can I change the value of those parameters (spoofprotect, syncookies, dynaddr_hack, notimestamps, nobroadcasticmpecho, ip_forward) from sysctl.conf file in systemd?
From this link, I see that, these values can be edited. ip_forward=no ipv6_forward=no spoofprotect=yes syncookies=no The above variables can now be set in /etc/sysctl.conf which is acceseble via the System configuration menu, System variables. From this answer, I see changing net.ipv4.icmp_echo_ignore_broadcasts is ...
Change network values from sysctl.conf
1,697,182,102,000
I see on the web two different commands to load sysctl custom parameters: sysctl --system sysctl -p Is there any difference between the two commands? I know the second one I posted can take the path of a file to load but without any file specified, everything will be loaded.
The sysctl --system load settings from all configuration files. The sysctl -p will load settings from the default /etc/sysctl.conf. man sysctl: -p[FILE], --load[=FILE] Load in sysctl settings from the file specified or /etc/sysctl.conf if none given. Specifying - as filename means reading da...
Difference between sysctl options to set system parameters
1,292,477,163,000
What is the difference between procfs and sysfs? Why are they made as file systems? As I understand it, proc is just something to store the immediate info regarding the processes running in the system.
What is the difference between procfs and sysfs? proc is the old one, it is more or less without rules and structure. And at some point it was decided that proc was a little too chaotic and a new way was needed. Then sysfs was created, and the new stuff that was added was put into sysfs like device information. S...
What is the difference between procfs and sysfs?
1,292,477,163,000
What is the difference between the device representation in /dev and the one in /sys/class? Is one preferred over the other? Is there something one offers and the other doesn't?
The files in /dev are actual devices files which UDEV creates at run time. The directory /sys/class is exported by the kernel at run time, exposing the hierarchy of the hardware through sysfs. From the libudev and Sysfs Tutorial excerpt On Unix and Unix-like systems, hardware devices are accessed through special file...
Difference between /dev and /sys/class?
1,292,477,163,000
The Linux kernel swaps out most pages from memory when I run an application that uses most of the 16GB of physical memory. After the application finishes, every action (typing commands, switching workspaces, opening a new web page, etc.) takes very long to complete because the relevant pages first need to be read bac...
Based on memdump program originally found here I've created a script to selectively read specified applications back into memory. remember: #!/bin/bash declare -A Q for i in "$@"; do E=$(readlink /proc/$i/exe); if [ -z "$E" ]; then #echo skipped $i; continue; fi if echo $E | grep -qF me...
Making Linux read swap back into memory
1,292,477,163,000
I have a nearly common Linux machine here. So, it has a PCI (*-X, etc) bus, on that some USB controllers, and I have USB devices on these USB controllers. Similar to this: $ lspci|grep USB 00:12.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller 00:12.2 USB controller: Adva...
This information can be retrieved from the iSerial entry of the verbose output of the lsusb. Easiest is to pass the output to the the less viewer and search manually with /, or for example with grep: $ lsusb -v 2>/dev/null | grep '^Bus\|iSerial' Bus 001 Device 029: ID 12d1:1506 Huawei Technologies Co., Ltd. Modem/Net...
How to find the pci slot of an usb controller in Linux?
1,292,477,163,000
I'm trying to clarify which is the most useful (in terms of functionality) method of interacting with devices in Linux. As I understand, device files expose only part of functionality (address blocks in block devices, streams in character devices, etc...). ioctl(2) seems to be most commonly used, yet some people says...
ioctl tends to go hand-in-hand with a /dev entry; your typical code would do fd=open("/dev/mydevice",O_RDRW); ioctl(fd,.....); This is perfectly standard Unix behaviour. Inside the kernel driver you can put access controls (eg only root can do some things, or require a specific capability for more fine grained acces...
Usage difference between device files, ioctl, sysfs, netlink
1,292,477,163,000
I'd like to know more about the advanced uses of the /proc and /sys virtual filesystems, but I don't know where to begin. Can anyone suggest any good sources to learn from? Also, since I think sys has regular additions, what's the best way to keep my knowledge current when a new kernel is released.
Read this blog post: Solving problems with proc There are a few tips what you can do with the proc filesystem. Among other things, there is a tip how to get back a deleted disk image or how to staying ahead of the OOM killer. Don't forget to read the comments, there are good tips, too.
How do I learn what I can do with /proc and /sys [closed]
1,292,477,163,000
I have a bash script which uses rsync to backup files in Archlinux. I noticed that rsync failed to copy a file from /sys, while cp worked just fine: # rsync /sys/class/net/enp3s1/address /tmp rsync: read errors mapping "/sys/class/net/enp3s1/address": No data available (61) rsync: read errors mapping "/sys/class/n...
Rsync has code which specifically checks if a file is truncated during read and gives this error — ENODATA. I don't know why the files in /sys have this behavior, but since they're not real files, I guess it's not too surprising. There doesn't seem to be a way to tell rsync to skip this particular check. I think you'r...
Why does rsync fail to copy files from /sys in Linux?
1,292,477,163,000
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 ...
This is essentially a matter of checking a whole bag of corner cases. A drive can appear in /proc/mounts A drive can be used as swap (use /proc/swaps) A drive can be part of an active LVM pv (use pvdisplay) A drive can be part of a dm-mapper RAID group (use /proc/mdstat) A drive can be directly accessed by an applica...
How to find out easily whether a block device (or a part of it) is mounted somehow
1,292,477,163,000
This answer to another question basically boils down to chrooting into another Linux distribution in order to mainly use that as a replacement to its too restricted (but irreplaceable) parent. The suggested actions before running chroot, which I would like to understand better, are: cp /etc/resolv.conf etc/resolv.conf...
/etc/resolv.conf is copied in order not to lose the DNSs. /lib/modules is copied because because it may be necessary to use some hardware component that need not be present at the time of setting up the chroot. You must remember that the original question you refer to in your OP concerns the replacement of a NAS OS w...
Which of proc, sys etc. should be bind-mounted (or not) when chrooting into a "replacement" distribution?
1,292,477,163,000
While I am studying, I saw security file system which is mounted on /sys/kernel/security . It seems like to operate similar to sysfs or proc file system. Security file system keeps data on memory not in disk, so when write something into the file in securityfs it does not actually write to disk just update data in mem...
Here are some links regarding securityfs: A post from the author of securityfs Article about PipeFS, SockFS, DebugFS, and SecurityFS. The author stats: This filesystem is meant to be used by security modules, some of which were otherwise creating their own filesystems. So I guess the name comes from the Linux Se...
What is securityfs?
1,292,477,163,000
I ran some commands without completely understanding them while trying to get screen brightness working and now I'm stuck with a nasty symlink in '/sys/class/backlight/asus_laptop' that I am trying to get rid of. I have tried sudo rm /sys/class/backlight/asus_laptop sudo rm '/sys/class/backlight/asus_laptop' su root ...
The sysfs file system, typically mounted on /sys, just like the /proc file system, isn’t a typical file system, it’s a so called pseudo file system. It’s actually populated by the kernel and you can’t delete files directly. So, if the ASUS laptop support isn’t appropriate for you, then you have to ask the kernel to re...
Debian: cannot remove symlink in /sys/: operation not permitted
1,292,477,163,000
I've faced a really strange issue today, and am totally helpless about it. Some of the servers I manage are monitored with Nagios. Recently I saw a disk usage probe failing with this error: DISK CRITICAL - /sys/kernel/debug/tracing is not accessible: Permission denied I wanted to investigate and my first try was to...
/sys /sys is sysfs, an entirely virtual view into kernel structures in memory that reflects the current system kernel and hardware configuration, and does not consume any real disk space. New files and directories cannot be written to it in the normal fashion. Applying disk space monitoring to it does not produce usef...
"cd" into /sys/kernel/debug/tracing causes permission change
1,292,477,163,000
If /proc/config.gz is unavailable, how do I know what decompression algorithms the running kernel is capable of using on a compressed cpio initramfs? Is the gzip algorithm always available, even when CONFIG_DECOMPRESS_GZIP is not y when building the kernel?
Compression algorithms are declared in lib/decompress.c. Gzip is defined in lib/decompress_inflate.c and doesn't get any special status; it'll only be there if CONFIG_DECOMPRESS_GZIP is y when the kernel is compiled. The list of available compression algorithms is the compressed_formats structure. Since it's defined a...
How do I know what decompression algorithms are compiled-in into the linux kernel?
1,292,477,163,000
How can I get hard disk capacity, usage, etc. using the /proc or /sys filesystems? If it is possible, please tell me which file(s) I need to process to get that information.
This is Answer cat /sys/block/sda/size Above file will returns some number like 312581808, then this number need to multiply by 512 standard block size then u ll get long int value in bytes, then u can convert to GB.
How to get hard disk information from /proc and/or /sys
1,292,477,163,000
Background: I am exploring how to copy an ordinary LVM-on-LUKS Debian 9 ("Stretch") installation from a thumb drive (the "source drive") onto a ZFS-formatted drive (the "target drive") in order to achieve a ZFS-on-LUKS installation. My process is based on this HOWTO.* I think the ZFS aspect is irrelevant to the issue ...
You need to add mount --make-rslave /mnt/"$i" after your first mount command, to set the correct propagation flags for those mount points. They protect the host from changes made inside the chroot environment, and help prevent blocking situations like yours.
unmount sys/fs/cgroup/systemd after chroot, without rebooting
1,292,477,163,000
This is on a Raspberry Pi. Here's the output of sudo ls -lL /sys/class/gpio/gpio18: -rwxrwx--- 1 root gpio 4096 Mar 8 10:50 active_low -rwxrwx--- 1 root gpio 4096 Mar 8 10:52 direction -rwxrwx--- 1 cameron cameron 4096 Mar 8 10:50 edge drwxrwx--- 2 root gpio 0 Mar 8 10:50 power drwxrwx...
I solved the problem by adding cameron to the gpio group: sudo usermod -aG gpio cameron gpio export 18 out echo 1 > /sys/class/gpio/gpio18/value Now everything works.
Unable to write to a GPIO pin despite file permissions on /sys/class/gpio/gpio18/value
1,292,477,163,000
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-rul...
It's the device link in class directories that you aren't supposed to use. The idea is that /sys/class/net/eth0 is a symbolic link to somewhere under /sys/devices, and the device link merely links to a (grand-)*parent directory; instead of using the device link, you're supposed to walk back to a parent directory if ne...
Getting information from sysfs
1,292,477,163,000
On any PC where USB host controller is connected to the PCI/PCIE bus I see the following: $ cat /sys/bus/usb/devices/usb1/{idVendor,idProduct,manufacturer,product,serial} 1d6b 0002 Linux 4.14.157-amd64-x32 ehci_hcd EHCI Host Controller 0000:00:1a.0 I.e. the EHCI host controller, which in this example has the PCI devi...
Linux has an abstraction that lets Host Controller Drivers share code. As a comment in drivers/usb/core/hcd.c says: * USB Host Controller Driver framework * * Plugs into usbcore (usb_bus) and lets HCDs share code, minimizing * HCD-specific behaviors/bugs. * * This does error checks, tracks devices and urbs, and ...
Why does Linux list USB Host Controller' vendor as "Linux Foundation"?
1,292,477,163,000
I want to search for a string inside the /sys/class/tty/* directories. So I tried with: # grep -rn path -e pattern but it returns nothing. Example: # cat /sys/class/tty/ttySTM0/iomem_base 0x40010000 # ls -l /sys/class/tty/ttySTM0/iomem_base -r--r----- 1 root root 4096 Jan 17 10:37 /sys/class/tty/ttySTM0/iomem_base...
Use either of these instead: grep -rn /sys/class/tty/* -e 0x40010000 2> /dev/null grep -Rn /sys/class/tty/ -e 0x40010000 2> /dev/null The glob in the first command is needed in order to have it follow the symlinks that aren't specified on the command line as the contents of /sys/class/tty are all symlinks to the con...
Grep inside /sys file returns nothing
1,292,477,163,000
Values of a specific parameter (for example, blkio.throttle.write_bps_device) for all devices are stored in a single file. echo "$MAJOR:$MINOR $LIMIT" > blkio.throttle.write_bps_device inserts/updates a value to $LIMIT. It does not clear the file, as you might think. So I see no way to delete a value. Also this config...
I had the same problem, and I found that you have to set $LIMIT to 0 to remove that limit: echo "$MAJOR:$MINOR 0" > blkio.throttle.write_bps_device This removes the entry from the cgroup. If you then cat blkio.throttle.write_bps_device, you will not see the entry any more.
How to delete a device parameter for a cgroup?
1,292,477,163,000
I am using a library (librealsense) that only outputs the bus and port number as such (9.1). It uses libusb internally. The issue is from this identifier in libusb I want to know what physical device it belongs to in /dev/video0. For instance, 9.1 -> /dev/video0 and 7.2 -> /dev/video2 when two cameras are plugged in i...
Answering so I can close this question full credit to @ridgy and @dirkt for their help. With the command: udevadm info -n video0 -q path Or similarly with ls -l /sys/class/video4linux/, a path of the form /devices/pci0000:00/0000:00:10.0/usb7/7-2/7-2:1.0/video4linux/video0 can be found. That in combination with the l...
How to map /sys/bus/usb/devices to /dev/video*?
1,292,477,163,000
On my local machine, I have /sys/block/sda1/stat. On an Amazon machine, I have /sys/block/xvda1/stat. When I run cat /sys/block/sda1/stat or cat /sys/block/xvda1/stat both give 11 fields of output. What is the difference between /sys/block/sda1/stat and /sys/block/xvda1/stat files?
The /sys directory is generally where the sysfs filestystem is mounted, which contains information about devices and other kernel information. The files in /sys/block contain information about block devices on your system. Your local system has a block device named sda, so /sys/block/sda exists. Your Amazon instance...
What is the difference between /sys/block/sda1/stat and /sys/block/xvda1/stat?
1,292,477,163,000
I'm wondering if I can use the directory listing of /sys/module instead of lsmod to get a list of currently loaded modules. Is that the list of loaded modules only? Or maybe that combined with /sys/module/*/initstate?
Each loaded module has an entry in /sys/module. But there are also kernel components with an entry in /sys/module that are not loaded as modules. Each kernel component¹ that can be built as a module has an entry in /sys/module, whether it is compiled and loaded as a module or compiled as part of the main kernel image....
Are Modules listed under /sys/module all the Loaded Modules?
1,292,477,163,000
I wonder if it is possible to mount only part of sysfs for usage in chroot. Example I would require only /sys/class/gpio and rest is not required. mount -t sysfs sys/some/folder /mnt/temp_sys
The generic way to do this for any kind of file systems is bind mount. This example is using /tmp. To do that on /sys you may replace /tmp/sysall by /sys: mkdir /tmp/sysall mkdir -p /tmp/mychroot/sys/class/gpio mount -t sysfs sysfs /tmp/sysall/ mount --bind /tmp/sysall/class/gpio /tmp/mychroot/sys/class/gpio umount...
Mounting only a specific part of sysfs
1,292,477,163,000
I found a file /sys/class/firmware/timeout, and this file contains just one word 60. Is this timeout related to bootloader like GRUB timeout? What is the practical use of it?
It is not related to any bootloader at all. When a driver uses the kernel's common firmware loading infrastructure to load a firmware file, the kernel can either load the file directly from the standard /lib/firmware directory tree, or it can optionally start an user-space process to handle the firmware load. This us...
What is firmware timeout?
1,292,477,163,000
On Linux, the command lsblk -o partlabel will display the partlabel for block devices. I have used gdisk to change a partlabel. After the change, lsblk is still reporting the old value of the partlabel. (Aside: The paths /dev/disk/by-partlabel/* are also still using the old partlabel values.) Is there some way to refr...
I found an answer: sudo udevadm trigger Source: http://ptspts.blogspot.com/2009/09/how-to-refresh-devdisk-on-linux.html Update #1: It appears the sudo may be unnecessary. So: udevadm trigger Update #2: It appears that sudo is necessary to propagate a changed Btrfs filesystem label. (While this is not the question ...
How to update/refresh changed partlabels as reported by lsblk?
1,292,477,163,000
I have one of these: Basically, it's a USB device with three LEDs (red, green, and blue). The Linux kernel has supported this device through the usbled module for quite some time now. However, I am not sure how to actually control the device from a Bash script. The /sys directory contains the following files: root@de...
The files red, green, and blue are char devices that allow ASCII decimal values to be written to them. For example, to change the device to bright red, one would do the following*: #!/bin/bash echo 9 >red echo 0 >green echo 0 >blue * note that this must be run as root
Using Bash to write to a device in /sys?
1,292,477,163,000
I'm writing a script, and I'm interested in being able to identify the transport class (fc - "fibre channel", scsi, iscsi, etc.) for a given block device. I can retrieve this information via ls -l /dev/disk/by-path on RHEL, but I'd rather query sysfs if that's at all possible (for a variety of reasons, including porta...
Unless I get a better answer, I'm going to take this as my solution. It's very indirect but appears to work. Basically, I judged from the fact that udevd was able to make the path in /dev/disk/by-path, it must be in sysfs because to my knowledge that's all udev really does: Takes sysfs information and performs configu...
Can you identify transport via sysfs?
1,292,477,163,000
I was making (my first) kernel module to play with the gpio pins of my pandaboard and interrupts. Already "built-in", I noticed you can do (briefly) cd /sys/class/gpio echo 138 > export # a file gpio138 appears echo out > gpio138/direction echo 1 > gpio138/value to turn some voltage high or low on connector pins...
1) What handles /sys/class/gpio ? A kernel module ? a driver ? It's a kernel interface similar to the /proc directory. 2) is it possible to have more complicated module parameters in a kernel module, with some directory structure ? Like a 'delays' directory containing the params for delays Yes; some things in /pro...
Kernel module parameters vs /sys/class/... explanation
1,292,477,163,000
On a running linux system, what is a portable (among linux distributions) way to find out what filesystems the current kernel has compiled-in (not through modules) support for? Consider for example my current Ubuntu x86_64 kernel: 3.11.0-24-generic #41-Ubuntu. It has for instance no /proc/config.gz, which would be my ...
Is is as simple as comparing /proc/filesystems with lsmod? No: $ comm -31 <(lsmod | awk 'NR!=1 {print $1}' |sort) \ <(</proc/filesystems awk '{print $NF}' |sort) | fmt anon_inodefs autofs bdev cgroup cpuset debugfs devpts devtmpfs ext2 ext3 fuseblk fusectl hugetlbfs mqueue nfs4 pipefs proc pstore ramfs ro...
How do I find out what filesystem drivers are compiled-in into the linux kernel?
1,292,477,163,000
[gala@arch ~]$ sudo !! sudo hdparm -i /dev/sda /dev/sda: Model=KINGSTON SHFS37A120G, FwRev=603ABBF0, SerialNo=50026B725B0A1515 Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% } RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4 BuffType=unknown, BuffSize=unknown, MaxMultSect=1, MultSect=1 ...
# strace hdparm -i /dev/sda … ioctl(3, HDIO_GET_IDENTITY, 0x7fffa930c320) = 0 brk(0) = 0x1c42000 brk(0x1c63000) = 0x1c63000 write(1, "\n", 1 ) = 1 write(1, " Model=… So hdparm gets its information from the HDIO_GET_IDENTITY ioctl, not fro...
Get block device model name and manufacturer from pseudo-fs
1,292,477,163,000
I have an AMD CPU with 8 cores and 2 threads per core. Linux (correctly) shows this as 16 "cpus". However, sysfs actually shows 32 "possible" cpus, with 16 of them not present and offline: $ cat /sys/devices/system/cpu/possible 0-31 $ cat /sys/devices/system/cpu/present 0-15 $ cat /sys/devices/system/cpu/online 0-15...
A CPU is “possible” if there's room for it in the kernel memory. The number of possible CPU is the maximum number of CPU that can be brought online, including ones that are hotplugged after boot. The documentation of this part of sysfs is in How CPU topology info is exported via sysfs: possible: CPUs that have been a...
How does Linux detect number of "possible" CPUs
1,292,477,163,000
Is the file located under: /sys/block/<xxx>/size Constantly referencing to 512 byte block count, or is there any special cases where the block count changes? I'm curious because: thinkpad :: /sys/block/sdf % cat queue/physical_block_size ...
The size entry returns the nr_sects field of the block device structure. Traditionally, in Unix disk size contexts, “sector” or “block” means 512 bytes, regardless of what the manufacturer of the underlying hardware might call a “sector” or “block”. I can't find authoritative documentation, but looking at the Linux so...
sysfs block size count
1,292,477,163,000
I wrote the following simple linux kernel module to test the param feature: #include<linux/module.h> int a = 5; module_param(a, int, S_IRUGO); int f1(void){ printk(KERN_ALERT "hello world\n"); printk(KERN_ALERT " value passed: %d \n", a); return 0; } void f2(void){ printk(KERN_ALE...
The /sys (sysfs) filesystem is somewhat special; many operations are not possible, for example creating or removing a file. Changing the permissions and ownership of a file or setting an ACL is permitted; that allows the system administrator to allow certain users or groups to access certain kernel entry points. There...
Why am I able to write a module parameter with READ ONLY permissions?
1,292,477,163,000
Kernel space device drivers usually implement directories and file that show through /sys or /proc. Can the long running user space programs do this as well? I have a daemon or long running program that needs to be able to be queried for some data and have some data set by external programs while it runs. I could do ...
I don’t think there’s any way to add /sys or /proc entries outside the kernel. For /sys it wouldn’t make much sense anyway — it’s a direct representation of kobject data structures. You can however provide similar interfaces from userspace, for example using FIFOs; see mkfifo for details. You can see an implementation...
Can user space programs provide/implement sysfs or procfs files to pass data to and from a program?
1,292,477,163,000
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
I have not read the source code that populates operstate, but generally, reading a file in sysfs executes some code on the kernel side that returns the bytes you're reading. So, without you reading operstate, it has no "state". The value is not stored anywhere. How to watch for sysfs file change Since these are not ...
How to attach a listener to sysfs files?
1,292,477,163,000
If I understand correctly, in Linux, everything is a path, right down to each piece of hardware. I am trying to get information about how my sensors are structured, so I thought I would just use tree to map out all the things in my hwmon directory. However, tree does not behave the same with this directory as I am acc...
tree behaves that way because it doesn’t dereference symlinks by default. The -l option will change that: tree -l /sys/class/hwmon/ but you’ll have fun making sense of all the output.
Why can't tree fully list /sys/class/hwmon? And how could I do that?
1,292,477,163,000
I have Compaq CQ60-120ec notebook. I discovered that there is a directory /sys/class/thermal/cooling_device2. The type said LCD. I tried to control the cooling device, and it dimmed my backlight on the laptop. But I have question I cannot find aywhere on the internet. Why it is showing up as thermal device? Why not as...
I dug around a bit, and the reason behind your "LCD cooler" turned out to be incredibly interesting, in my opinion: First off all, apparently LCD devices being listed as coolers under acpi are a thing, and not just a strange feature of your laptop - there are some more examples of those floating around online. If you ...
Sysfs LCD backlight as thermal device
1,292,477,163,000
Program A periodically (20 times/s) over-writes the first (and only) line of a sysfs file (F). Program B periodically (20 times/s) opens the same sysfs file (F), reads the first line and closes it. Since F is a shared resource and in the above scenario that does not have any synchronization between the two programs, t...
The sysfs code was partially split in version 3.14 (2014) into a kernfs common part that would make it suitable for other subsystems to have a virtual filesystem, so we have to look at sysfs and kernfs. Though there is no apparent serialization in the sysfs code, the kernfs layer above is using a mutex in kernfs_file...
Shared access of sysfs
1,448,217,067,000
ACPI procfs is deprecated in new kernel versions. In sysfs, which is supposed to replace it, I don't know of any clean way to read the state of the lid button. What is the new way of doing this?
TL;DR: This exact feature is gone forever, because of laptops' poor quality and buggy precious, proprietary, NDA-ed firmware. But there is a workaround. According to this thread on Linux kernel bug tracker, firmware in way too many laptops initializes its internal lid state variable to zero on boot - meaning closed. D...
sysfs alternative to /proc/acpi/button/lid/LID/state
1,448,217,067,000
Having had a bit of an internet-scour, I think the answer may be "No", but: Can I find the USB port description (as per dmidecode) corresponding to the USB device from sysfs? We can enumerate all USB hubs and devices by listing /sys/bus/usb/devices. For example: lrwxrwxrwx 1 root root 0 May 18 09:40 1-2 -> ../../../de...
The output of dmidecode is based on SMBIOS data. Here is apparently-latest version of the SMBIOS specification, as of this writing. The lower half of page 70 describes the data structure for the port connector information. The only meaningful values there are the DMI structure handle (a simple 16-bit number), internal...
Can I relate a USB device from /sys to a particular USB connector from Dmidecode?
1,448,217,067,000
I have one of these and I am trying to write a Bash script for finding the device path in /sys. My approach goes something like this: start in /sys/modules/usbled since this is the name of the kernel module loaded when the device is plugged in cd to drivers/usb:usbled, which appears to be the bus and name of the driv...
OK I think your question title is a bit unintentionally misleading, since in the text you're saying you've already found the device and are asking how to programmatically do so. One question that comes to mind is how you manually found it and why you couldn't just script around it. I'll answer the question as best I c...
Finding a char device in /sys using a Bash script?
1,448,217,067,000
When I connect my Samsung 390G (a cheap cell phone!) to Ubuntu 13.04, dmesg seems to indicate that the storage device thereon is recognizable: [Sun Dec 29 01:26:10 2013] scsi16 : usb-storage 2-1.2:1.0 [Sun Dec 29 01:26:11 2013] scsi 16:0:0:0: Direct-Access SAMSUNG MMC Storage 2.31 PQ: 0 ANSI: 2 [Sun Dec 29 0...
You'll likely need to add a UDEV rule to detect this devices presences. Once the device is detected, UDEV can create the corresponding /dev/sdb1 to go along with it. These docs from OpenSUSE should get you started in the creation of this rule. Chapter 13. Dynamic Kernel Device Management with udev Regarding your que...
Kernel recognizes USB device but then I can't find it in /sys or /dev
1,448,217,067,000
I just unmounted cgroup version 1, leaving just a single cgroup2 mount on my system. $ mount | grep -i cgroup tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755) cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate) I was under the impre...
It's actually very simple. All cgroup mounts must be done on top of a directory. Before you had, cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd) cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids) cgroup on /sys/fs/cgroup/net_cls,net_prio t...
Why, after unmounting cgroup v1, do I still have empty directories under /sys/fs/cgroup?
1,448,217,067,000
I want to write a driver to pass some info to a device, and to do so I've made a sysfs entry. It works fine, but the problem is that I don't have the permissions to write to it unless I am logged in as admin. I'd like it to have open read and write permissions. The way I was advised to write the driver, I used the fol...
The __ATTR macro expands to the following [1]: #define __ATTR(_name, _mode, _show, _store) { \ .attr = {.name = __stringify(_name), \ .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ .show = _show, \ .store = _store, \ } Note the use of the...
How to give Sysfs attribute write permissions?
1,448,217,067,000
box101:~ # cat /sys/class/net/eno1/carrier cat: /sys/class/net/eno1/carrier: Invalid argument What the...? OK, so what does strace say? ... open("/sys/class/net/eno1/carrier", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=4096, ...}) = 0 fadvise64(3, 0, 0, POSIX_FADV_SEQUENTIAL) = 0 read(3, 0x19c8000, 65536) ...
There are some issues with hardware/driver as explained on this LKML thread. Quoting just a little part of the reply mail: The reason is that most drivers don't even probe the link or negotiate link speed and flow control until the device is brought up. Many don't even power up the PHY when the device is down, in or...
Reading from sysfs returns EINVAL
1,448,217,067,000
On Linux (Ubuntu 11.10 on a ARM processor in my case) I was looking for a way to measure CPU temperature. I found out that a cat /sys/class/thermal/thermal_zone0/temp did the trick. Now I wonder: what is the /sys/class filesystem meant for?
/sys is an implimentation of the sysfs (system file system) which is a virtual file system (it doesn't exist on disk) various system internals can be read here, in a similar way /proc and the procfs shows process information. /sys/class shows information that relate to a class of device/attribute. You can read an ove...
/sys/class filesystem on Linux
1,448,217,067,000
If I pipe a string consisting only of a positive integer into /sys/class/backlight/intel_backlight/brightness, it works. But if I pipe a string containing anything else I've tried, I get an error message: $ sudo su -c "echo 10 >/sys/class/backlight/intel_backlight/brightness" $ sudo su -c "echo -- -1 >/sys/class/backl...
You can only write non-negative integers to this file because it is a special file and the kernel rejects any other input. It isn't a special file in the sense of having a special file type, but it's a special file because it's on a special filesystem. When you access a “normal” filesystem, the kernel stores the file ...
How come I can only pipe positive integers into this file?
1,448,217,067,000
I'm trying to make /sys/fs/selinux/enforce always contain "1", and prevent it from being changed. I've been able to do this on /etc/selinux/config by running chattr +i /etc/selinux/config However, when i try this on a file in the selinux sysfs I get the following error: chattr: Inappropriate ioctl for device while rea...
You will have to patch the kernel. Files in /sys and /proc are purely virtual, you cannot change their permissions using normal Linux utilities.
Any way to make sysfs file immutable?
1,448,217,067,000
I have one USB touchscreen connected to my hardware setup but using cat /proc/bus/input/devices gives me two entries for the same device : I: Bus=0003 Vendor=2965 Product=5023 Version=0110 N: Name="Kortek Kortek Touch" P: Phys=usb-0000:00:14.0-3.4/input2 S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.4/3-3.4:1...
I think I found the reason behind this. The same device is exposed to USB subsystem as two devices with different interfaces. like in the entry Sysfs=/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.4/3-3.4:1.2/0003:2965:5023.0006/input/input7, the device exposes Interface 2 of the hardware as seen from the string 3-3.4:...
Multiple entries in /proc/bus/input/devices for same device
1,448,217,067,000
I was trying to get frequecy from my device at run time. I used this device node sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq It gave me 60000. I tried this one cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq I get 396000. What is the unit of these values. Is it 60000 Hz or Mhz?
The values are given in kHz (see the documentation). So 60000 is 60 MHz, 396000 is 396 MHz.
What is the unit of this value
1,448,217,067,000
my rootfs.cpio has only following files: [root@localhost extract]# ls dev init tmp dev has console only. init is cross-compiled from the program given at the end: Then I make a my image and run linux. It runs fine but when init comes it shows error similar to the following : Failed to open /sys/class/gpio/gpio251...
/sys is a special filesystem. You can't just create it and put files in it. It's like /proc, a fake filesystem provided by the kernel. Geting /sys working requires 2 things: In your kernel configuration, you need to have CONFIG_SYSFS=y. You need to mount it with mount -t sysfs none /sys (assuming you're running from ...
Accessing GPIO after kernel boots
1,448,217,067,000
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 & hum...
/sys/class/hwmon/hwmon2 is a symlink to /sys/devices/platform/soc/3f205000.i2c/i2c-0/0-0044/hwmon/hwmon2 (technically, /../../devices/platform/soc/3f205000.i2c/i2c-0/0-0044/hwmon/hwmon2). /sys/devices contains the sysfs files, by device, for all the devices in the system. This allows them to have a unique path and nam...
Why is this folder duplicated in `sysfs`?
1,448,217,067,000
I'm testing udev rules with a file /etc/udev/rules.d/10-test.rules. This line: DEVPATH=="/devices/system/node/node0", ATTR{hugepages/hugepages-1048576kB/nr_hugepages}="4" makes /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages be 4. But this line: DEVPATH=="/kernel/mm", ATTR{hugepages/hugepage...
/sys/devices/system/node/node0 represents a NUMA hardware node that may accept a command to go into an offline state independent of the rest of the system. So it can be the subject of udev events, which can trigger actions based on udev rules. /sys/kernel/mm represents no particular hardware: it is just a place for ge...
Why does udev rule not work on `DEVPATH=="/kernel"`?
1,448,217,067,000
The mount point for debugfs is /sys/kernel/debug, and the mount point for sysfs is /sys/, why can these 2 mount points be overlapped without interference?
Every directory can be a mountpoint, like / is a mountpoint, and /sys is too, or often /home is a separate mountpoint.
Why can the mount points of debugfs and sysfs be overlapped?
1,448,217,067,000
My assumption is that sysfs is built using ioctl queries, meaning all the information you would want (or at least most of it) is already available by simply reading files on sysfs. I notice some programs (e.g., hdparm) still use ioctl calls rather than simply hitting sysfs , and I'm curious if there's a reason for tha...
As rightly asserted by Tilman in comments, sysfs and ioctl both provide userland access to kernel data structures. Since the kernel does not need system calls to access to its own data, neither is the sysfs tree built resorting to ioctl calls, nor any user action on its files will translate into ioctl calls. You writ...
Is there ever a reason to query ioctl for hardware info when we have sysfs?
1,448,217,067,000
What APIs/interfaces are available for this? I think I want sysfs, but according to what various kernel documentation exists, that interface can be summed up as "you're not allowed to use any of this, implementation details.", and what little it does allow you to use is completely undocumented. Specifically I want to ...
No one else has answered this but I've come up with a solution, so answer: I think the most correct way is to use /sys/class/block/*, which contains (symlinks to) available block devices. It also has their partitions, which you will want to ignore and can identify by the existence of a partition file. This file is und...
How to get connected block devices on Linux
1,448,217,067,000
I have an input class device (accelerometer) bound to a driver which exposes sysfs attributes that I need to access from userland. Using a udev rule, I have provided an alias that unambiguously identifies my device, i.e. ll /dev/input yields: lrwxrwxrwx 1 root root 6 May 18 13:47 accelerometer0 -> ...
Programmatically, you could first stat("/dev/input/accelerometer0", &stat_struct) to find out the major and minor device numbers. Then use libudev's udev_device_new_from_devnum() to get a struct udev_device for your accelerometer, and then udev_device_get_syspath() to get the pathname of its sysfs directory.
How to find sysfs directory for a specific device?
1,501,078,696,000
I've got some sort of home entertainment system running an old version of Linux 2.6. It has a SATA > USB bridge system and a couple of USB ports. What I want to do is use it as Network Attached Storage. Now, luckily, it has an open and accessible telnet server running. The problem is, I can't find where the kernel, n...
mknod /dev/mtdblock0 c 31 0 You created a character device. You wanted a block device. So use b instead of c in the mknod command. Block device numbers and character device numbers are independent. Block device 31:0 is unrelated to character device 31:0. Your kernel has no driver for character device 31:0, hence the “...
Failing to create /dev entry from sysfs, No such device or address
1,501,078,696,000
I know that I can use cat /sys/class/net/eth0/statistics/rx_bytes to see the amount of received bytes. Sadly I only can run this command as root. When I am another user, I get cat: /sys/class/net/eth0/statistics/rx_bytes: Permission denied Is there an easy way to allow non-root users to read this file? Currently a n...
As far as I can tell, this file is public by default. Check if there are startup scripts that restrict permissions on your system, either with traditional file permissions or with a security framework such as SELinux or AppArmor. If you want to leave most directories opaque but allow access to this one file, you can a...
Allow non-root user go get network traffic statistics
1,501,078,696,000
My current primary question motivator: $ ls -l /sys/devices/platform/samsung total 0 -rw-r--r-- 1 root root 4096 27. jaan 14:17 battery_life_extender drwxr-xr-x 3 root root 0 19. jaan 18:40 leds -r--r--r-- 1 root root 4096 26. jaan 23:37 modalias -rw-r--r-- 1 root root 4096 27. jaan 12:57 performance_level drwx...
One solution would be a script, which changes permissions on that files using chmod and then setting you system so it would start the script on system bootup.
Is there a generic approach to automatically make some sysfs controls ch{own,mod} user-accessible?
1,501,078,696,000
I customized the system using Kernel 6.4.0 and Busybox, but I don't know why the three files starting with phys_ cannot be accessed, and other files in the same folder can. # pwd /sys/class/net/eth0 # ls addr_assign_type carrier_up_count gro_flush_timeout napi_defer_hard_irqs proto_down tx_qu...
The contents of that phys_port_id file is generated upon request (when a process reads it) by the phys_port_id_show() function in the Linux kernel. You can see that it returns EOPNOTSUPP if the driver for the network interface doesn't implement a ndo_get_phys_port_id operation. If you look for ndo_get_phys_port_id in ...
cat: read error: Operation not supported for /sys/class/net/eth0/phys_*
1,501,078,696,000
I am wondering what happens when two processes write to a character device file at the same time. Currently, I am mostly worried about /dev/spidev0.0 on a Raspberry pi. If I assume correctly that it's the drivers task to deal with concurrent writes, does the driver see which processes have written which data? Or does ...
Looking at the Linux 5.4.97 kernel source, I see drivers/spi/spidev.c. In that file, I see the function that handles write requests: ssize_t spidev_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) { struct spidev_data *spidev; ssize_t s...
Concurrent write access to character device file
1,501,078,696,000
I am looking at files in sysfs, specifically in /sys/bus/usb/devices The files contains small numbers, expressed as two characters, for example "00" All of the examples that I have contain numbers that are "09" or lower. I am writing a script to interpret these, and it is not clear to me whether I should expect "0A" o...
It depends on the kobject field and its serialisation functions. It’s not always easy to find those, but for USB they’re conveniently grouped. bInterfaceNumber is declared thus: usb_intf_attr(bInterfaceNumber, "%02x\n"); The second argument is the format string, so it shows a hex value. The line below shows that bAlt...
Are numbers in sysfs presented in decimal or hex?
1,501,078,696,000
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 ...
No, file system monitoring is a kernel function, and systemd just uses this function. The sysfs file system is a mapping of kernel objects to file names, and does not support inotify. The best way to monitor interface up/down events is through netlink (the ip mon command shows what events are available there), but the...
Watching for /sys/class/net file changes using systemd
1,501,078,696,000
If you build a custom GNU/Linux system for an embedded device, do you need to execute mount -t proc proc /proc mount -t sysfs sysfs /sys somewhere in init process or is this done automatically by the kernel? I've read contradicting statements about this. An embedded Linux book advises to run the commands in init scri...
If you have systemd, it does that automatically (and some extra mount points as well, including /dev/, /dev/shm, /dev/pts, /run and even /tmp). If you have a different init system, you'll have to do that according to its documentation, most likely manually using /etc/fstab or/and scripts. Here's what gets mounted on F...
Who mounts /proc and /sys in GNU/Linux systems?
1,501,078,696,000
Thank you for reading this question. I was trying to compile a kernel module that works with sysfs, and while executing make I ended up with this error. Can somebody please help me understand what this error means? /usr/src/linux-headers-4.19.0-9-common/include/linux/build_bug.h:29:45: error: negative width in bit-fie...
This specific error isn’t particularly important, it’s a “trick” used to break the build if a given value is determined to be zero. To understand why the build is failing, you need to look at the next error message, which should include note: in expansion of macro ‘BUILD_BUG_ON_ZERO’ followed by the expression which...
negetive width in bit field '<anonymous>' while running 'make'
1,501,078,696,000
Once upon a time, I cast this shellspell, # tail -f /sys/devices/platform/applesmc.768/light and it does produce, (0,0) Those file I read is light sensor abstraction file of Macbook Pro. Unfortunately, when I give some light into the sensor (in the same place as camera), It didn't update the value! It does show the...
Use watch around cat or a while loop instead: watch cat /sys/devices/platform/applesmc.768/light while sleep 0.5; do cat /sys/devices/platform/applesmc.768/light; done The file is not being appended to with new values, it is being replaced so inorder to reread the values you need to reread the file. Thus tail will n...
Tail-ing /sys/devices/platform/applesmc.768/light not working
1,501,078,696,000
I'd like to guarantee that what I write to a sysfs file (specifically the /sys/class/gpio files) is sync'd to the actual register. The code I had initially opened the file with the O_SYNC flag, which I assumed did this. However, in another piece of code, I tried using fsync(), but it failed with EINVAL, and man fsync ...
/sys is a completely RAM-based filesystem for access to kernel data structures. This includes the GPIO interfaces. All you need to do is open the pseudofile normally, and use a single write to write the data. If it succeeds, and all of the data (except possibly any trailing whitespace like newlines) was written, the k...
Synchronous I/O on sysfs files
1,501,078,696,000
I wanted to check if the multi-generational LRU was active on my desktop, so I looked at the value of /sys/kernel/mm/lru_gen/enabled. It was set to 0x0007. I felt unsure what to make of this value, so I checked the value on a different device where I knew for sure that I had enabled it since I configured the kernel my...
The multi-gen LRU documentation in the kernel describes the values as follows: Values Components 0x0001 The main switch for the multi-gen LRU. 0x0002 Clearing the accessed bit in leaf page table entries in large batches, when MMU sets it (e.g., on x86). This behavior can theoretically worsen lock contention...
What do the different values of /sys/kernel/mm/lru_gen/enabled mean?
1,501,078,696,000
I'm running ubuntu linux and I have a bluetooth mouse that I would like to capture evdev events from. The problem is that the event device can potentially be different any time I connect the mouse: sometimes it's /dev/input/event17, sometimes /dev/input/event16, etc. /dev/input/by-id and /dev/input/by-path aren't gett...
Use udevadm info to query device attributes, then creat udev rule which would create symlink in /dev/ to easy access the device by your custom name. See https://wiki.archlinux.org/index.php/Udev#udev_rule_example
Is there a reliable path to specific device events?
1,501,078,696,000
On our 3.X series kernel, a proprietary PCI-Express device has a proprietary kernel driver. We're seeing some weird errors on trawling PCI capabilities. I can not find any great docs - does anyone know if the kernel driver can control what data is exposed in sysfs/procfs based on user-id? Specifically, this call fail...
Yes, a kernel driver can control the data it exposes in sysfs/procfs based on user-id, and/or basically any information the kernel has access to. When you read something from procfs or sysfs, the system call for reading the information basically ends calling a function in the respective driver. That function can see a...
PCI-E, sysfs and user-id permission weirdness
1,501,078,696,000
I believe I could not fully understand the benefits of writing device drivers in embedded systems for some specific devices, such as GPIO, when there are alternative ways of doing the same job. You can access the GPIOs via sysfs and device tree. Write a new device tree overlay and enable it Go to the /sys/class/gpio...
The advantage of option 2 is that you can validate the request in a single place. Say for a dishwasher you can ensure the door sensor says the door is closed before you turn on the water. Sure you can tell people to check the door status bit before they set the water on bit, but will they all do so? A potential disadv...
Driver development vs sysfs access vs mmap for GPIOs
1,501,078,696,000
Is the information that the Linux kernel provides to the user via sysfs a strict subset of the information that the Linux kernel provides to the user via procfs? If not, then which information is provided via sysfs that is not provided via procfs?
No, it is not a strict subset. It is not even a subset. Here is a demonstration, on a desktop PC running a major GNU/Linux distribution without any customisations that should affect the result, that there is at least one datum present in sysfs that is not present in procfs: $ grep -ir `cat /sys/block/sda/device/model...
Is sysfs a strict subset of procfs? [duplicate]
1,501,078,696,000
What exactly is under the /sys/module/<module_name>/holders directory? From what I see it's all symlinks. But symlinks representing what?
Those symlinks link to modules using the given module. You can see them using lsmod too. For example, on my system, lsmod shows (among many others) ip6_tables 32768 1 ip6table_nat This means that the ip6_tables module is loaded, and that it’s used by the ip6table_nat. This is also represented under /sys/...
What's inside Linux kernel sysfs holders directory?
1,461,408,431,000
I'm trying to make a systemd timer that runs every 15 minutes. Right now I have: timer-fifteen.timer: [Unit] Description=15min timer [Timer] OnBootSec=0min OnCalendar=*:*:0,15,30,45 Unit=timer-fifteen.target [Install] WantedBy=basic.target timer-fifteen.target: [Unit] Description=15min Timer Target StopWhenUnn...
Your syntax translates to every 15 seconds, if you want every 15 minutes, IMO the most readable way is: OnCalendar=*:0/15 An answer most similar to what you use in your question is: OnCalendar=*:0,15,30,45 More information: http://www.freedesktop.org/software/systemd/man/systemd.time.html
systemd timer every 15 minutes
1,461,408,431,000
I've successfully migrated a few of my cron jobs over to systemd. I followed some guides and have taken the standard approach of creating 3 files: myjob.timer - systemd timer unit myjob.service - systemd service unit myjob.sh As you can probably guess, at a certain time myjob.timer is triggered, which runs myjob.serv...
if myjob.service contains no [Install] block, then it is sufficient to just disable the timer. The timer was the only thing starting the .service file, so with the .timer disabled, nothing will start the .service file. Also remember to run systemctl --user stop myjob.timer. Disabling the timer prevents it from being s...
Which is the correct way to disable a systemd timer unit?
1,461,408,431,000
I am testing a systemd timer and trying to override its default timeout, but without success. I'm wondering whether there is a way to ask systemd to tell us when the service is going to be run next. Normal file (/lib/systemd/system/snapbackend.timer): # Documentation available at: # https://www.freedesktop.org/softwar...
The state of currently active timers can be shown using systemctl list-timers: $ systemctl list-timers --all NEXT LEFT LAST PASSED UNIT ACTIVATES Wed 2016-12-14 08:06:15 CET 21h left Tue 2016-12-13 08:06:15 CET 2h 18min ago systemd-tmp...
Is there a way to know when a systemd timer will run next?
1,461,408,431,000
There are several good references on systemd timers including this one: systemd.time Unfortunately, it still isn't clear to me how to create a timer that will run periodically, but at a specific number of minutes after the top of the hour. I want to create a timer that runs 30 minutes past the hour, every 2 hours. So...
Every 2 hours at 30 minutes past the hour should be OnCalendar=00/2:30 # iow hh/r:mm 00/2 - the hh value is 00 and the repetition value r is 2 which means the hh value plus all multiples of the repetition value will be matched (00,02,04..14,16..etc) 30 - the mm value, 30 will match 30 minutes past each hour I le...
systemd timer every 2 hours at 30 minutes past the hour?
1,461,408,431,000
I'm trying to set up a systemd service in order to launch a set of files on a daily basis (different types of journals) from directories based off the date. For example, a todo list for today would be located in: ~/Documents/Journals/2019/1/23/ToDo.md Now the easiest thing to do is to put it in a separate directory,...
Yes, you can write directly to the target directory. You can't really use a pipe directly as part of an ExecStart= command, since systemd doesn't really implement a full shell. But you can invoke a shell explicitly, which would make it work. For example: ExecStart=/bin/sh -c '/usr/bin/atom | /Path/To/Script/Todays_Dir...
Pipe output of script through Exec in systemd service?
1,461,408,431,000
In various examples, I have seen all of these different choices suggested: WantedBy=timers.target WantedBy=multi-user.target WantedBy=basic.target WantedBy=default.target WantedBy=mytimer.target (custom user-defined name) However, in the examples I have found, no further explanation is offered. The following pages a...
For the simple use case, use WantedBy=timers.target. See man systemd.special: timers.target A special target unit that sets up all timer units (see systemd.timer(5) for details) that shall be active after boot. It is recommended that timer units installed by applications get pulled in via Wants= dependencies from...
I'm writing a systemd timer. What value should I use for WantedBy?
1,461,408,431,000
I've created a systemd job using systemd-run --on-calendar .... Now I've replaced it with proper .timer and .service files, but I'm not able to remove the old one. I can stop it and disable it, but when I call systemctl list-timers it still appears with its arbitrary name run-r0d0dc22.... I also looked for its .timer ...
The transient files end up in /run/user/ and do not seem to ever be removed until the user logs out (for systemd-run --user) or until a reboot, when /run is recreated. For example, if you create a command to run once only at a given time: systemd-run --user --on-calendar '2017-08-12 14:46' /bin/bash -c 'echo done >/tm...
Removing a timer created with "systemd-run --on-calendar"
1,461,408,431,000
I'm using a systemd timer and unit to automatically trigger a backup job. But currently it runs only at one moment in the evening. Is it possible to have it run at multiple moments by declaring it in the same timer? This is how it's now: [Unit] Description=Run luky-borg-backup every night [Timer] OnCalendar=21:00 Acc...
Is it possible to have it run at multiple moments by declaring it in the same timer? Yes. See this excerpt from man systemd.timer (my emphasis): OnCalendar= Defines realtime (i.e. wallclock) timers with calendar event expressions. See systemd.time(7) for more information on the syntax of calendar event expressi...
timer with multiple oncalendar moments
1,461,408,431,000
I use systemd-cron which creates unit files under /lib/systemd. The unit file for cron-daily.timer has [Timer] OnCalendar=daily This triggers the scripts at midnight. I want them to trigger at 3am instead. If I create override.conf in the cron-daily.timer.d directory under /etc/systemd/system to have [Timer] OnCalen...
systemd timer units can take multiple OnCalendar= specifications, so when you're creating your override to run at 3am, you're actually adding that time (making it run twice daily, at midnight and 3am.) When you list the timer, it will show you the next schedule for it and, unless you're running that command between mi...
Cannot override systemd timer with specific time [duplicate]
1,461,408,431,000
I am on Arch Linux where I am trying to create a systemd timer as a cron alternative for hibernating my laptop on low battery. So I wrote these three files: /etc/systemd/system/battery.service [Unit] Description=Preko skripte preveri stanje baterije in hibernira v kolikor je stanje prenizko [Service] Type=oneshot E...
An answer to this question is to swap User=nobody not with User=ziga but with User=root in /etc/systemd/system/battery.service. Somehow even if user ziga has all the privileges of using sudo command it can't execute systemctl hibernate inside of the bash script. I really don't know why this happens. So the working fi...
using systemd timers instead of cron
1,461,408,431,000
I'm using systemd-timer to periodically run a script which consumes a webservice. Problem is, upon system resume or wake-up, internet connectivity would not get started right away but the timer gets fired and hence the script returns error (If the service waits for a couple of seconds, the script would run correctly a...
Add After=network-online.target to the [Unit] section of the timer. Explanation: Timers do accept all the relative ordering commands in the [Unit] section that are known for services. In fact both the [Unit] and [Install] sections are identical for timers and services. Form the official manuals: A unit configuration ...
How to make a systemd-timer depend on internet connectivity?
1,461,408,431,000
I'm trying to change the cleanup interval for Apache PrivateTmp files from the default 30 days to 6 hours. I read that to edit the time intervals, I should set up an override file in /etc/tmpfiles.d/tmp.conf rather than editing /usr/lib/tmpfiles.d/tmp.conf, so I created that file with the following lines: # override t...
This answer is a bit late but I'll leave it here in case others stumble on it. I think that it's important to understand the underlying mechanism of how systemd overrides work. Your solution illustrates that you figured out the low level implementation details and how to manually create overrides, which is a good thi...
How to edit the timer for systemd-tmpfiles-clean?
1,461,408,431,000
I have created a systemd user timer that expires daily, i.e. at midnight. The problem is that my computer is normally suspended at night. When I wake it up in the morning, I want the timer to trigger, but that doesn't happen. I discovered the Persistent option, but that only helps when the system is powered down, sinc...
It seems there is no problem with the Persistent option and suspend. The problem seems to be that Persistent=true only works if the timer has had a chance to trigger at least once, i.e. if LAST is not n/a. But my computer is normally suspended at midnight, so the timer has never triggered.
Systemd timer that expired while suspended
1,461,408,431,000
I have a script that updates my google drive. I made a systemd unit to run this script, and a timer that runs the unit every 10 seconds, which both work. However, when I get disconnected from internet, the script fails and systemd stops running the it even if the internet comes back on. Is there any way I can make...
Add Restart=always to the service unit, so systemd will keep bringing up the service if it crashes. On a side note you should use OnUnitInactiveSec instead of OnUnitActiveSec. OnUnitInactiveSec=10s (or 20s) will start the service 10 seconds after it stopped. This way you make sure it doesn't get called twice and poss...
How to run a script every 5 seconds only when connected to internet
1,461,408,431,000
I've been migrating my crontabs to systemd's timer units. They all look similar to this: .timer file: [Unit] Description=timer that uses myjob.service [Timer] OnCalendar=*-*-* *:00:00 Unit=myjob.service [Install] WantedBy=timers.target .service file: [Unit] Description=Script that runs myjob.sh [Service] ExecStart...
I resolved this problem by converting my 'user' timers into root/system timers. I disabled all of my .service and .timer files, and moved them out of my home directory into /etc/systemd/system. I added the 'User=' section to each service file, so that my scripts were ran by the regular user and not as root. Now my t...
Prevent systemd timer from running on startup
1,461,408,431,000
I am writing a script that prepares my Linux system for benchmarking. Among other things I want to stop all systemd timer units, and revert this action afterwards. In short, I need the equivalent of service crond stop/start. All I have found so far is systemctl list-timers and then manually stop each one, and afterwar...
To stop all currently running timers, you can simply use: systemctl stop '*.timer' To restart the timers later, you’ll have to remember which ones were running at the time. timers=$(systemctl list-units --type=timer --state=active --no-legend | awk '{print $1}') systemctl stop $timers # ... systemctl start $timers (...
Temporarily stop all systemd timer units
1,461,408,431,000
When I run systemctl list-timers, the last executed dates are far in the future. For example, this is part of the output: $ systemctl list-timers NEXT LEFT LAST PASSED UNIT ACTIVATES Sat 2017-08-19 02:29:16 CE...
Update (2022-08-08): A bugfix has been merged now. Hopefully, the following workaround is no longer needed. Update (2023-01-28): Unfortunately, the bugfix had to be reverted in the 252 release since it caused another regression. Thus, the problem is still open and the workaround below is still relevant. Until the Sys...
"systemctl list-timers" shows last executed dates that are far in the future
1,461,408,431,000
I converted some cron jobs to systemd.timer units and want to send a mail on each job failure and success. The excellent ArchLinux wiki page provides information about this and the setup runs smoothly on failure. Now I want to add an email notification whenever the unit ran successful, but according to systemd.unit th...
You could use ExecStartPost=/bin/systemctl start some-other-service if the Type= is oneshot. Read about the details in man systemd.service To review a full list of directions, use man systemd.directives, which lists all the directions and where they are documented.
systemd run unit on success of another
1,461,408,431,000
I want a script to run minutely, but stop executing it during the nighttime. I tried OnCalendar=*-*-* 05..00:*:00 but that lead to Failed to parse calendar specification, ignoring: *-*-* 05..00:*:00 Timer unit lacks value setting. Refusing Whats wrong here?
You're using an invalid time range. When using BEGIN..END, END must be later than BEGIN. Obviously, 00 is earlier than 05 so 05..00 errors out. You need OnCalendar=*-*-* 05..23:*:00 This will run your script every minute from 05:00 until 23:59. I assume that was your intent. If instead you wanted to run from 05:00 u...
Systemd Timer every minute on specific hours (using a range of values)
1,461,408,431,000
summary: I am trying to set up a systemd timer to regularly backup a directory using the rsync command. I made an rsync command that works when run manually in a terminal, but it doesn't work correctly when run as a systemd timer. detailed explanation: As a simple example, I have following directory tree in /home/trev...
I think I figured this out on my own by reading the manual for systemd services (man systemd.service). The ExecStart= option doesn't directly support shell command lines, which I think is why the brace expansion was not being performed as intended. I got everything to work by passing my rsync command to sh -c in the E...
rsync command doesn't work when run as a systemd service
1,461,408,431,000
Currently, I have this systemd timer (my.timer): [Unit] Description=My Timer [Timer] OnActiveSec=30 Unit=my-subsequent.service [Install] WantedBy=multi-user.target The timer is set to activate upon boot due to: systemctl enable my.timer and systemctl start my.timer. Upon activation, the timer waits for 30 seconds,...
Yes, using After=, and Requires= is the correct approach for ordering services. You may also want to note that if a service specified in Requires fails, so will your service. From the manpage: Often, it is a better choice to use Wants= instead of Requires= in order to achieve a system that is more robust when dealing...
Systemd: How to get a timer to run after a required service?
1,461,408,431,000
How can I reset the left time of a user systemd timer? I have a user systemd service: [Unit] Description=Remind to a take break [Service] ExecStart=/opt/scripts/break_reminder Environment=PATH=/sbin:/bin:/usr/bin:/usr/sbin:/opt/scripts [Install] WantedBy=default.target and a user systemd timer [Unit] Description=Re...
OnUnitActiveSec binds to the last activation time of break_reminder.service. OnUnitActiveSec= Defines a timer relative to when the unit the timer unit is activating was last activated. (systemd.timer manpage) So to reset the left time on break_reminder.timer, you'd need to reset the last activation timestamp of brea...
How to reset left time of user systemd timer
1,461,408,431,000
Are systemd per user systemd-timer running for offline users ? If not, is it possible to allow them to be running for users within a specific group ? Will the target service of the timer be launched correctly as the user it is supposed to run for this way ?
A quick search for [systemd users] found this answer as the first result for you: The systemd user instance is started after the first login of a user and killed after the last session of the user is closed. Sometimes it may be useful to start it right after boot, and keep the systemd user instance running afte...
Run user's systemd timer while they don't have any open session