{"id":3440,"date":"2015-10-06T16:52:22","date_gmt":"2015-10-06T21:52:22","guid":{"rendered":"http:\/\/neosmart.net\/blog\/?p=3440"},"modified":"2015-10-06T16:52:22","modified_gmt":"2015-10-06T21:52:22","slug":"chs-lba-and-4k-advanced-format-drives","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/chs-lba-and-4k-advanced-format-drives\/","title":{"rendered":"CHS, LBA, and 4k advanced format drives"},"content":{"rendered":"<p>Modern hard drives are shipping with newer features, some of them more confusing than others. One such feature that&#8217;s causing a lot of head-scratching and confusion amongst the ranks is the new, so-called &#8220;advanced format&#8221; hard disks that are now shipping. Generally, these are newer SSDs as well as traditional &#8220;spinning rust&#8221; hard drives larger\u00a0than 4TiB in capacity. What&#8217;s 4k all about and why do we need it? To understand this, we&#8217;re going to have to take a trip back in time and find out exactly how disks work, how an operating system talks to a disk in order to read\/write from\/to the disk, and see why the old way was broken and needed to be replaced with something newer and better.<\/p>\n<p><!--more--><\/p>\n<p>Let&#8217;s first start with some definitions: there are two different ways of accessing a location within a drive, one is the older\u00a0<strong>CHS<\/strong> scheme and the other is the\u00a0<strong>LBA<\/strong> scheme, currently used by all modern operating systems.<\/p>\n<p><strong>CHS<\/strong> stands for Cylinder, Head, Sector and is the most low-level method of determining where to read or write from the drive. You tell it to use cylinder x, head y, and sector z and read or write the contents of that location to or from an address in the memory (a buffer). It is derived from the actual, physical components of a (traditional, spinning rust) hard drive, where you have physical cylinders and read heads. The sector is the smallest addressable unit, <strong>and was traditionally fixed at 512 bytes<\/strong>.<\/p>\n<p><strong>LBA<\/strong> is logical byte addressing wherein the drive reads from and writes to a sector address by its offset, for example, read the 37th sector on the disk or write this to the 1434th sector on the disk (starting from zero).<\/p>\n<p>The problem? Each of these values is limited in range. In fact, because of how severely limited CHS was, LBA had to be introduced. For CHS, the possible values for C (the cylinder) is 1023, while H (heads) can be 255 maximum, and S (sector) can only go up to 63, meaning you can have at most 1024 cylinders x 255 heads x 64 sectors x 512 bytes mapped in traditional CHS format, giving you a grand total of under 8 GiB! Using CHS, it&#8217;s simply not possible to access a disk larger than 8 GiB!<\/p>\n<p>So LBA was introduced with a 32-bit limit giving you 2<sup>32<\/sup> x 512 bytes or 2 TiB limit on disk size &#8211; and this is the reason an MBR disk cannot exceed 2TiB because it uses CHS and LBA to specify partition sizes, and neither can support anything over 2TiB.<\/p>\n<p>Newer, better options have been introduced like the GPT partitioning scheme which extends LBA to 64 bits, giving you a heck of a lot more than you&#8217;ll ever need at 2<sup>64<\/sup> x 512 bytes &#8211;\u00a0<em>but<\/em>\u00a0there&#8217;s a catch: a lot of legacy hardware and legacy operating systems and legacy BIOS implementations and legacy drivers don&#8217;t support UEFI or GPT, and a lot of people would like to have something that can be more-easily upgraded to go past the 2TiB limit without having to rewrite the entire stack from scratch. And, at long last, we reach the 4096 sector size.<\/p>\n<p>See, throughout all the limitations discussed above, one thing has been a fixed assumption: the sector size. From day one, it has been 512 bytes and it&#8217;s stayed that way ever since. But recently, hard disk manufacturers realized there&#8217;s an opportunity to work some magic: take the traditional CHS or 32-bit LBA and simply replace the sector size with 4096 (4k) instead of 512 bytes. When an OS says &#8220;give me the 2nd sector on the disk&#8221; by requesting LBA 1 (because LBA 0 is the first), we aren&#8217;t going to give it bytes 512 &#8211; 1023 but rather bytes 4096 &#8211; 8191.<\/p>\n<p>Suddenly, our 2TiB limit is upgraded to 2<sup>32<\/sup> x 4096 bytes, or 16 TiB, without having to ditch MBR, switch to UEFI or GPT, or anything!\u00a0An additional advantage is that things are a lot faster because if you&#8217;re reading and writing 4096 bytes at a time, it&#8217;s 8x fewer operations to read or write, say, 4GiB of data, which helps with avoiding flooding the command buffer and improves random access times, cache locality, and more.<\/p>\n<p>The only catch is that if the OS isn&#8217;t aware that this is a magic disk that uses 4096 sectors instead of 512 byte sectors, there&#8217;s going to be a mismatch. Each time the OS says &#8220;hey, you, disk, write me these 512 bytes to offset xxx&#8221; the disk will use up\u00a0<em>4096 bytes<\/em>\u00a0to store these 512 bytes (the rest being zeros or junk data, assuming you don&#8217;t end up with a memory underflow) because they don&#8217;t communicate in bytes, they communicate in sectors.<\/p>\n<p>So BIOSes now (sometimes) include an option to let you manually specify that a 512-byte sector size should be used instead of the native 4096 byte sector size that newer disks are using &#8211; with the caveat that you cannot use it to access more than 2TiB of the disk on an MBR system, just like it was in the &#8220;good old days.&#8221; But modern OSes that are 4k-aware can take advantage of all this to use this magic to read and write in 4096-byte chunks and voil\u00e0!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modern hard drives are shipping with newer features, some of them more confusing than others. One such feature that&#8217;s causing a lot of head-scratching and confusion amongst the ranks is the new, so-called &#8220;advanced format&#8221; hard disks that are now &hellip; <a href=\"https:\/\/neosmart.net\/blog\/chs-lba-and-4k-advanced-format-drives\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":505,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[904,19],"class_list":["post-3440","post","type-post","status-publish","format-standard","hentry","category-software","tag-hard-drives","tag-hardware"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4xDa-Tu","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/505"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=3440"}],"version-history":[{"count":1,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3440\/revisions"}],"predecessor-version":[{"id":3441,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3440\/revisions\/3441"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=3440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=3440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=3440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}