In addition to /proc, the kernel also exports information to another virtual file system called sysfs. sysfs is used by programs such as udev to access device and device driver information. The creation of sysfs helped clean up the proc file system because much of the hardware information has been moved from proc to sysfs.

The sysfs file system is mounted on /sys. The top-level directories are shown. Following is a brief description of some of these directories:

 

/sys/block

 

This directory contains entries for each block device in the system. Symbolic links point to the physical device that the device maps to in the physical device tree. For example, attributes for the sda disks reside in the following directory:

# ls -l /sys/block/sda/
total 0
-r--r--r-- 1 root root 4096 Mar 24 13:03 alignment_offset
lrwxrwxrwx 1 root root    0 Mar 24 13:04 bdi -> ../../../../../../../../virtual/bdi/8:0
-r--r--r-- 1 root root 4096 Mar 24 13:03 capability
-r--r--r-- 1 root root 4096 Mar 24 13:03 dev
lrwxrwxrwx 1 root root    0 Mar 24 13:04 device -> ../../../0:0:0:0
-r--r--r-- 1 root root 4096 Mar 24 13:03 discard_alignment
-r--r--r-- 1 root root 4096 Mar 24 13:03 events
-r--r--r-- 1 root root 4096 Mar 24 13:03 events_async
-rw-r--r-- 1 root root 4096 Mar 24 13:03 events_poll_msecs
-r--r--r-- 1 root root 4096 Mar 24 13:03 ext_range
drwxr-xr-x 2 root root    0 Mar 24 13:04 holders
-r--r--r-- 1 root root 4096 Mar 24 13:03 inflight
drwxr-xr-x 2 root root    0 Mar 24 13:04 integrity
drwxr-xr-x 2 root root    0 Mar 24 13:04 power
drwxr-xr-x 3 root root    0 Mar 24 13:04 queue
-r--r--r-- 1 root root 4096 Mar 24 13:03 range
-r--r--r-- 1 root root 4096 Mar 24 13:03 removable
-r--r--r-- 1 root root 4096 Mar 24 13:03 ro
-r--r--r-- 1 root root 4096 Mar 24 13:03 size
drwxr-xr-x 2 root root    0 Mar 24 13:04 slaves
-r--r--r-- 1 root root 4096 Mar 24 13:03 stat
lrwxrwxrwx 1 root root    0 Mar 24 13:04 subsystem -> ../../../../../../../../../class/block
-rw-r--r-- 1 root root 4096 Mar 24 13:03 uevent

 

/sys/bus

 

This directory contains subdirectories for each physical bus type supported in the kernel. Each bus type has two subdirectories: devices and drivers. The devices directory lists devices discovered on that type of bus. The drivers directory contains directories for each device driver registered with the bus type. Driver parameters can be viewed and manipulated. For example, to list the drivers for the virtual devices, enter:

# ls -lR /sys/bus/xen/drivers
/sys/bus/xen/drivers:
total 0
drwxr-xr-x. 2 root root 0 Mar 24 13:37 vbd
drwxr-xr-x. 2 root root 0 Mar 24 13:37 vif

/sys/bus/xen/drivers/vbd:
total 0
--w-------. 1 root root 4096 Mar 24 13:40 bind
lrwxrwxrwx. 1 root root    0 Mar 24 13:40 module -> ../../../../module/xen_blkfront
--w-------. 1 root root 4096 Mar 24 13:37 uevent
--w-------. 1 root root 4096 Mar 24 13:40 unbind
lrwxrwxrwx. 1 root root    0 Mar 24 13:40 vbd-51792 -> ../../../../devices/vbd-51792
lrwxrwxrwx. 1 root root    0 Mar 24 13:40 vbd-768 -> ../../../../devices/vbd-768

/sys/bus/xen/drivers/vif:
total 0
--w-------. 1 root root 4096 Mar 24 13:40 bind
lrwxrwxrwx. 1 root root    0 Mar 24 13:40 module -> ../../../../module/xen_netfront
--w-------. 1 root root 4096 Mar 24 13:37 uevent
--w-------. 1 root root 4096 Mar 24 13:40 unbind
lrwxrwxrwx. 1 root root    0 Mar 24 13:40 vif-0 -> ../../../../devices/vif-0

 

/sys/class

 

This directory contains every device class registered with the kernel. Device classes describe a functional type of device. Examples include input devices, network devices, and block devices.

 

/sys/devices

 

This directory contains the global device hierarchy of all devices on the system. This directory also contains a platform directory and a system directory. The platform directory contains peripheral devices specific to a particular platform such as device controllers. The system directory contains non-peripheral devices such as CPUs and APICs.

 

/sys/firmware

 

This directory contains subdirectories with firmware objects and attributes.

 

/sys/module

 

This directory contains subdirectories for each module that is loaded into the kernel, for example:

# ls /sys/module/xen*
/sys/module/xen_blkfront:
coresize  drivers  holders  initsize  initstate  notes  parameters  refcnt  rhelversion  sections  srcversion  taint  uevent

/sys/module/xen_netfront:
coresize  drivers  holders  initsize  initstate  notes  parameters  refcnt  rhelversion  sections  srcversion  taint  uevent

 

/sys/power

 

The system power state can be controlled from this directory. The disk attribute controls the method by which the system suspends to disk. The state attribute allows a process to enter a low power state.

 

The sysctl Utility

 

The sysctl utility can also be used to view or modify values to writable files in the /proc/sys directory. To view the current kernel settings, enter:

# sysctl -a
abi.vsyscall32 = 1
crypto.fips_enabled = 0
debug.exception-trace = 1
...

 

This is the same information seen if each of the files were viewed individually, for example: 

# cat /proc/sys/abi/vsyscall32
1

 

The echo command can be used to assign values to writable files in /proc/sys:

# echo 1 > /proc/sys/net/ipv4/ip_forward

 

The equivalent sysctl command follows, displaying the result of the change immediately:

# sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1

 

Changes made by using both echo and sysctl are lost when the system is rebooted. To preserve custom settings, add them to the /etc/sysctl.conf file. Values added to this file take effect each time the system boots.

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)