How to properly align partitions

fdiskpartedpartition

I'm trying to understand what are the rules for creating correctly aligned partitions.

For the moment I'm playing with parted on a virtual machine, but I'm planning to move to a real hard disk when I feel more confident. I bought my laptop in 2008 so it doesn't have 4 KiB sectors, but 512 B ones. I'm going to use the EXT4 filesystem with 4 KiB blocks, so I suppose I need to align to 4 KiB anyway. As far as I know, sectors are numbered from zero and the first one is reserved for the MBR. So I conclude that I need to leave 7 sectors unused (4096 B / 512 B – 512 B) after the MBR, and the first partition could start at sector 8. The end of this partition could be any sector number that is one less than a number divisible by 8. For example 15, for an extremely small partition with just one EXT4 block.

The problem is that parted says me that "The resulting partition is not properly aligned for best performance", but doesn't tell me what's wrong exactly. If I try to use fdisk instead, I cannot even use a sector less than 2048 (1 MiB) for the start of the first partition. I searched for a rationale behind this, but I found nothing.

In the future I could be interested in partitioning rules that also take in consideration LVM, RAID and encryption, but this is not really important for the moment. I need to understand the basics first.

Best Answer

I asked on the util-linux mailing list (the ''fdisk'' program belongs to the util-linux package). You can read the whole thread here. Let me quote the relevant portions.

Kay Sievers said:

It's a de-facto standard, which Windows does too. The first megabyte is reserved here for a boot loader or any other management data that could be needed for a disk or box to boot from.

Karel Zak said:

The real reason is that 1MiB is ideal offset to keep partitions aligned on almost all random hardware. This offset is compatible with 512-byte, 4096-byte sector devices, many raid devices as well as old broken WD disks where physical sector size has been incorrectly reported. You can use dd(1) to move your PT + data to another device without care about physical device topology (I/O limits), etc.

It's also important to keep your partition sizes aligned to MiB -- this is for example default in fdisk if you specify the size in +{M,G} convention.

Related Question