Partitioning for 4k cluster size in Linux/Ubuntu
The 4k cluster size “Advanced Format” drives are causing a lot of confusion, especially in Linux and Windows XP. The Windows XP solutions are pretty well documented by the manufacturer. But it’s confusing to get the sectors aligned for maximum performance under Linux. I looked at a lot of instructions before I got it working right. kamihacker has some instructions in Spanish that are a bit different and might be helpful, too.
Many hard drive manufacturers are now moving to 4k cluster sizes on their large hard drives. Western Digital is calling these Advanced Format Drives. In the past, hard drives used 512 byte sectors and these drives actually have 4k sectors while emulating 512 byte sectors for backwards compatibility. The Anandtech Article gives some background. This means you also must align your file system storage blocks to the ones the hard drive uses, otherwise you’ll have bad performance. Linux can align the blocks but it doesn’t always do it automatically.
There are a lot of ways to do this, but not all that I tried worked. The two most useful posts I found in figuring it out were at http://www.formortals.com/how-to-create-4kb-aligned-partitions-in-windows-xp-and-linux/ and http://www.ibm.com/developerworks/linux/library/l-4kb-sector-disks/index.html?ca=dgr-twtr4KB-Disksdth-LX. I used pieces of information from both these pages to get my drive partitioned properly and working.
I got this information from the IBM page: start fdisk as follows (be sure to change /dev/sda to the drive specification on which you want to create the file system). I’m assuming this is an unpartitioned drive. If not, use something like gparted to remove any partitions you don’t want first. The “magic” command that will make it align to 4k blocks.
sudo fdisk -H 224 -S 56 /dev/sda
Starting it this way will ensure 4k alignment. You can use the options in fdisk to then simply tell it the partition size in human terms (like ‘300G). It will rounds it to even 4k blocks because of the startup options you gave it.
If you don’t know how to use fdisk, follow instructions such as those at the Technology for Mortals site. If you follow these specific fdisk instructions, you DO NOT need to do the second half of the instructions where he types ‘x’ and uses expert commands to move the start sector since it’s already aligned to a 4k block for you.
After creating these partitions you will need to use the mkfs.ext4 or similar for your partition to actually make the filesystem on the partition. Use the –help option to get information about how to make the filesystem of your choice. You could probably also format in gparted without repartitioning, though I didn’t try it that way.
You can verify you partitioned correctly with a GUI tool such as gparted (sudo gparted) and then look at the properties for a partition. You know you did it right if the start sector is evenly divisible by 8 (since 8×512 is 4096) and the partition size will also be equally divisible by 8.
Let me know if this post helped you out, and thanks to kamihacker for the photo of the drive. This is the exact model I got which requires aligning to 4k blocks for performance. The alternate instructions in Spanish are probably also useful to those who speak Spanish out there.
