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

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.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

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.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply