How to get hard disk information from /proc and/or /sys

22,125

Solution 1

This is Answer

   cat /sys/block/sda/size

Above file will returns some number like 312581808, then this number need to multiply by 512 standard block size then u ll get long int value in bytes, then u can convert to GB.

Solution 2

Refer kernel docs for block device subsystem. stat.txt is for block device I/O stats.

Kernel/userspace ABI docs is also useful, see sysfs-block for comprehensive list of available sysfs entries.

You can also get block device capacities from /proc/partitions.

Share:
22,125

Related videos on Youtube

shas
Author by

shas

this website is very useful

Updated on September 18, 2022

Comments

  • shas
    shas almost 2 years

    How can I get hard disk capacity, usage, etc. using the /proc or /sys filesystems?

    If it is possible, please tell me which file(s) I need to process to get that information.

  • shas
    shas almost 9 years
    from /proc/partitions file difficult to calculate, using /sys/block/sda/size we can get it in single line output.
  • Adam Chance
    Adam Chance almost 7 years
    Is this the usage, availability, or total capacity?
  • Zayne S Halsall
    Zayne S Halsall about 5 years
    this is only capacity... question also asks for usage... so presumably not available?