How to interact with sysfs
according to the training:
sysfs is used both to gather information about the system, and modify its behavior while running. In that sense, it resembles /proc, but it is younger than and has adhered to strict standards about what kind of entries it can contain. For example, almost all pseudo-files in /sys contain only one line, or value; there are none of the long entries you can find in /proc.
how do we interact with it though?
Comments
-
For the most part you just look at it -- you use ls, cat, echo, etc just as if they were normal files although they are pseudofiles--they exist only in memory. There are some programmatic interfaces using the "libsysfs" library and there are some utilities in the "sysfsutils" package (names might differ on some distributions). The main tool from that package is "systool"; you can get a brief help messages with:
c8:/tmp>systool -h Usage: systool [<options> [device]] -a Show attributes -b <bus_name> Show a specific bus -c <class_name> Show a specific class -d Show only devices -h Show usage -m <module_name> Show a specific module -p Show path to device/driver -v Show all attributes with values -A <attribute_name> Show attribute value -D Show only drivers -P Show device's parentand you can do man systool for details. This tool is useful if you want to see the whole structure of things. More typically you are just trying to read off one value, such as:
c8:/tmp>cat /sys/block/sdc/queue/rotational 0 c8:/tmp>cat /sys/block/sda/queue/rotational 1 c8:/tmp> Which shows me sda (third disk) is an old fashioned hard drive, and sdc (third disk) is an SSD. Have fun!
2 -
More typically you are just trying to read off one value, such as:
c8:/tmp>cat /sys/block/sdc/queue/rotational 0 c8:/tmp>cat /sys/block/sda/queue/rotational 1 c8:/tmp> Which shows me sda (third disk) is an old fashioned hard drive, and sdc (third disk) is an SSD. Have fun!
I just tried your example cat /sys/block/vda/queue/rotational in a QEMU VM:
heiko@LM20-heiko:~$ cat /sys/block/vda/queue/rotational
1Looks like a HDD, but it's a LVM volume on a NVMe drive. lsblk --discard seems to get it right:
root@LM20-heiko:~# lsblk --discard
NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
vda 512 512B 2G 0
├─vda1 0 512B 2G 0
└─vda2 0 512B 2G 0
├─vgmint-root 0 512B 2G 0
└─vgmint-swap_1 0 512B 2G 0Just wonder if this is expected behavior, or undocumented feature (bug).
0 -
I think it is expected, the VM really doesn't do much with unless you get deeper into how you set it up. Note you can change the value by echo'ing "1" into the sys entry. I actually don' t know enough whether to tell you whether that will make much difference, such as in tuning the parameters for the I/O scheduler.
0
Categories
- All Categories
- 175 LFX Mentorship
- 175 LFX Mentorship: Linux Kernel
- 745 Linux Foundation IT Professional Programs
- 372 Cloud Engineer IT Professional Program
- 168 Advanced Cloud Engineer IT Professional Program
- 73 DevOps IT Professional Program - Discontinued
- 3 DevOps & GitOps IT Professional Program
- 98 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- AI & ML Training
- Blockchain & Decentralized Identity Training
- Cloud & Containers Training
- Cybersecurity Training
- DevOps & Site-Reliability Training
- Linux Kernel Development Training
- Networking Training
- Open Source Best Practice Training
- System Administration Training
- System Engineering Training
- Web & Application Development Training
- 2 LFD103-JP クラス フォーラム
- 4 LFD210-CN Class Forum
- 764 LFD259 Class Forum
- 681 LFS101 Class Forum
- 2 LFS158-JP クラス フォーラム
- 162 LFS207 Class Forum
- 3 LFS207-DE-Klassenforum
- 4 LFS207-JP クラス フォーラム
- 61 LFS241 Class Forum
- 52 LFS242 Class Forum
- 42 LFS243 Class Forum
- 19 LFS244 Class Forum
- 4 LFS250-JP クラス フォーラム
- 166 LFS253 Class Forum
- 19 LFS256 Class Forum
- 1.4K LFS258 Class Forum
- 165 LFS261 Class Forum
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 768 Linux Distributions
- 81 Debian
- 67 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 106 Mobile Computing
- 18 Android
- 73 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 945 Programming and Development
- 310 Kernel Development
- 617 Software Development
- 977 Software
- 369 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)
