Storage devices work with an internal page size varying between 512 bytes, to 4096 bytes (or higher for SSDs). Proper partition alignment ensures data written to a storage device do not straddle between these internal pages. If partitions are misaligned, a piece of data could cause multiple write or read operations, resulting in reduced performance.

Background[edit | edit source]

On legacy hard disks, the first partition typically began at LBA 63. With each physical sector containing 512 bytes, such a partition is offset by 32256 bytes (32KB - 512B). This is fine on legacy drives because the disk worked with 512 byte data. However, with modern hard disks using 4K physical sector sizes, using such a partition scheme would cause the partition to straddle between two physical sectors (as the 32256 offset isn't divisible by 4K).

When creating a partition on a modern Linux system, this is not something you need to concern yourself with as fdisk has sensible defaults when DOS compatibility mode is disabled, resulting in new partition aligned at the 1MB boundary (2048 sectors).

Legacy Systems[edit | edit source]

On older systems, you need to be mindful of the units that are reported by fdisk. Ensure that partitions are aligned properly by specifying the units with the fdisk -lu option. When creating a partition, you can specify 32 sectors by 64 heads (for 2048 sectors, with each being 512 bytes results in a 1MB alignment) with the fdisk options -S 32 -H 64. For example:

# fdisk -S 32 -H 64 /dev/sdd

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').


Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1907729, default 1): 2
Last cylinder, +cylinders or +size{K,M,G} (2-1907729, default 1907729): 
Using default value 1907729

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
64 heads, 32 sectors/track, 1907729 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003522f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               2     1907729  1953513472   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

## Verify that the partition starts on 2048 
# fdisk -lu /dev/sdd

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
64 heads, 32 sectors/track, 1907729 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003522f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048  3907028991  1953513472   83  Linux

See Also[edit | edit source]