Kahibaro
Discord Login Register

1.5.2.7 `/sys`

Understanding `/sys`

/sys is a special, virtual filesystem that exposes information about your hardware and certain kernel features. It is usually mounted as a sysfs filesystem and is managed directly by the kernel.

Unlike normal directories, files in /sys do not live on disk. They are created and updated by the kernel in real time. Reading them queries the kernel; writing to some of them can change kernel behavior or hardware settings.

This chapter focuses on what makes /sys unique and how to safely explore it as a beginner.

Key characteristics of `/sys`

Common top‑level areas in `/sys`

Here are some of the most important subdirectories you’ll see under /sys and what they represent. Names and exact structure can vary slightly between systems, but the concepts are consistent.

`/sys/devices`

Represents actual hardware devices as the kernel sees them: PCI devices, USB devices, CPU cores, memory blocks, and more.

Examples of things you might see inside:

You’ll often use /sys/devices indirectly via symbolic links from other directories (like /sys/class).

`/sys/class`

Groups devices by type (class), not by physical location. Devices that belong to the same functional class are listed together here, even if they are attached via different hardware buses.

Common subdirectories include:

Each entry here usually points (via a symlink) back to the corresponding device in /sys/devices.

`/sys/bus`

Groups devices based on the bus or connection type used to communicate with them.

Examples:

Each bus directory contains lists of devices and drivers associated with that bus.

`/sys/block`

Lists block devices, such as hard drives, SSDs, and sometimes partitions.

You’ll see names like:

Inside each block device directory, you can view attributes like size, queue settings, and sometimes performance tuning options.

`/sys/firmware`

Exposes interfaces to firmware‑related features and configuration, such as:

Modifying some of these values can affect power behavior, boot options, and more, so it should be handled with care.

`/sys/power`

Controls and reports system‑wide power management information. Common entries include:

Regular users typically only read these files; writing is usually reserved for root and can immediately change power behavior.

`/sys/kernel`

Contains tunable parameters and information about different kernel subsystems.

Common parts include:

Many of these settings are used for debugging or advanced tuning.

Typical use cases for `/sys` (for beginners)

Even as a beginner, you can safely inspect /sys to better understand your system. Here are a few practical, read‑only examples.

Checking CPU information

CPU cores are usually visible under /sys/devices/system/cpu:

ls /sys/devices/system/cpu
cat /sys/devices/system/cpu/cpu0/online

You might see directories like cpu0, cpu1, etc. Inside each, you can find attributes describing that core.

Inspecting network interfaces

Network interfaces appear under /sys/class/net:

ls /sys/class/net
cat /sys/class/net/eth0/operstate
cat /sys/class/net/eth0/address

Replace eth0 with the actual interface name on your system (such as enp3s0, wlan0, etc.).

Viewing disk device attributes

Block devices are listed in /sys/block:

ls /sys/block
cat /sys/block/sda/size
cat /sys/block/sda/queue/rotational

The size value is in 512‑byte sectors; multiply it by $512$ to get the size in bytes.

Exploring input devices

Input devices such as keyboards and mice show up under /sys/class/input:

ls /sys/class/input
ls -l /sys/class/input/event0

These are often mapped to /dev/input/event* devices.

Reading vs writing in `/sys`

Always:

  1. Read the current value first.
  2. Research any attribute before attempting to change it.
  3. Avoid experimenting as root on a system you care about.

Relationship of `/sys` to other virtual filesystems

/sys is part of a family of virtual kernel interfaces:

They complement each other: /proc is more process‑ and system‑info‑oriented, while /sys is more device‑ and subsystem‑oriented, with more structured and fine‑grained control.

Summary

Views: 114

Comments

Please login to add a comment.

Don't have an account? Register now!