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
.
Related videos on Youtube
Comments
-
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 almost 9 yearsfrom /proc/partitions file difficult to calculate, using /sys/block/sda/size we can get it in single line output.
-
Adam Chance almost 7 yearsIs this the usage, availability, or total capacity?
-
Zayne S Halsall about 5 yearsthis is only capacity... question also asks for usage... so presumably not available?