How to format a 4k sector hard drive?

Solution 1:

First, most Advanced Format drives present a logical sector size of 512 bytes, even though the physical sector size is 4096 bytes (4KiB). This is done through juggling data in the drive's firmware, and it can result in performance problems if the partitions are not properly aligned. Chances are this isn't the source of your problem, though, and your focus on partition alignment is misplaced. (To be sure, partition alignment is important; it's just not the source of your problem.)

My hunch (and it is just a hunch) is that your problem results from switching between a USB enclosure and direct connection of the disk. Some enclosures translate 512-byte logical sectors on the disk into 4096-byte logical sectors presented to the computer -- that is, the opposite of what the firmware in an Advanced Format disk does. I'm not positive, but I suspect that some enclosures do this only on over-2TiB disks. Both MBR and GPT partitioning schemes refer to data by sector numbers, so changing the sector size invalidates the partitioning data. Thus, if you prepare the disk in a USB enclosure that translates in this way and then try to use the disk directly (or vice-versa), you'll see errors because the partitions (and even GPT backup data) won't be where the computer expects it to be. It'd be like telling a blindfolded person to "walk 2 forward," where you mean 2 feet, but the person thinks you mean 2 meters, and so walks into a wall.

The solution to this problem is to prepare and use the disk in one way -- either use the USB enclosure or use a direct connection, not both. If both are necessary for some reason, you'll need to find an enclosure that works without applying this type of translation.

To test my hypothesis, you can use a tool (like parted) that reports logical sector sizes. For instance:

sudo parted /dev/sda print
Model: ATA Hitachi HDP72505 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B

I've omitted a bunch of information from this output. The important detail is in the final line shown here: The logical and physical sector sizes are both 512 bytes. If you run this test, then reattach the disk in the other way and run it again, you can compare the results. If the logical sector size changes depending on how you attach the disk, then my hypothesis is correct and it's the source of your problem. Or at least, it's one problem; there may be others, too. In particular, the Error synchronizing after initial wipe error you mentioned could indicate another problem. OTOH, that could be a side effect of parted trying to read backup GPT data from beyond the end of the disk. Either way, if you see a change in logical sector size, you should address that issue before dealing with anything else. If you want to repartition the disk but have problems because of the Error synchronizing error, try using gdisk or cgdisk (in the gdisk package) rather than parted or GParted; the gdisk family is more robust against errors than is the parted family.

Solution 2:

It reports 512 bytes because that is the logical sector size for backward compatibility with older OSes ( Windows ). (g)parted aligns partitions to 1 MiB, which is more than enough to work properly with drives using 4k physical sectors, so it is fine the way it is.