Partition Alignment detailed explanation
Partition alignment is understood to mean the proper alignment of partitions to the reasonable boundaries of a data storage device (such as a hard disk, solid-state drive (SSD) or RAID volume). Proper partition alignment ensures ideal performance during data access. Incorrect partition alignment will cause reduced performance, especially with regard to SSDs (with an internal page size of 4,096 or 8,192 bytes, for example), hard disks with four-kilobyte (4,096 byte) sectors and RAID volumes.
A History of Partitions
In the past, the first partition always began at LBA Address 63, which corresponds to the sixty-fourth sector (see also CHS and LBA hard disk addressing). Such (logical) sectors had a size of 512 bytes. This was acceptable for normal hard disks (with a physical sector size of 512 bytes). Newer hard disks with a physical sector size of 4,096 bytes (four kilobytes) are really emulating a sector size of 512 bytes as far as external access is concerned, however internally they are working with 4,096 bytes. Even SSDs work with page sizes of four or eight kilobytes. Partitioning beginning at LBA Address 63 as such is a problem for these new hard disk and SSDs.
If partitions are formatted with a file system with a typical block size of four kilobytes, the four-kilobyte blocks for the file system will not directly fit into the four-kilobyte sectors for a hard disk or the four-, or eight-, kilobyte pages for an SSD. When a four-kilobyte file system block is written, two four-kilobyte sectors or pages will have to be modified. The fact that the respective 512-byte blocks must be maintained simply adds to the already difficult situation, meaning that a Read/Modify/Write process will have to be performed. A reduction in writing performance of up to a factor of 25 is the consequence during smaller data access attempts.[1]
Proper Partition Alignment
To avoid these problems, alignment at one-megabyte boundaries is recommended, which is a conservative approach over the long term. With the current addressing system divided in logical sectors of 512 bytes, doing so would correspond to 2,048 sectors.
Virtualized Systems
The article, File System Alignment in Virtualized Environments, contains information about virtualized systems.
Windows
Newer version of Windows (Windows Vista, Windows 7 and Windows Server 2008) perform the following, reasonable alignment:[2][3]
- Disk sizes less than or equal to four gigabytes should be aligned on sixty-four-kilobyte boundaries
- Disk sizes larger than four gigabytes should be aligned on one-megabyte boundaries
Older versions of Windows will require manual alignment.[4]
Linux
fdisk (Older Versions)
With older version of fdisk, manual alignment can be achieved using the -S and -H flags. There are a variety of recommendations with regards to the specific number of sectors per track determined by the -S flag and the number of heads determined by the -H flag.[5][6][7] The -S 32 -H 64
flags will however definitely align along the one megabyte boundary (32 sectors per track by 64 heads by 512 bytes equals 1,048,576 bytes or 1 megabyte). Thereby, creation of the first partition will begin with Cylinder 2. Misalignment will occur using fdisk, if special parameters are not used.
fdisk from Version 2.17.1
With regard to util-linux-ng versions after 2.17.1, fdisk will align on the one megabyte boundary, if DOS compatibility mode has been disabled.[8]
The recommended settings for newer versions of fdisk are:[9]
- Use the fdisk utility from util-linux-ng versions 2.17.2 or later
- Read the fdsik warnings.
- Deactivate DOS compatibility mode (the -c flag).
- Use sectors as display units (the -u flag).
- Use the +size(M, G) option in order to specify the end of a partition.
Incorrect Alignment Example
The following example shows an incorrect alignment. It is caused by DOS compatibility mode.
root@ubuntu-10-04:~# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xe4909079. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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): p Disk /dev/sdb: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xe4909079 Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-19457, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-19457, default 19457): +10G Command (m for help): u Changing display/entry units to sectors Command (m for help): p Disk /dev/sdb: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders, total 312581808 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: 0xe4909079 Device Boot Start End Blocks Id System /dev/sdb1 63 20980889 10490413+ 83 Linux Command (m for help):
Proper Alignment Example using Older Versions of fdisk
Partitions can be properly aligned using the -S 32 -H 64
flags, if the second cylinder is used as the starting point.
debian:~# fdisk -S 32 -H 64 /dev/sdc The number of cylinders for this disk is set to 65536. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p Disk /dev/sdc: 68.7 GB, 68719476736 bytes 64 heads, 32 sectors/track, 65536 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Disk identifier: 0x5a3b93b6 Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-65536, default 1): 2 Last cylinder or +size or +sizeM or +sizeK (2-65536, default 65536): Using default value 65536 Command (m for help): p Disk /dev/sdc: 68.7 GB, 68719476736 bytes 64 heads, 32 sectors/track, 65536 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Disk identifier: 0x5a3b93b6 Device Boot Start End Blocks Id System /dev/sdc1 2 65536 67107840 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. debian:~# fdisk -lu /dev/sdc Disk /dev/sdc: 68.7 GB, 68719476736 bytes 64 heads, 32 sectors/track, 65536 cylinders, total 134217728 sectors Units = sectors of 1 * 512 = 512 bytes Disk identifier: 0x5a3b93b6 Device Boot Start End Blocks Id System /dev/sdc1 2048 134217727 67107840 83 Linux debian:~#
Proper Alignment Example using fdisk Versions 2.17.1 or later
Proper alignment can be achieved by deactivating DOS compatibility mode and setting the sector unit (the partition will start at the LBA Address 2,048. In the case of an SSD with a page size of four kilobytes, there will be 256 empty pages at the beginning of the disk. The partition will begin precisely at the start of Page 257).
root@ubuntu-10-04:~# fdisk -c -u /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xfae13403. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): p Disk /dev/sdb: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders, total 312581808 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: 0xfae13403 Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First sector (2048-312581807, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-312581807, default 312581807): +10G Command (m for help): p Disk /dev/sdb: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders, total 312581808 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: 0xfae13403 Device Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux Command (m for help):
Testing the Alignment
Either of the two following commands will test alignment under Linux (replace /dev/sdX with the name of the device, such as /dev/sda).
sfdisk -d /dev/sdX
fdisk -l -u /dev/sdX
This example shows a system with an Ubuntu 10.04 installation. In this case, the Ubuntu 10.04 installer has aligned both the primary and the logical partitions at the one-megabyte boundary. This is indicated by the fact that the start sector number for the partition can be divided by 2,048 (2,048 sectors * 512 bytes per sector equals 1,048,576 or one megabyte). The extended partition (in this example, /dev/sda2) has not been aligned at the one-megabyte boundary. However, this is not required, since that partition merely serves as a container for the logical partitions and the logical partitions themselves are aligned at the one-megabyte boundaries.
user@ubuntu-test:~$ sudo sfdisk -d /dev/sda Warning: extended partition does not start at a cylinder boundary. DOS and Linux will interpret the contents differently. # partition table of /dev/sda unit: sectors /dev/sda1 : start= 2048, size= 39061504, Id=83, bootable /dev/sda2 : start= 39065598, size=1761810434, Id= 5 /dev/sda3 : start= 0, size= 0, Id= 0 /dev/sda4 : start= 0, size= 0, Id= 0 /dev/sda5 : start= 39065600, size= 3997696, Id=82 /dev/sda6 : start= 43065344, size=1757810688, Id=83 user@ubuntu-test:~$ sudo fdisk -l -u /dev/sda Disk /dev/sda: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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: 0x000d8343 Device Boot Start End Blocks Id System /dev/sda1 * 2048 39063551 19530752 83 Linux /dev/sda2 39065598 1800876031 880905217 5 Extended /dev/sda5 39065600 43063295 1998848 82 Linux swap / Solaris /dev/sda6 43065344 1800876031 878905344 83 Linux user@ubuntu-test:~$
Logical Volume Manager
If the Logical Volume Manager (LVM) is used, proper alignment will still be an important issue.
As a rule, alignment should be automatic. Older versions of the LVM align at the sixty-four-kilobyte boundary, which places the beginning of the physical volumes at the beginning of a page for SSDs as well. An August 2010 patch now ensures alignment at the one-megabyte boundary. The patch is included in the LVM Version 2.02.73 from August 18th 2010.
- lvm-devel RFC PATCH change default alignment of pe_start to 1MB (Mike Snitzer, linux-lvm mailing list, 05.08.2010)
- lvm-devel RFC PATCH v2 change default alignment of pe_start to 1MB (Mike Snitzer, linux-lvm mailing list, 06.08.2010)
- LVM2 What's New (Change default alignment of pe_start to 1MB.)
- Re: (linux-lvm) LVM Alignement (Mike Snitzer, linux-lvm mailing list, 22.07.2011)
Software RAID
A Linux Software RAID array normally aligns properly. The superblock for RAID volumes using the older Superblock Metadata Version 0.90 is at the end of the device (in a block aligned on a sixty-four-kilobyte boundary). The RAID data starts at the beginning of the device. A software RAID array using the newer Superblock Metadata Version 1.* will align the data at the one megabyte boundary (see Linux Software RAID: Testing Alignment).
Table of References
- ↑ http://www.ibm.com/developerworks/linux/library/l-4kb-sector-disks/#benchmarks
- ↑ Disk Partition Alignment Best Practices for SQL Server (msdn.microsoft.com, May 2009)). In Windows Vista as well as Windows Server 2008, partition alignment is usually performed by default. The default for disks larger than 4 GB is 1 MB; the setting is configurable and is found in the registry at the following location: HKLM\SYSTEM\CurrentControlSet\Services\VDS\Alignment
- ↑ LUN Types and Linux partition alignment (blogs.netapp.com)
- ↑ Disk performance may be slower than expected when you use multiple disks in Windows Server 2003, in Windows XP, and in Windows 2000 (Microsoft KB)
- ↑ http://www.thinkpad-forum.de/software/linux/88045-umzug-von-hdd-zu-ssd-mit-minimalen-arbeitsaufwand/#post807878
- ↑ http://www.nuclex.org/blog/personal/80-aligning-an-ssd-on-linux
- ↑ http://www.ocztechnologyforum.com/forum/showthread.php?54379-Linux-Tips-tweaks-and-alignment&p=373224#post373224
- ↑ https://ata.wiki.kernel.org/index.php/ATA_4_KiB_sector_issues#L-2._Userspace_tools_status_.28thanks_to_Karel_Zak.5B13.5D.29
- ↑ http://karelzak.blogspot.com/2010/05/4096-byte-sector-hard-drives.html
Additional Information
- Aligning IO on a hard disk RAID – the Theory (MySQL Performance Blog), 09.06.2011
- Chapter 20. Storage I/O Alignment and Size (RHEL6 Storage Administration Guide)
- ATA 4 KiB sector issues (ata.wiki.kernel.org)
- http://www.infoq.com/news/2010/03/4k-sectors
- http://blogs.netapp.com/storage_nuts_n_bolts/2010/03/lun-types-and-linux-partition-alignment.html
- Partitioning Advice by Rod Smith
- Western Digital’s Advanced Format: The 4K Sector Transition Begins (AnandTech)
- Linux Hardware RAID Howto
- http://superuser.com/questions/164439/what-is-the-the-dos-compatibility-flag-in-fdisk
- http://www.chip.de/artikel/SSD-So-haelt-die-Hightech-Festplatte-8x-laenger-5_37897062.html
- http://en.wikipedia.org/wiki/Logical_Disk_Manager#Compatibility_problems
- Recommendations for Aligning VMFS Partitions (VMware)
- Best Practices for File System Alignment in Virtual Environments (NetApp)
Author: Werner Fischer Werner Fischer, working in the Knowledge Transfer team at Thomas-Krenn, completed his studies of Computer and Media Security at FH Hagenberg in Austria. He is a regular speaker at many conferences like LinuxTag, OSMC, OSDC, LinuxCon, and author for various IT magazines. In his spare time he enjoys playing the piano and training for a good result at the annual Linz marathon relay.
|