Welcome to the Linux Foundation Forum!

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?

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 916

    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:

    1. c8:/tmp>systool -h
    2. Usage: systool [<options> [device]]
    3. -a Show attributes
    4. -b <bus_name> Show a specific bus
    5. -c <class_name> Show a specific class
    6. -d Show only devices
    7. -h Show usage
    8. -m <module_name> Show a specific module
    9. -p Show path to device/driver
    10. -v Show all attributes with values
    11. -A <attribute_name> Show attribute value
    12. -D Show only drivers
    13. -P Show device's parent

    and 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:

    1. c8:/tmp>cat /sys/block/sdc/queue/rotational
    2. 0
    3. c8:/tmp>cat /sys/block/sda/queue/rotational
    4. 1
    5. c8:/tmp>
    6.  
    7. Which shows me sda (third disk) is an old fashioned hard drive, and sdc (third disk) is an SSD. Have fun!
  • Posts: 99

    More typically you are just trying to read off one value, such as:

    1. c8:/tmp>cat /sys/block/sdc/queue/rotational
    2. 0
    3. c8:/tmp>cat /sys/block/sda/queue/rotational
    4. 1
    5. c8:/tmp>
    6.  
    7. 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
    1

    Looks 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 0

    Just wonder if this is expected behavior, or undocumented feature (bug).

  • Posts: 916

    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.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training