4

I have some HDD disk which has 4096 physical sector size and 512 bytes logical size. It is SATA disk. Now I'd like to use 4kiB in Linux as a logical also sector size - not 512 bytes one. How can I achieve this? Is it possible to switch this disk to operate only in 4kiB mode?

How can I be sure that all the partitions I created are aligned to 4kiB? Do I have to manually calculate start and end sector numbers of given partition to have 4kiB alignment?

I'm using Linux and sometimes Windows. Mainly I'm creating partitions using Linux fdisk - not Windows one. Maybe using of "fdisk -b 4096" is enough solution? Hm... Probably not, because how Linux will be know which sector size given disk uses?

4

Unless you use options to force a legacy MS-DOS compatible mode, or use expert mode to specify exact LBA block numbers for the beginning and end of partitions, most modern partitioning tools (Linux and otherwise) will align partitions to multiples of 1MB by default. This is also what modern Windows does, and it guarantees compatibility with both 4kB sector size and various SSD and SAN storage devices which might require alignment to larger powers of two for optimal performance.

You can use lsblk -t to check the alignment offsets of each partition. If the value in the ALIGNMENT column is zero, then as far as the kernel knows, the partition should be optimally aligned.

To switch the HDD sector size, you would first need to verify that your HDD supports the reconfiguration of the Logical Sector Size. Changing the Logical Sector Size will most likely make all existing data on the disk unusable, requiring you to completely repartition the disk and recreate any filesystems from scratch. The hdparm --set-sector-size 4096 /dev/sdX would be the "standard" way to change the sector size, but if there's a vendor-specific tool for it, I would generally prefer to use it instead - just in case a particular disk requires vendor-specific special steps.

On NVMe SSDs, nvme id-ns -H /dev/nvmeXnY will tell (among other things) the sector size(s) supported by the SDD, the LBA Format number associated with each sector size, and the currently-used sector size. If you wish to change the sector size, and the desired size is actually supported, you can use nvme format --lbaf=<number> /dev/nvmeXnY to reformat a particular NVMe namespace to a different sector size.

3
  • Regarding using of "hdparm --set-sector-size..." - is this permanent setting? I mean is it enough to do this only once and even after the reboot the logical sector size will be as I set before reboot? – user2699113 Jan 25 '20 at 7:39
  • 1
    I haven't personally tested this, but I would very much expect changing the logical sector size to be a persistent setting, as it makes a pretty fundamental change to how the data is accessed. But that is one of the reasons why I'd recommend using a vendor-specific tool for that job, if one is available: if a particular disk model needs something special to make the setting persist, a vendor-specific tool would "know" for sure how to do it right. – telcoM Jan 25 '20 at 9:21
  • Finally someone that answers how to do this in a NVMe disk! THANKS A LOT! – TanisDLJ Jul 22 '20 at 10:50
1

As the block counter is 32 wide, you can address with this counter max of 2TB disk space divided by 512 B sectors. Hence the min. addressable portion of the modern disk is called cluster and usualy is of the 4096 = 8 x 512 Bytes. Even the internal buffers and programs deals still with 512B sector it is just the logical interpretation only. In the man fdisk you can read: Recent kernels know the sector size. Use this option only on old kernels or to override the kernel's ideas. You, mainly on linux, do not need to do any changes of the default configurations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.