6

I have a Seagate 750GB drive.

Parted shows the drive as 750GB

parted /dev/sdc print
Model: ST375064 0AS (scsi)
Disk /dev/sdc: 750GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size   File system  Name     Flags
 1      17.4kB  750GB  750GB  ext3         primary

However, the size entry in /proc/partitions is supposedly in blocks:

cat /proc/partitions
major minor  #blocks  name
8       32  732574584 sdc

Parted says the block size is 512B, blockdev --getbsz /dev/sdc says the block size is 4096.

But... it is clear that /proc/partition is wrongly reporting the device size in KiB rather than blocks.

Can this behavior be depended on across Linux and/or kernel versions? (I need a scriptable and consistent way of finding the size of a block device)

Centos 6.6 with 3.10 kernel.

EDIT I

lsblk -o kname,phy-sec,log-sec,min-io
KNAME PHY-SEC LOG-SEC MIN-IO
sda       512     512    512
sda1      512     512    512
sda2      512     512    512
Danny
  • 235
  • 3
  • 10

2 Answers2

1

parted and lsblk reports the logical/physical block (aka sector) size properly. You can double check this using smartctl -i /dev/sda.

blockdev --getpbsz --getss /dev/sda reports the right information too.

/proc/partitions reports sizes in KiB but it's completely unrelated to the physical block size of the device, instead it's the buffer cache block size.

blockdev --getbsz /dev/sda probably reports the actual IO size ( 4KiB matches kernel page size).

wazoox
  • 6,918
  • 4
  • 31
  • 63
  • 1
    That makes a lot of sense! I didn't see anywhere where `/proc/partitions` "block size" meant something different than disk "block size". Very misleading. So to my core mission: "a scriptable and consistent way of finding the size of a block device", what do you recommend? Call `smartctl` and parse the output? Read `/proc/partitions` and multiply by some number obtained from... where? – Danny Jan 30 '19 at 01:05
  • @Danny it depends in what units you want the result :) If all you care about is KiB, `/proc/partition` is fine and portable across all Linux releases, and bonus, doesn't need any particular program to be installed (smartmontools isn't guaranteed to be present). – wazoox Jan 30 '19 at 21:20
  • 2
    Thanks, very helpful. To summarize, `/proc/partitions` reports size in Kib **NOT** blocks as shown in the header. I'd call that a bug ;-) – Danny Jan 31 '19 at 01:39
  • @Danny Agreed with you that it's very misleading to the point of being a bug. – Hashim Aziz Jun 12 '20 at 20:38
-2

Use /proc/partitions or (c)fdisk. Something that doesn't pretty-print results to be better human-readable.

The blocks in /proc/partitions are always in 512B blocks... newer disks will use 4k blocks internally, but usually emulate 512B blocks to the outside. Some disks will only speak 4k blocks, also on the outside, but /proc/partitions will still print results in 512B blocks.

Sig-IO
  • 1,056
  • 9
  • 11
  • But still doesn't make sense. /proc/partitions tells me my 750GB drive is 732,574,584 "blocks" Multiplying by 512 bytes in no way gives 750GB – Danny Aug 18 '17 at 01:20
  • The information on his disks also clearly lists 512 both physical and logical block size. – Rusty Weber Apr 18 '18 at 18:00
  • 3
    This answer is incorrect. A block size of 1024 is often (if not always) used for the numbers in `/proc/partitions`. – kasperd Jan 27 '19 at 13:16