/sys Filesystem

/sys is a virtual filesystem where the Linux kernel exports its internal state as files. Every piece of hardware, every kernel subsystem, and every device driver has a directory here. Read a file to query a setting. Write to it to change behavior — no reboot required, no config file needed.

What Is sysfs?

How is /sys different from /proc? /proc was the original Linux "kernel info as files" interface — it's messier, less organized, and mixes process information with hardware info. /sys (sysfs) was introduced with the 2.6 kernel as a clean replacement for hardware/device information. /sys is strictly hierarchical and organized by kernel subsystem. Both exist today, but /sys is the right place for device and driver configuration.
$ ls /sys/ block/ bus/ class/ dev/ devices/ firmware/ fs/ kernel/ module/ power/ # Key directories: # /sys/block/ ← block devices (sda, nvme0n1) # /sys/bus/ ← buses (pci, usb, i2c, platform) # /sys/class/ ← device classes (net, input, power_supply) # /sys/devices/ ← all devices in hardware tree # /sys/module/ ← loaded kernel modules and their params

/sys/block — Disk Configuration

# Every block device has a directory ls /sys/block/ # sda sdb nvme0n1 loop0 loop1 ... # Disk queue settings (most important for performance) ls /sys/block/sda/queue/ # scheduler ← I/O scheduler # nr_requests ← queue depth # read_ahead_kb ← read-ahead size # rotational ← 1=HDD, 0=SSD # max_sectors_kb ← max I/O size per request # Read scheduler cat /sys/block/sda/queue/scheduler # mq-deadline [bfq] none # Check if SSD or HDD cat /sys/block/sda/queue/rotational # 1 = spinning disk (HDD) # 0 = solid state (SSD) # Disk size in 512-byte sectors cat /sys/block/sda/size # 1953525168 ← * 512 = ~1TB # Partition info ls /sys/block/sda/ # dev queue sda1 sda2 sda3 size stat ... cat /sys/block/sda/stat # reads read_merges read_sectors read_ms writes write_merges ... # ← I/O statistics (same data as /proc/diskstats)

/sys/class/net — Network Interface Config

# List network interfaces ls /sys/class/net/ # eth0 lo wlan0 docker0 ... # Interface speed cat /sys/class/net/eth0/speed # 1000 ← 1Gbps # MAC address cat /sys/class/net/eth0/address # 00:11:22:33:44:55 # TX queue length cat /sys/class/net/eth0/tx_queue_len # 1000 # Carrier (link up/down) cat /sys/class/net/eth0/carrier # 1 = link up, 0 = link down # Bring interface up/down via /sys: echo 1 > /sys/class/net/eth0/flags # (use 'ip link' instead in practice)

/sys/class/power_supply — Battery & Power

# Laptop battery info ls /sys/class/power_supply/ # AC BAT0 BAT1 cat /sys/class/power_supply/BAT0/capacity # 87 ← 87% charge cat /sys/class/power_supply/BAT0/status # Discharging cat /sys/class/power_supply/BAT0/energy_full # 50000000 ← microwatt-hours cat /sys/class/power_supply/BAT0/energy_now # 43500000 ← current charge in microwatt-hours # CPU frequency scaling ls /sys/devices/system/cpu/cpu0/cpufreq/ # scaling_governor scaling_cur_freq scaling_min_freq scaling_max_freq cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor # powersave # Switch to performance mode: echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

/sys/module — Kernel Module Parameters

# See loaded modules ls /sys/module/ # bluetooth ext4 usbcore nvidia ... # Module parameters (can change without unloading module!) ls /sys/module/usbcore/parameters/ # autosuspend usbfs_memory_mb ... cat /sys/module/usbcore/parameters/autosuspend # 2 ← USB autosuspend timeout in seconds # Change parameter live: echo -1 > /sys/module/usbcore/parameters/autosuspend # disable autosuspend # NVMe module params cat /sys/module/nvme/parameters/io_timeout # 30 ← I/O timeout in seconds

Controlling Hardware Directly

sysfs lets you control hardware without any program — just write to files:

# Control LEDs (Raspberry Pi, servers with front panel) ls /sys/class/leds/ # input2::capslock input2::numlock ... cat /sys/class/leds/input2::capslock/brightness # 0 echo 1 > /sys/class/leds/input2::capslock/brightness # turn on # Raspberry Pi GPIO (older kernels): echo 17 > /sys/class/gpio/export # claim GPIO 17 echo out > /sys/class/gpio/gpio17/direction # set as output echo 1 > /sys/class/gpio/gpio17/value # set high (3.3V) # CPU core online/offline (disable a core): echo 0 > /sys/devices/system/cpu/cpu3/online # take cpu3 offline echo 1 > /sys/devices/system/cpu/cpu3/online # bring it back

Frequently Asked Questions

What will I learn here?

This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.

How should I use this page?

Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.

What should I read next?

Use the navigation below to continue to the next lesson or explore related topics.