Proper alignment of partitions on an Advanced Format HDD using Parted

Solution 1:

Parted is just being overly conservative. The usual practice these days is to align partitions on 1MiB (2048-sector) boundaries because this works on Advanced Format disks, on certain type of RAID setups that require alignment, and on most SSDs. For an Advanced Format disk, so long as the alignment is on a multiple of 8, you're fine, and 2048 is a multiple of 8. The lost disk space is puny -- 0.0000336% of your total disk space, if I did the math right and didn't mistype anything. So don't worry about it; just use the 1MiB alignment.

Solution 2:

I shall probably add that on Linux one can come in a situation where parted may never pass an optimal and a minimal alignment check at the same time.

The reason for this is that parted ( at least as of version 3.2 ) relies on libblkid, which in turn reports values from /sys/block/<disk>/queue/minimum_io_size and /sys/block/<disk>/queue/optimal_io_size ( see io-limits.txt ).

So while for an Advanced Format disk the former is likely to be something like 4k, the latter can have some mad value -- e.g. 65535 * 512 == 33553920.

Now if we look at the source code -- "proper", or "best performance" alignment is defined by the formula in parted.c::partition_align_check():

part->geom.start % pa->grain_size == pa->offset, 

where grain_size comes from I/O block size above, geom.start is our partition offset, and alignment offset pa->offset is quite frequently zero.

By default, parted would assume 1 MiB to be an optimal, and ~4k to be the minimal ( not quite so, it is a bit of a simplification ) block size, so these values would correlate ; however, if libblkid decides otherwise, parted tends to trust it, and replace that default value of 1 MiB with the value found in /sys/block/<disk>/queue/optimal_io_size. ( At the same time, /sys/block/<disk>/queue/minimum_io_size will quite likely give you the same 4096 B. )

In that case, parted optimal check will never pass simultaneously with the minimal check, what could possibly be a little confusing.

With that in mind -- if in doubt, have a look at queue/optimal_io_size and queue/minimum_io_size, and if the former is not divisible by the latter, just ignore parted' warning, and decide for yourself whether do you want to go with an optimal or a minimal check.