4. sysfs

The sysfs filesystem was introduced to provide a better way to manage devices on a Linux system, a task for which the /dev directory was not fully equipped. Understanding what is /sys in Linux is key to modern system administration.

What is sysfs?

sysfs is a virtual filesystem, typically mounted at /sys, that exports information about kernel objects, hardware devices, and drivers from the kernel's device model to userspace. Unlike files on a physical disk, the files and directories within /sys are generated on the fly and represent the current state of the sys system.

The Role of the linux /sys Directory

The primary purpose of the linux /sys directory is to provide a structured view of all the devices on your system. It contains detailed information such as the manufacturer and model, where the device is plugged in, its current state, and its position in the device hierarchy.

The files you see here are not device nodes like those in /dev. You don't directly interact with the device itself through /sys; rather, you use it to view information and manage the device's attributes.

sysfs vs. /dev

While /sys and /dev both relate to devices, they serve different functions.

  • The /dev directory provides device nodes, which are special files that allow programs to access the devices themselves.
  • The /sys filesystem is used to view information about and manage the devices. It exposes the underlying device model.

For example, let's inspect the contents of a block device directory within /sys:

pete@icebox:~$ ls /sys/block/sda
alignment_offset  discard_alignment  holders   removable  sda6       trace
bdi               events             inflight  ro         size       uevent
capability        events_async       power     sda1       slaves
dev               events_poll_msecs  queue     sda2       stat
device            ext_range          range     sda5       subsystem

This output shows various attributes and subdirectories related to the sda hard drive, offering a much more detailed view than /dev/sda alone.

Sign in to save your learning progress

Sign in

Exercises

Practice makes perfect! Here are some hands-on labs to reinforce your understanding of hardware device exploration in Linux:

  1. Explore Hardware Devices in Linux - Practice identifying and inspecting hardware devices within a Linux environment, similar to how the /sys filesystem provides device information.

This lab will help you apply the concepts of understanding system hardware and its representation in Linux, building confidence with device exploration.

Quiz

What directory is used to view detailed information on devices? Please answer in English.