Welcome to the Linux Foundation Forum!

How to interact with sysfs

bfmcneillbfmcneill Posts: 6
edited June 26 in Cloud Engineer Boot Camp

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

  • coopcoop Posts: 437

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

    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!
    
  • heiko_sheiko_s Posts: 34

    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:

    [email protected]:~$ 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:

    [email protected]:~# 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).

  • coopcoop Posts: 437

    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.

Sign In or Register to comment.