Question: When partitioning with fdisk the last few sectors cannot be included in a partition, as far as I have experienced. I always thought this is due to MiB- or IO-block-alignment, but I just realized that the last sector it allows me to use is not aligned! I tried several tools with several HDDs from different vendors, and it’s always the last 30-something sectors.For example:
Disk /dev/sdb: 465.8 GiB, 500107862016 bytes, 976773168 sectorslast MiB-aligned sector: ??976773119last IO-block-aligned (4KiB) sector: ?976773167 (the last one)last usable sector: ??976773134
This is of course not a big problem, but I’m curious of the reason. Does it have to do with bad sectors?
Answer: I bet you created a GUID Partition Table (GPT) on the disk to get the “last usable sector” number.
Did you notice that the last usable sector is 34 sectors less than the total number of sectors?
Check this out:
(source)
Those “unusable” 33 sectors are actually for the backup GPT! ?(That’s LBA -34 to the end.)
We can also derive why the last MiB-aligned sector and the last I/O block aligned sector are the way they are.
Note: You likely arrived at your last sector numbers without using a GPT. ?The legacy MS-DOS partition table only takes up 512 bytes (1 logical sector) at the beginning of the disk with nothing at the end.
Disk Information
Logical sector size: ?512 (used in calculations)Physical sector size: ?4096 (used for I/O block alignment)
Physical Block Alignment
Your last aligned sector: 976773167
Physical sector size: ?4096Divide by logical sector size: 512 ??—-Sectors for block alignment: ?8Total sector count: ?976773168Divide by alignment sectors: ? 8 ??———Max 4KiB blocks: ?122096646Unusable sectors remainder: ?0Total sector count: ?976773168Subtract remainder: ?-0 ??———First unalignable sector: 976773168Your last aligned sector: 976773167
1MiB Block Alignment
Your last aligned sector: 976773119
1MiB in bytes: ?1048576Divide by logical sector size: 512 ??——-Sectors for 1MiB alignment: ?2048Total sector count: ?976773168Divide by alignment sectors: ? 2048 ??———Max 1MiB blocks: ?476940Unusable sectors remainder: ?48Total sector count: ?976773168Subtract remainder: ?-48 ??———First unalignable sector: 976773120Your last aligned sector: 976773119