24

What is partition alignment and why? Does it have something to do with the 2048-sector gap between two logical partitions?

1
  • @grawity The crucial part is different. I need someone to explain that in detail. Feb 25, 2012 at 14:59

1 Answer 1

29

Newer hard drives are being manufactured to utilise 4 kilobyte sectors rather than the conventional 512-byte sectors.

This is done to make more efficient use of the physical space on hard drives as for every sector there is a small batch of error correction data on the drive, and by going from 0.5kilobytes to 4kilobytes per sector means that there can be much less space on the drive wasted in this error correction data. To show what I mean here is an image taken from the Wikipedia article on Advanced Format Drives:

enter image description here

The reason for having to align your disk stems from the interaction of software that was written to expect 512-byte sectors working on a drive with 4-kilobyte sectors. If the software expects 512-byte sectors then it may well be trying to write to what it thinks is the "second" sector of a cluster, but is in fact the second 512 bytes of a 4-kilobyte sector.

The problem is that "Advanced Format" drives that simulate a 512-byte sector to the operating system but actually work with 4-kilobyte sectors internally is that a sector can only be written "in one go". In order to write to that second 512 byte area the entire 4KB sector must be read, and then re-written back to the drive, and this is a slower process than simply telling the drive to rewrite the whole 4KB sector.

Even if the operating system is aware of 4KB sectors it must have the drive properly aligned so that the boundaries between sectors agrees between where the drive says they are and where the operating system thinks they are.

Then there are SSDs, which have a similar problem in that they can be written byte-by-byte, but only erased in large blocks of typically 256KB or 512KB. In this way, in order to maximise performance you must align the partition (and thus sector) boundaries along one of those 256 or 512KB blocks.

For this reason a lot of modern partitioning tools simply align the entire drive along a 1MB boundary, which neatly does away with the need to detect whether you have any of the many types of drive, be they 512-byte sectors, 4KB sectors, or SSD with some arbitrary block size.

-=EDIT=-

To tell if your drive is properly aligned there are a number of ways to check, as this article on Lifehacker mentions. The advice applies mainly to SSds but is equally relevant to making sure a normal hard drive is aligned properly:

To see if your partitions are aligned correctly, hit the Start menu and type in msinfo32. Enter Msinfo32 and go to Components > Storage > Disks. Look for your SSD on the list and find the "Partition Starting Offset" item. If this number is divisible by 4096 (that is, if dividing it by 4096 equals a whole number and not a decimal), your partition is correctly aligned. If not, you need to realign it. Luckily, this is pretty easy to do with the Gparted live CD. If you have an Ubuntu live CD lying around, that will work too, since it has Gparted available under System > Administration.

10
  • 3
    Just a note: The performance lost due to wrong alignment comes when the software wants to write a lot of 4kiB filesystem sectors far away from each other. If each write overflows 512B into the next 4kiB disk sector, that next whole sector must be rewritten too, resulting in twice as much writing as necessary. (the first disk sector still contains 3.5kiB of the data written)
    – Eroen
    Feb 25, 2012 at 13:53
  • @kinokijuf As I mentioned the 4KB sectors are to make more efficient use of the disk (saving space is equivalent to free extra storage and therefore could be seen to translate to extra cash that can be charged) but the alignment itself is done for performance reasons.
    – Mokubai
    Feb 25, 2012 at 14:15
  • 1
    Most modern partitioning tools align along a 1 MiB boundary, e.g. 1048576 bytes. Alignment along 1 MB boundary does not work as it is not a multiple of 4096.
    – Futal
    Nov 9, 2017 at 10:11
  • 1
    @Mokubai: 1MB = 1,000,000 bytes (not a multiple of 1024), 1MiB = 1,048,576 bytes (1024 multiple). It's defined in ISO/IEC 80000 recognized by all standard institutes such as NIST.
    – Futal
    Mar 2, 2018 at 8:32
  • 2
    @Futal 99.9% of people are aware of the stupid situation that brought us to need a MiB/MB distinction and simply don't care about it. It is pointless and (for the most part) irrelevant. Most people can also use a linguistic trick known as "contextual clues" to figure out which one is meant. If I am talking about 512byte and 4kb sectors in the same sentence then it is doubtful I mean 4000bytes or even 1000000bytes as 1MB.
    – Mokubai
    Mar 2, 2018 at 9:54

Not the answer you're looking for? Browse other questions tagged .