Ian Ward

Boxkite Inc.
Urwid 2014-02-09 (1.2.0)
Speedometer 2011-12-08 (2.8)

Moving to Python 3

Urwid Applications
Urwid Intro
Unfortunate Python
Django 1.1
Article Tags


Ian Ward's email:
first name at this domain

wardi on OFTC, freenode and github

Locations of visitors to this page

WD HDD lying about 4K sectors

Posted on 2010-11-29.

Many hard drives available today have 4K physical sectors instead of the old standard 512-byte sectors. The larger sectors allow the manufacturers to save space required for error correction, so they can save money, and in turn we get cheaper hard drives. Which is great, except that if a drive is using 4K sectors the drive must report it to the operating system or performance may suffer.

I recently purchased two WD HDDs: one 1.5TB and one 2TB, both "EARS" models. The 1.5TB drive happily reports that it has 4K physical sectors:

fdisk -l /dev/sdc
Disk /dev/sdc: 1500.3 GB, 1500301910016 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

But the 2TB drive claimed to have 512 byte sectors.

fdisk -l /dev/sdd
Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

"That's strange", I thought. So I ran a quick test to see if the 2TB drive was lying.

I first partitioned the 2TB drive with a single partition covering the whole disk, but I manually adjusted the beginning sector so that the partition data would be aligned with 4K sectors:

fdisk /dev/sdd

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-243201, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-243201, default 243201): 
Using default value 243201

Command (m for help): x

Expert command (m for help): b
Partition number (1-4): 1
New beginning of data (63-3907024064, default 63): 64

Another way to do this would be to turn off "DOS-compatible mode" in fdisk, then your first partition will start at sector 2048 (1MiB from the start of the disk) which is also aligned.

Next I timed the mkfs.ext4 command on this partition:

time mkfs.ext4 /dev/sdd1
Block size=4096 (log=2)
real    6m6.511s
user    0m1.760s
sys 0m42.160s

Then I deleted the partition and created one with the fdisk defaults, and ran the test again:

time mkfs.ext4 /dev/sdd1
Block size=4096 (log=2)
real    6m53.963s
user    0m2.000s
sys 0m30.490s

If anything, the second test would have had an advantage because it was accessing blocks on disk recently accessed by the first, but the second command took almost one minute longer than the first.

So be careful out there. Even if your operating system is capable of using disks with 4K sectors properly, your hardware might be lying to you.

Tags: Hardware Linux