0%

Fix "The resulting partition is not properly aligned for best performance"

When partitioning disks larger than 2 TB on Linux, you usually need to use parted instead of fdisk. If you are used to accepting the defaults in fdisk, parted can feel a bit less forgiving.

If you insert a new disk and it appears as /dev/sdb, you can start partitioning with:

1
parted /dev/sdb

Inside parted, you may see an error like this:

1
Error: /dev/sdb: unrecognised disk label

That simply means the disk does not have a partition table yet. For disks larger than 2 TB, use GPT. For smaller disks, the traditional msdos label is usually enough:

1
mklabel gpt

To create a partition in parted, use mkpart. This command creates one partition across the whole disk:

1
mkpart primary 0 100%

The parameters mean: primary partition, starting sector, and percentage of disk space used.

That looks fine, but if you accept everything by default, you may end up with this warning:

1
Warning: The resulting partition is not properly aligned for best performance.

It is only a warning, but since it affects performance, it is worth fixing. The usual cause is that the starting sector is not aligned properly.

To calculate a better starting sector, check these values:

1
2
3
4
5
6
7
8
cat /sys/block/sdb/queue/optimal_io_size
1048576
cat /sys/block/sdb/queue/minimum_io_size
262144
cat /sys/block/sdb/alignment_offset
0
cat /sys/block/sdb/queue/physical_block_size
512

If optimal_io_size is not 0, add optimal_io_size and alignment_offset, then divide by physical_block_size. In the example above:

1
(1048576 + 0) / 512 = 2048

If optimal_io_size is 0, using the common default start sector 2048 is usually a good choice.

Then create the partition like this:

1
mkpart primary 2048s 100%

Do not forget the s suffix after 2048.

With that starting sector, the partition should be created without the alignment warning.

Reference:

http://rainbow.chard.org/2013/01/30/how-to-align-partitions-for-best-performance-using-parted/

如果我的文字帮到了您,那么可不可以请我喝罐可乐?