13

I bought a Seagate ST3000DM001 3TB hard drive. It was sold inside an enclosure. I formatted to ext4, copied some data to it and then I removed it from the enclosure and connected it directly to the motherboard. My data wasn't visible to OS (it was seeing one unknown ~300GiB partition and the rest as free space) so I started reading about Advanced Format and >2TB drives.

I connected the disk with USB again, copied all the data, and plugged to sata once again. I used gparted to create a GPT partition table (the ubuntu disk utility wouldn't let me with Error synchronizing after initial wipe: Timed out waiting for object (udisks-error-quark, 0), created one big 3Tb Ext4 partition, left the default Align to value to MiB and formatted.

The drive is recognized correctly, and mounts properly. Files can be copied from and to the drive successfully.

However:

Gparted shows the disk having 512k sectors which I know is not true1

gparted screenshot

while cat /sys/block/sdb/queue/physical_block_size reports 4096

I have found some reports that libparted has a problem with non-512k sectors2 and others3 that say that aligning to MiB is enough.

Parted reports that the drive is aligned when I choose minimal:

(parted) align-check 
alignment type(min/opt)  [optimal]/minimal? min                           
Partition number? 1                                                       
1 aligned
(parted)    

Is my configuration correct? Do I have performance penalty because the disk is formatted with 512k sectors, is gParted reporting false values or I have understood the whole thing wrong?

  1. http://www.storagereview.com/seagate_barracuda_3tb_review_1tb_platters_st3000dm001
  2. http://ubuntuforums.org/showthread.php?t=1536933&p=9754234#post9754234
  3. http://wdc.custhelp.com/app/answers/detail/a_id/5655
3
  • I have a few of these Seagte drives as well as WD and Fujitsu/HGST 3TB drives and they all work without issues. You may be right about GParted, because my Seagate one that is currently connected via USB shows up with 4096 sector size in GParted. My GParted version is 0.12.1, the default from quantal.
    – LiveWireBT
    Aug 27, 2013 at 2:34
  • I believe that it will show 4096 here too if I connect it via USB. There's some magic in the USB-SATA controller there.
    – qwazix
    Aug 27, 2013 at 6:54
  • Relevant QA: superuser.com/questions/679725/…
    – qwazix
    Dec 2, 2018 at 20:04

4 Answers 4

12

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.

3
  • I do believe that the problem is because of switching between usb and internal. Indeed that was my initial thought and that is why I re-created the partition table after putting the disk back into the pc and connected with sata. (I took it out in the first place just to take my data out). I don't want to remove it again to test the logical sector reported via USB but all facts suggest this.
    – qwazix
    Aug 27, 2013 at 21:15
  • I do not intend to keep switching interfaces, the disk works as it is now, prepared under SATA connection. I am just worried about the performance penalties you mentioned and I want to understand what really happens. parted /dev/sdb print returns 512/4096 so it seems that gParted reports the logical sector size which explains why @LiveWireBT sees 4096 for the same disk (connected via USB) and also confirms your hunch as above.
    – qwazix
    Aug 27, 2013 at 21:28
  • Had the same problem with a Verbatim Store'n'Go external drive, the logical sector size is 512 while the physical size is 4096.
    – gaborous
    Feb 12, 2015 at 17:01
5

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.

4

Changes have been made to both the Linux kernel and utilities to support Advanced Format drives. These changes ensure that all partitions on Advanced Format drives are properly aligned on 4K sector boundaries. Kernel support for Advanced Format drives is available in kernel versions 2.6.31 and above. Support for portioning and formatting Advanced Format drives is available in the following Linux utilities:

Fdisk: GNU Fdisk is a command line utility that partitions hard drives. Versions 1.2.3 and above support Advanced Format drives.

Parted: GNU Parted is a graphical utility for partitioning hard drives. Versions 2.1 and above support Advanced Format drives.

4K native (4Kn) disks have a 4-KB logical sector size. Modern operating systems can store data on these disks, but they generally cannot boot from these disks. These disks are commonly external drives with USB connection.

To create a partition used as a media storage device, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo mkfs.ext4 -m 0 /dev/sdb1

Most of the 4k disks have a physical sector size of 4096 bytes so that 3TB can fit on the plates, but they still have 512B logical sector size for compatibility with OSs that expect one sector to be 512B. That's why when you use the print command in parted to print the details, is says sector size logical/physical 512B/4096B. That's normal.

This "conversion" is done by the intelligence on the disk itself, and it's normal. It's how it should work.

If you can't see the whole 3TB first check in BIOS that it's not limiting the disk size. Maybe you need bios update to support the disk.

Also using parted to create partition starting from 0 which is a mistake. You need to start the first parttion on sector 2048 which is equivalent to 1MiB so that the partitions on the disk are aligned for optimal performance.

So, change the unit to MiB, print the disk details which will also print the disk size in MiB, and create the partition (if you only want single partition) starting from 1MiB and ending at the last MiB (or one before the last).

For example, a 3TB disk should have in reality something like 2,861,022 MiB. So creating a single partition spanning the whole disk on a disk device called /dev/sdX would be like (replace the X with the correct letter):

sudo parted /dev/sdX
unit MiB
mklabel gpt
print (to see the total size in MiB)
mkpart primary 1 2861022
quit

If the disk size is few MiB more or less than 2861022 adjust the ending location.

That's it. After that create the filesystem you want on the partition.

Sources, and extra reading

4K-sector drives and Linux

Error check and install 4k drives in Linux

Ubuntu Forums

1
  • Thanks for the response, but it doesn't really answer my question. I get that the kernel recognizes the sector size of the drive and that gparted is supposed to recognize that too, but it reports otherwise and I am curious if there is an explanation to that, if it's a bug, or if I have done something wrong.
    – qwazix
    Aug 27, 2013 at 16:27
0

As long as you align your partitions on a multiple of 4KB, you're fine. You don't otherwise have to do anything special for drives with 4KB physical sectors.

Old partitioning software aligned partitions on a multiple of 63x512B sectors, which will result in bad performance if the drive has 4KB physical sectors because that is 31 and a half KiloBytes, NOT a multiple of 4KB.

Virtually no partitioning software available now in Ubuntu will do this anymore (unless you specifically request it to somehow). Most will align to a multiple of 1MiB (2048x512B sectors, which is also 256x4KB sectors) by default.

What would happen if you didn't align it?

If you don't align the partitions to multiples of 4KB, the worst that's going to happen is a performance loss (a fairly significant one for small files). Drives with 4KB sectors tend to emulate 512B sectors for compatibility with existing systems. So they function perfectly well if you just treat them as a 512B sector drive. But when you write to a single 512B area, it will rewrite a whole 4KB sector.

So, for performance reasons it's important to ensure that the 4KB clusters you use in your filesystem align with the 4KB sectors on the drive, so that a single cluster write won't result in needing to write two 4KB sectors on the drive.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .