Partition Alignment

From Leo's Notes
Last edited on 6 April 2021, at 18:28.

Partitions should be aligned as follows:

  • 1MB is common. To be safe, check the block size of your SSD and align your partition based on that.
Media Type Alignment
Hard Drive (less than 2TB, without AF) 512 bytes
Hard Drive (greater than 2TB, with AF) 4096 bytes
Solid State Drives 1MB*


Background[edit | edit source]

Hard drives store data on platters that are subdivided into tracks and each track divided into sectors. On most older hard drives under, each sector holds 512 bytes of data while newer hard drives supporting using advanced format (AF) stores 4096 bytes per sector. Every time a contents of a sector is changed, the entire sector must be read, modified, then re-written.

Solid state devices on the other hand stores data in banks of memory cells and groups them into pages ranging from 4 to 16KB. These pages are then further grouped into a block that ranging from 128 to 512 pages, or 512KB to 8MB. Likewise to a sector, every time a contents of a block is changed, the entire block must be read by the controller, modified, then re-written as a whole.

A partition should be aligned such that its offset is divisible by the sector size in the case of hard drives and the block size in the case of SSDs. A misaligned partition would result write amplification, as everything that's written will cause two sectors or pages to be modified. What should have been a change to one sector now becomes two. Consequently, a misaligned partition would results in lower throughput and increases wear on SSDs

Legacy Systems[edit | edit source]

This section only applies to systems with an older versions of fdisk. On older systems, you need to pay special attention to the units that are reported by fdisk. as they are most likely reported as Cylinder-Head-Sector (CHS) units. Ensure that partitions are aligned properly by specifying the units with the fdisk -lu option.

To create a partition with a 2048 sector or 1MB offset, we can call for 32 sectors by 64 heads. We can calculate the offset thusly: 32 * 512 bytes * 64 heads = 1MB.

Use 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]