/dev lets you use a device. /sys lets you learn about it. The /sys directory is the mount point of sysfs, a virtual filesystem in which the kernel presents devices, drivers and related objects.
A filesystem made by the kernel
Nothing in /sys is stored on disk. The kernel produces the contents when you read them.
findmnt /sysTARGET SOURCE FSTYPE OPTIONS
/sys sysfs sysfs rw,nosuid,nodev,noexec,relatimeThe main directories
ls /sysblock bus class dev devices firmware fs kernel module power/sys/devicesis the device tree, arranged by how things are connected./sys/classgroups devices by function, such asnetortty./sys/busgroups them by bus, such aspciorusb./sys/blocklists block devices./sys/modulehas information about kernel modules.
Many entries in class and block are symbolic links into /sys/devices, so one device can be reached in several ways.
One value per file
An attribute file normally holds a single value as text, so cat is enough. Replace eth0 with an interface that exists on your system.
ls /sys/class/net
cat /sys/class/net/eth0/address
cat /sys/class/net/eth0/mtu
cat /sys/class/net/eth0/operstateeth0 lo
52:54:00:12:34:56
1500
upFor disks:
cat /sys/block/sda/size
cat /sys/block/sda/queue/rotational976773168
0The size value counts 512 byte sectors, whatever the real sector size of the drive. A rotational value of 0 means the kernel treats it as a non spinning device. Virtual disks may not report this accurately.
Writing changes the kernel
Some attributes are writable. Writing one usually changes behaviour immediately and needs root. For example, on a laptop with a backlight entry:
ls /sys/class/backlight
echo 200 | sudo tee /sys/class/backlight/intel_backlight/brightnessThe directory name depends on your hardware, and many machines have none. Use tee because a plain sudo echo 200 > file performs the redirection as your normal user. A value written this way does not by itself persist across reboots.
To collect the properties of a device in one go, udevadm info reads from sysfs and the udev database. For permission basics, see the permissions lab.
Try it
- Run
ls -l /sys/class/netand see where the links point. - Read the
addressandmtufiles of one interface. - Run
ls /sys/block, then read thesizefile for one entry and multiply by 512. - Run
ls /sys/module | headto see modules known to the kernel.
Only read files while exploring. Do not write to attributes you do not understand.
Check your understanding
Exploring sysfs
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.