1. Sectorblock partition alignment
partition/disk/volume/sector alignment
Paolo Pedaletti: Paolo.Pedaletti@OpenLabs.it
Copyright (c) 2010 Paolo Pedaletti
Version 20121128
“What happens if
I press this button?”
Anonymous.
Table of Contents
Definition.............................................................................................................................................2
Not Aligned..........................................................................................................................................2
Aligned.................................................................................................................................................3
Alignment table................................................................................................................................3
Partitions..............................................................................................................................................4
Alignment verify..............................................................................................................................4
Example: NOT aligned.................................................................................................................4
Example: 512Kb alignment ( = 512bytes * 32 sectors * 32 heads)............................................5
File System...........................................................................................................................................6
LVM:.................................................................................................................................................6
EXT4................................................................................................................................................6
Application: RAID1...............................................................................................................................6
Linkography........................................................................................................................................7
2. Definition
Physical HD setup:
– sector: the smallest unit of a hard disk that software can read or write. Even though a file
might only be a single byte long, the operating system has to read or write at least 1 sector 1
to read or write that file2.
– Track: group of sector on the same HD plate surface at the same distance from the center
(fake/simulated LBA3 HD geometry)
– File System blocks or LVM extents4
– File System blocks of virtual device file (.img, .vdk, .raw)
Not Aligned
IIF (if and only if) you have a HD with MSDOS style partition scheme (4 primary partitions and
maybe some extended partitions) you have to worry about alignment.
You have not to worry about partition alignment if:
1. you don't partition the disk (of course :) ), i.e. use whole /dev/sdk
2. you use a different partition schema, like GPT or other.
Virtual and physical File System blocks are not aligned between them and neither with the HD
geometry sectors.
In this case reading even only 1 virtual File System block imply reading 2 real File System blocks or
LVM extents and 3 HD tracks (it's just an rough example)
1
2
3
4
http://www.ibm.com/developerworks/linux/library/l4kbsectordisks/index.html
http://arstechnica.com/microsoft/news/2010/03/whynewharddisksmightnotbemuchfunforxpusers.ars/
http://en.wikipedia.org/wiki/Logical_block_addressing
http://en.wikipedia.org/wiki/Logical_volume_management
4. Partitions
Alignment verify
Example: NOT aligned
fdisk -lu /dev/sda
Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders, total 156301488 sectors
Units = sectors of 1 * 512 = 512 bytes
512 bytes = 1 sector
63 Sectors = 1 track on 1 HD plate
255 Head|surfaces → 1 cylinder
1 cylinder → 255 * 63 = 16065 sectors * 512 bytes = 8032 ,5 Kb
the set of all cylinders → whole HD
Bytes per cilinder are not an integer multiply of bytes per block, so there is a
disallineamento tra traccie (hardware/hard disk) e blocchi (software/filesystem)!!!!
:[~]$ xfs_info /dev/sda1
meta-data=/dev/sda1 isize=256
agcount=4, agsize=610468 blks
=
sectsz=512
attr=2
Data
=
bsize=4096
blocks=2441872, imaxpct=25
=
sunit=0
swidth=0 blks
Naming
= version 2
bsize=4096
ascii-ci=0
Log
= interno
bsize=4096
blocks=2560, version=2
=
sectsz=512
sunit=0 blks, lazy-count=0
Realtime = nessuno
extsz=4096
blocks=0, rtextents=0
5. Example: 512Kb alignment ( = 512bytes * 32 sectors * 32 heads)
$ fdisk -S 32 -H 32 /dev/sdj
or
$ echo “1024,,” | sfdisk -uS /dev/sdj
512 bytes = 1 sector
32 Sectors = 1 track on 1 HD plate
32 Heads|surfaces → 1 cylinder
1 cylinder → 32*32 = 1024 sectors * 512 bytes = 512Kb
the set of all cylinders → whole HD
$ fdisk -lu
/dev/sdj
Disco /dev/sdj: 1000.2 GB, 1000204886016 byte
32 testine, 32 settori/tracce, 1907739 cilindri, totale 1953525168 settori
Unità = settori di 1 * 512 = 512 byte
Dispositivo Boot
/dev/sdj1
Start
End
Blocks
Id System
32 1953524735
976762352
83 Linux
32*512=16384 ; 16384/4096=4 !!!!!!!! OK !!!!!!!! :-)
Since the first partition cannot start at first (0) cylinder, minimal loss of capacity is obtained if the
first partition starts at the second (1) cylinder so boot manager (grub) can put itself into the first
cylinder.
To achieve this, cylinder size must be a multiple of 512KB (so the partition start at a cylinder
boundary).
If grub can't find enough space at the beginning of the disk:
:[~]$ grubinstall /dev/sda
/usr/sbin/grubsetup: warn: Your embedding area is unusually small. core.img won't fit in it..
/usr/sbin/grubsetup: warn: Embedding is not possible. GRUB can only be installed in this setup by
using blocklists. However, blocklists are UNRELIABLE and its use is discouraged..
/usr/sbin/grubsetup: error: if you really want blocklists, use –force.
And:
mke2fs -t ext2 -E stripe-width=128 /dev/sda1
For 512Kb alignment