How can I find out the size of a block device, such as /dev/sda? Running ls -l gives no useful information.
|
|
migrated from stackoverflow.com Oct 18 '12 at 16:39
|
Since the kernel already scanned the partition layouts when the block device came into service, why not ask it directly? $ cat /proc/partitions major minor #blocks name 8 16 390711384 sdb 8 17 514079 sdb1 8 18 390194752 sdb2 8 32 976762584 sdc 8 33 514079 sdc1 8 34 976245952 sdc2 8 0 156290904 sda 8 1 514079 sda1 8 2 155774272 sda2 8 48 1465138584 sdd 8 49 514079 sdd1 8 50 1464621952 sdd2 |
|||||
|
|
|
|
|||
|
|
|
This simple code. Couldn't find any documentation, but does the trick nicely:
|
|||
|
How about:
This will give you a list of all your disks with their respective capacity, usage, and more. |
|||
|
|
will give you the size in KB (first number) as well as the space used (second number) and space available (third number) |
|||||
|
|
The blockdev(8) has a different answer? Options --getsz and deprecated --getsize are not the same. BLKSSZGET (blockdev --getss) is for physical sector size and BLKBSZGET (blockdev --getbsz) is for logical sector size.
|
|||
|
|
First, my thanks to all who contributed. I learned a few useful things. Still, my experience is that most of these answers are somewhat
incomplete, at least where CD and DVDs are concerned,
notably regarding whether they are available to normal users
rather than restricted to the superuser. Commands intended for the superuser can always be accessed by a normal
user by prefixing them with Many may work, for a normal user, for a DVD on the DVD drive, even when it is not mounted, while they will not work for a hard disk (again when invoked as normal user). For example The same is true of other examples (as non-root, normal user)
This works for the DVD drive, here called Similarly, as normal user, the command
will give the size of a DVD on device The command
|
||||
|
|
|
No need for ioctl in C. Just seek to the end of the file and get the size (in bytes) that way:
|
|||
|
|
|
Is The ioctl BLKGETSIZE has the same problem as it is in units of 512 rather than BLKSSZGET. BLKGETSIZE64 solves this ambiguity. The real block count is BLKGETSIZE64/BLKSSZGET.
See http://lkml.indiana.edu/hypermail/linux/kernel/0105.2/0744.html |
|||||
|
|
There is an EMC utility called Try it out. ftp://ftp.emc.com/pub/symm3000/inquiry/ Here is a brief description of what it does: http://slashzeroconf.wordpress.com/2009/02/09/emc-inq-utility/ |
||||
|
|