Tuesday, May 15, 2012

Partition Alignment

#sudo fdisk -luc

turn off MSDOS mode

#sudo fdisk -H 32 -S 32 -cu /dev/yourdisk

1 Gigabyte = 2,097,152 sectors
1 Megabyte = 2,048 sectors


total_sectors / 2,097,152 (sectors in 1GB) = Total Gigabytes
remaining_sectors / 2,048 (sectors in 1MB) = Total Megabytes

Example
2,097,152 X 25 = 52,428,800 (25GB)
2,048 X 750 = 1,536,000 (750MB)
(2,097,152 X 12) + (2,048 X 500) = 26,189,824 (12GB+500MB)


Remember: If you're aligning partitions make sure to start at a sector evenly divisable by 512.
When asked for the size of your partition you'll need to prefix a + to your sectors.
Your last partition may consume the rest of the disk without a worry.


Alignment.

thumb rule is all about your partition starting at a sector evenly divisable by 512. The size of your partition and/or where it ends does not matter. As long as your partition starts at a sector divisable by 512 you're good.

If you had the following partitions sizes ready to go and you could sacrifice 512 bytes per partition without a worry, you subtract 1 sector from each partition. Doing it this way insures no gaps between partitions.


52,428,800 (25GB) - 1 sector = 52,428,799
1,536,000 (750MB) - 1 sector = 1,535,999
26,189,824 (12GB+500MB) - 1 sector = 26,189,823


start at 2,048 because this is the most common start sector in almost all guides. The following example assumes you don't mind shaving 512 bytes per partition by subtracting 1 sector each. In other words you don't need the absolute size and in that process create no gaps between partitions.


Start       End
2,048       +52,428,799  # This partition ends at 52,430,847, the next partition starts at 52,430,848 (evenly divisable by 512)
52,430,848  +1,535,999   # This partition ends at 53,966,847, the next partition starts at 53,966,848 (evenly divisable by 512)


The following example assumes you do mind shaving 512 bytes and want absolute sizes. If you need an absolute size per partition and cannot subtract 1 sector per partition you simply start your next partition at a sector evenly divisable by 512.


Start       End
2,048       +52,428,800  # This partition ends at 52,430,848, our next partition cannot start there. It will start at 52,430,848 + 512 = 52,431,360 (evenly divisable by 512)
52,431,360  +1,536,000   # This partition ends at 53,967,360, our next partition cannot start there. It will start at 53,967,360 + 512 = 53,967,872 (evenly divisable by 512)
53,967,872  +26,189,824  # This partition ends at 80,157,696, our next partition cannot start there. It will start at 80,157,696 + 512 = 80,158,208 (evenly divisable by 512)


No comments:

Post a Comment