sysfs is a virtual filesystem in the Linux kernel, normally mounted at /sys, that presents the kernel’s internal device model as a tree of directories, attribute files and symbolic links. Every device, driver, bus, class and many kernel subsystems appear there, so administrators and tools can read hardware state and change kernel settings with ordinary file operations.
In the Linux filesystem landscape, sysfs is related to procfs and tmpfs because none of them store data on disk. Its purpose is narrower and stricter than that of /proc: it exists to describe kernel objects and their relationships, with one value per file, which makes it the main data source for udev, lsblk and power management tools.
How sysfs exposes the kernel device model
sysfs works by mapping kernel objects called kobjects to directories, their attributes to files and their relationships to symbolic links. When a driver registers a device, the kernel creates the matching directory automatically, and when the device disappears, the directory disappears with it. No file content is stored anywhere: each read triggers a kernel callback that formats the current value on demand.
The central design rule is one value per file. An attribute such as /sys/class/net/eth0/mtu contains a single number in plain text, which makes the interface easy to use from shell scripts with cat and echo. Writable attributes accept a new value through a write call, which the kernel validates before applying.
sysfs is mounted early during boot, typically by the init system, with a command equivalent to mount -t sysfs sysfs /sys. It has no backing block device, so it never appears in lsblk output and does not need an entry in fstab on modern distributions. The kernel option behind it is CONFIG_SYSFS, which practically every general-purpose kernel enables.
Main directories under /sys
The top level of /sys organizes the same kernel objects from several different viewpoints, which is why one device is reachable through more than one path. The following table describes the directories administrators use most.
| Directory | What it contains | Typical use |
|---|---|---|
| /sys/devices | The real device hierarchy, ordered by physical topology | Canonical location of every device |
| /sys/class | Devices grouped by function, such as net, block or backlight | Finding a device by its role |
| /sys/bus | Buses such as pci, usb and i2c with their devices and drivers | Binding and unbinding drivers |
| /sys/block | Links to block devices such as disks and partitions | Queue settings and disk statistics |
| /sys/module | Loaded kernel modules and their parameters | Reading or adjusting module options |
| /sys/fs | Filesystem-specific controls, including cgroup | Tuning ext4, Btrfs or control groups |
| /sys/firmware | Firmware data such as ACPI tables and EFI variables | Inspecting platform firmware |
| /sys/kernel | Kernel-wide settings and debug mount points | Tracing and memory management controls |
Entries under /sys/class and /sys/block are mostly symbolic links into /sys/devices. Following such a link with readlink -f reveals the full physical path, for example the PCI controller and USB port behind a network adapter.
Reading and writing attributes
Attributes in sysfs are read with ordinary file commands and changed by writing a value as root. Changes take effect immediately but are not persistent across reboots, because sysfs is rebuilt from kernel state at every boot. Persistent settings belong in udev rules, systemd units or tools such as sysfsutils.
The table shows representative attributes with their purpose and access mode.
| Attribute path | Meaning | Access |
|---|---|---|
| /sys/class/net/eth0/address | MAC address of the interface | Read-only |
| /sys/block/sda/queue/scheduler | Active I/O scheduler for the disk | Read and write |
| /sys/class/power_supply/BAT0/capacity | Battery charge in percent | Read-only |
| /sys/class/backlight/*/brightness | Display backlight level | Read and write |
| /sys/devices/system/cpu/cpu1/online | Whether a CPU core is active | Read and write |
| /sys/module/*/parameters/* | Parameters of a loaded module | Depends on the module |
Permissions on sysfs files are set by the kernel, typically 0444 for read-only and 0644 for writable attributes, and udev rules can relax them for specific groups. A failed write usually returns EINVAL when the value is outside the accepted range.
sysfs compared with procfs and other virtual filesystems
sysfs differs from procfs mainly in scope and structure: procfs historically mixed process information with assorted kernel data in free-form files, whereas sysfs was introduced in the 2.6 kernel series to give devices a strict, typed hierarchy. The comparison below places sysfs among related virtual filesystems.
| Filesystem | Usual mount point | Primary content | Format of files |
|---|---|---|---|
| sysfs | /sys | Devices, drivers, buses, modules | One value per file |
| procfs | /proc | Processes and legacy kernel data | Often multi-line, free-form |
| devtmpfs | /dev | Device nodes for access to hardware | Character and block nodes |
| tmpfs | /tmp, /run | Temporary files in memory | Ordinary user data |
| debugfs | /sys/kernel/debug | Developer and debugging interfaces | No stability guarantee |
| configfs | /sys/kernel/config | Objects created by user space | One value per file |
A practical rule follows from this split: sysfs describes devices, while devtmpfs provides the device nodes used to send data to them. Reading /sys/block/sda/size returns the disk size, but reading data from the disk requires /dev/sda.
Stability, limitations and common mistakes
Not every sysfs file is a stable interface. The kernel documents attributes in the ABI documentation tree, which sorts them into stable, testing, obsolete and removed categories, and scripts should rely on stable attributes whenever possible. Paths under /sys/devices also depend on hardware topology, so they can change when a card moves to another slot.
- Hardcoding physical paths: use
/sys/classlinks or udev properties instead of full/sys/devicespaths. - Expecting persistence: values written by hand are lost at reboot unless a udev rule or service applies them again.
- Exposing sysfs in containers: container runtimes usually mount
/sysread-only to prevent containers from changing host settings. - Parsing with assumptions: some attributes contain lists in brackets, such as the active scheduler shown as
[mq-deadline]. - Polling instead of waiting: some attributes support
poll()notifications, but most changes are better tracked through udev events.
Understanding it simply
sysfs is like a control panel for the hardware, presented as folders and small text files. Each folder stands for a part of the computer, such as a disk, a network card or a battery, and each file holds one fact about it, such as its size or charge level.
Nothing in these folders is stored on disk. The system creates the answers at the moment someone looks, and some files can also be changed to adjust how a device behaves.
Applied in practice
An administrator of a database server notices uneven latency on a solid-state drive. Running cat /sys/block/nvme0n1/queue/scheduler shows [none] mq-deadline kyber, which confirms that no I/O scheduler is active. For a test, the administrator writes mq-deadline into the same file as root, and the change applies instantly, without a reboot.
After measuring the result for a day, the administrator decides to keep the original setting and also checks /sys/class/nvme/nvme0/model and firmware_rev to record the drive model and firmware version in the incident report. Because manual sysfs writes disappear at reboot, any setting the team wants to keep is placed in a udev rule that applies it each time the device appears.