Does the MBR of the disk contain this information and therefore when i call a command like fdisk, a kernel level code eventually runs and reads it from a specific part in MBR? If so, which part of it? What offset?
If it's not in the MBR, then how can these types of commands find it? They can't be reading it from the beginning of a partition considering they need to calculate the starting address of that partition and they need the sector size to do so, don't they?
How are commands like fdisk
implemented to find this information? Where do they read it from?
Best Answer
A device’s sector size isn’t stored in the MBR.
User space commands such as
fdisk
use theBLKBSZGET
andBLKSSZGET
ioctl
s to retrieve the sector sizes from disks. Thoseioctl
s are handled by drivers in the kernel, which retrieve the relevant information from the drives themselves.(There isn’t much documentation about the relevant
ioctl
s; you need to check the kernel source code.)You can see the relevant information using other tools which query drives directly, for example
hdparm
. On a small SSD,hdparm -I
tells meOn a large spinning disk with 4K sectors, I get instead