0

I know usually the sector size is 512 B but some drives use 4 KiB (advanced format).

How can I check which one is used by a drive? Is the sector size somewhere stored on the drive - e.g. in the MBR or GUID-partitiontable?

I'm interested in solutions for Windows 10 and Linux. It would be also great to know how to read it with a Python script or a hex editor.

  • Is the sector size somewhere stored on the drive Yes, but no. 4k drives may contain 512b in that place. You must ask physical characteristics of HDD (but in this case 4k drive may be treated as 512b drive by BIOS/driver too). – Akina Sep 3 '19 at 11:25
1

Sectors are managed by the drive's controller, so you'll need to check what the drive reports to the OS through the various "inquiry" commands (such as SCSI READ CAPACITY).

The sector size isn't accessible through normal read/write operations, because... you need to know the sector size before you can issue the read/write operations in the first place.

  • On Linux, you can use lsblk -t to see the topology parameters known by the kernel; the same information can be retrieved either directly from files in /sys/class/block/sda/queue, or through libudev (all sysfs files are 'attributes' in libudev).

  • You can also check fdisk -l for the "Sector size" line; it uses ioctl(BLKIOMIN), ioctl(BLKPBSZGET), and ioctl(BLKSSZGET) to retrieve this information from the kernel.

  • The most direct approach (and the one requiring the most privileges) is to send your own commands to the disk, e.g. for SCSI and ATA disks sg_readcap will report "Logical block length" and "Logical blocks per physical block exponent".

Note that some USB-SATA adapters send wrong information in these fields.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.