Sector­block partition alignment
partition/disk/volume/sector alignment

Paolo Pedaletti: Paolo.Pedaletti@OpenLabs.it
Copy...
Definition
Physical HD setup:
– sector: the smallest unit of a hard disk that software can read or write. Even though a fi...
Aligned

Virtual and physical File System blocks are aligned between them and even with the HD geometry 
sectors.
In this ...
Partitions
Alignment verify
Example: NOT aligned
fdisk -lu /dev/sda
Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 6...
Example: 512Kb alignment ( = 512bytes * 32 sectors * 32 heads)
$ fdisk -S 32 -H 32 /dev/sdj
or
$ echo “1024,,” | sfdisk -u...
File System
LVM:7
pvcreate –metadatasize 250k /dev/sdb2
Physical volume “/dev/sdb2″ successfully created
Why 250k and not ...
Link­ography
•
•
•
•
•

http://www.ibm.com/developerworks/linux/library/l-4kb-sector-disks/index.html
http://bartsjerps.wo...
Upcoming SlideShare
Loading in...5
×

Disk partition alignment

677

Published on

Disk partition alignment

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
677
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Disk partition alignment

  1. 1. Sector­block 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 Link­ography........................................................................................................................................7
  2. 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/l­4kb­sector­disks/index.html     http://arstechnica.com/microsoft/news/2010/03/why­new­hard­disks­might­not­be­much­fun­for­xp­users.ars/     http://en.wikipedia.org/wiki/Logical_block_addressing     http://en.wikipedia.org/wiki/Logical_volume_management  
  3. 3. Aligned Virtual and physical File System blocks are aligned between them and even with the HD geometry  sectors. In this case reading 1 virtual File System block imply reading 1 real File System block or LVM extent  and 1 HD track (again, it's just an rough example) MBR is on the first sector (512 bytes = 446 bytes boot code + 64 bytes partition table [16 bytes for  each partition] + 2 bytes boot code signature5). Tracks are made of sectors  , and cylinders are made     6 of tracks (the same on different plates surfaces) so for performance reason it's better to start on the  second HD cylinder, thus aligning the first partition on the second cylinder. Alignment table alignment|Cylinder size (Times 512b) 64K (128 sectors) -S 2 -H 64 2x64x512=65536b=64Kb -S 4 -H 32 4x32x512=65536b=64Kb -S 8 -H 16 8x16x512=65536b=64Kb -S 16 -H 8 16x8x512=65536b=64Kb -S 32 -H 4 32x4x512=65536b=64Kb 128K (256 sectors) -S 2 -H 128 2x128x512=131072b=128Kb -S 4 -H 64 4x64x512=131072b=128Kb -S 8 -H 32 8x32x512=131072b=128Kb -S 16 -H 16 16x16x512=131072b=128Kb -S 32 -H 8 32x8x512=131072b=128Kb 256K (512 sectors) -S 4 -H 128 4x128x512=262144b=256Kb -S 8 -H 64 8x64x512=262144b=256Kb -S 16 -H 32 16x32x512=262144b=256Kb -S 32 -H 16 32x16x512=262144b=256Kb 512K (1024 sectors) -S 8 -H 128 8x128x512=524288b=512Kb -S 16 -H 64 16x64x512=524288b=512Kb -S 32 -H 32 32x32x512=524288b=512Kb 1024K (2048 sectors) -S 16 -H 128 16x128x512=1048576b=1024Kb=1Mb -S 32 -H 64 32x64x512=1048576b=1024Kb=1Mb 5   http://en.wikipedia.org/wiki/Master_boot_record   6   http://en.wikipedia.org/wiki/Cylinder­head­sector  
  4. 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. 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: :[~]$ grub­install /dev/sda  /usr/sbin/grub­setup: warn: Your embedding area is unusually small.  core.img won't fit in it..  /usr/sbin/grub­setup: 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/grub­setup: error: if you really want blocklists, use –force.  And: mke2fs -t ext2 -E stripe-width=128 /dev/sda1 For 512Kb alignment
  6. 6. File System LVM:7 pvcreate –metadatasize 250k /dev/sdb2 Physical volume “/dev/sdb2″ successfully created Why 250k and not 256k? I can’t tell you — sometimes the LVM tools aren’t terribly intuitive.  However, you can test to make sure that physical extents start at the proper offset by using: # pvs /dev/sdb2 ­o+pe_start PV         VG   Fmt  Attr PSize  PFree  1st PE /dev/sdb2       lvm2 –   73.52G 73.52G 256.00K If you use a metadata size of 256k, the first PE will be at 320k instead of 256k. There really ought to  be an –pe­align option to pvcreate, which would be far more user­friendly, but, we have to work  with the tools that we have. Maybe in the next version of the LVM support tools…. EXT4 mke2fs ­t ext4 ­E stripe­width=32,resize=500G /dev/sda1 Application: RAID1 1. HD partitioned fdisk -S 32 -H 32 /dev/sda fdisk -S 32 -H 32 /dev/sdb 2. RAID1 assembled (RAID alignment) mdadm --create /dev/md0 --level=1 --chunk=32 --raid-devices=2 /dev/sda1 /dev/sdb1 3. Partition format (File System alignment) mkfs.ext4 -b 4096 -E stride=32 -E stripe-width=32 -O dir_index /dev/md0 Trying to explain fdisk -lu /dev/sdf fdisk -c -u -b 4096 -S 32 -H 32 /dev/sde cfdisk -h 32 -s 32 /dev/sde 7   http://thunk.org/tytso/blog/2009/02/20/aligning­filesystems­to­an­ssds­erase­block­size/  
  7. 7. Link­ography • • • • • http://www.ibm.com/developerworks/linux/library/l-4kb-sector-disks/index.html http://bartsjerps.wordpress.com/2011/02/22/disk-alignment-linux/ http://www.vmdamentals.com/?p=328 http://www.vmdamentals.com/?p=988

×