You may have read of the new 4K Advanced Format drives now becoming popular on the market. In fact, if you’ve got a drive larger than 1 TB, you probably have one, even if you don’t know it. I’ve found lots of people assembling home NAS servers using 2 TB drives, linux software RAID or LVM, and all of them are concerned about aligning various parts of the storage infrastructure to the new 4K format. But, thanks to libblkid, you don’t have to.
Full disclosure: I’m one of those people who assembled such a NAS. And I was one of those people who spent an inordinate amount of time worrying about the 4K alignment problem. I eventually learned that I’d been wasting my time. When you find people on various mailing lists, forums, and blogs talking about this, please point them here.
The fundamental problem is the need to align data structures to the physical storage device’s boundaries. If your device stores data in block of 4K, then you want to begin writing your data at a multiple of 4K. You do not want to start writing 4K of data beginning 2K from the start of the device, because that will mean reading and writing two blocks of data. It would be more efficient to align to the boundary and write only one block.
All low-level storage systems, from filesystems (ext4) to logical volume managers (lvm2) to software raid (mdadm) use various block sizes. The terms vary from blocks to chunks to stripes, but the concept is the same. We want these blocks to align to what is best for the underlying layers, from any RAID configuration down to the physical devices.
To solve this problem, libblkid provides topology information for block devices. This includes physical and logical block sizes. As of spring 2010, support for libblkid is available in all the standard tools:
- fdisk, since util-linux >= 2.15. You should start with ‘-c -u’ to disable DOS compatibility and use sectors instead of cylinders.
- parted, since parted >= 2.1. Parted defaults to 1 MiB alignment for unknown disks, which should align to just about any sector size. This includes gparted and other graphical tools such as the partitioner used in the Ubuntu desktop installer.
- mdadm, since util-linux >= 2.15. It is no longer necessary to manually specify stride and stripe-width. All MD superblocks are positioned either at the end of the array (0.9 and 1.0) or in multiples of 4K from the beginning (1.1, 1.2).
- lvm2, since util-linux >= 2.15.
- mkfs.{ext,xfs,gfs2,ocfs2} all support libblkid directly.
If you’re uncertain, verify that your tool depends on util-linux or libblkid. You can use the package manager, although you may need to examine a dependant library:
user@server:~$ dpkg -s libparted0debian1 | grep libblkid Depends: libblkid1 (>= 2.17), libc6 (>= 2.8), libdevmapper1.02.1 (>= 2:1.02.36), libuuid1 (>= 2.16)
Or use ldd, which is more direct:
user@server:~$ ldd /sbin/parted | grep libblkid libblkid.so.1 => /lib/libblkid.so.1 (0x00007f5833228000)
Conclusion: if you are running Ubuntu 10.04, Fedora 13, or RHEL 6 or later, you do not have to do anything to use your 4K disk efficiently. Create the RAID array, logical volume, and filesystem exactly as you normally would.
-
I had some issues with this recently when installing Ubuntu 11.10 64-bit Desktop on a new (2012) Seagate 2TB 4k format drive. After installation the Ubuntu graphical disk utility reported alignment issues with the newly installed GPT disk and warned that performance would be negatively impacted. After re-partitioning with GParted, then re-installing, the warnings went away.
I’m going to reinstall with Ubuntu 11.10 Server 64-bit to see if the same issues arise.
7 comments
Comments feed for this article
Trackback link: https://www.tolaris.com/2011/07/21/libblkid-or-why-you-dont-need-to-worry-about-4k-disk-format/trackback/