Using sgdisk
You can use sgdisk
to print detailled information:
sgdisk --print <device>
[…]
Disk /dev/sdb: 15691776 sectors, 7.5 GiB
Logical sector size: 512 bytes
[…]
When you multiply the number of sectors with the sector size you get the exact byte count that should match the output of dd
.
Using /sys
directly
You can also get those numbers directly from /sys
:
Number of sectors: /sys/block/<device>/size
Sector size: /sys/block/<device>/queue/logical_block_size
Here's a way of calculating the size:
sectors=$(cat /sys/block/sdb/size)
bs=$(cat /sys/block/sdb/queue/logical_block_size)
echo $(( $sectors * $bs )) --- OR --- echo "$sectors * $bs" | bc
Using udisks
udisks
outputs the information directly. It is reported as size
:
udisks --show-info <device> | grep size
Using blockdev
blockdev --getsize64 <device>
From /proc/partitions
grep ' sdb$' /proc/partitions
(number expressed in kibibytes).
blockdev --getsize64 /dev/ice
– frostschutz Jan 9 '14 at 12:39