sysfs
sysfs is a virtual filesystem (virtual means it takes up no disk space). It exports information about kernel devices, drivers, and other subsystems to user space and allows their configuration. It is generated by the kernel and always mounted at /sys.
Installation
Kernel
sysfs will usually be activated by default. The kernel option will only be visible if Configure standard kernel features (expert users)
is enabled, and even then may not be able to be changed:
File systems --->
Pseudo filesystems --->
-*- sysfs file system support
Usage
Use cat to read the information. For example, to output the charging level of a battery:
user $
cat /sys/class/power_supply/BAT0/status
Get the device name by listing the /sys/class/net directory contents using ls -al or the tree command (provided by the app-text/tree package):
user $
tree /sys/class/net
/sys/class/net/ ├── enp2s14 -> ../../devices/pci0000:00/0000:00:1e.0/0000:02:0e.0/net/enp2s14 ├── lo -> ../../devices/virtual/net/lo ├── sit0 -> ../../devices/virtual/net/sit0 └── wlp8s0 -> ../../devices/pci0000:00/0000:00:1c.0/0000:08:00.0/net/wlp8s0
sysfs can be used to set values at runtime. For example, the echo command can be used to enable system suspension:
root #
echo mem > /sys/power/state
To set values at boot time create a local.d script.
See also
- procfs — a virtual filesystem, which means - it resides in RAM.
It can be used to show and change system and process information.
- tmpfs — a virtual filesystem created to store files in dynamic (volatile) memory.