sysfs is a virtual filesystem normally mounted at /sys. It represents kernel objects and their relationships through directories, symbolic links, and small attribute files. Device-discovery tools and managers use it to understand the kernel's current device model.
Devices · Lesson 4
sysfs
Learn how sysfs exposes the Linux kernel's live device, driver, bus, and class model under `/sys`.
Navigating the Device Model
Important top-level views include:
/sys/devices/: the physical and logical device hierarchy/sys/class/: devices grouped by functional class, such as block or network/sys/bus/: buses, their devices, and drivers/sys/block/: a convenient view of block devices/sys/dev/: links indexed by character or block major and minor numbers
Many entries outside /sys/devices are symbolic links into the canonical hierarchy. Resolve a link with readlink -f when you need the actual parent path:
$ readlink -f /sys/class/block/sda
The example name may not exist on systems using other storage interfaces.
Which sysfs subtree contains the kernel's primary device hierarchy?
Reading Attributes
Attribute files expose individual values or controls. For a block device, examples can include:
$ cat /sys/class/block/sda/dev
8:0
$ cat /sys/class/block/sda/ro
0
$ cat /sys/class/block/sda/size
1953525168
dev reports the major and minor device numbers. ro reports the block device's read-only flag. For Linux block devices, size is conventionally expressed in 512-byte sectors, regardless of the device's physical sector size. Always consult the kernel ABI documentation for a specific attribute's units and meaning.
What does a block device's sysfs dev attribute normally contain?
Relating `/sys` and `/dev`
/dev contains nodes applications open for device I/O. /sys exposes object relationships, properties, status, and selected controls. A block node such as /dev/sda can be matched to /sys/dev/block/8:0, which resolves to the relevant sysfs object.
The two interfaces complement each other. Neither contains a complete standalone inventory of all hardware facts, and a device can disappear while it is being inspected.
Which statement correctly distinguishes /sys from /dev?
Writing Attributes Safely
Some sysfs attributes are writable and can change power state, driver binding, queue behavior, device authorization, LEDs, or other live controls. A successful text write can have immediate hardware or service effects; it is not equivalent to editing a persistent configuration file.
Read the documented ABI and current value, identify how the setting should be made persistent, and test only on an authorized system. Never recursively edit permissions or write guessed values across /sys.
Why can writing to a sysfs attribute be operationally significant?
Use Explore Hardware Devices in Linux to navigate sysfs read-only and correlate it with device nodes.
Lesson complete
You finished sysfs
You can now use sysfs as a structured view of live kernel objects.
Navigate device, class, bus, block, and device-number views.
Read one documented attribute at a time with correct units.
Correlate sysfs objects with
/devnodes.Treat writable attributes as live control interfaces.
Keep your learning progress
Create a free account to save this lesson and continue learning on any device.
Create a free account