2

I've been reading about using a 4096Byte logical block size if my hard drive uses a physical 4096Byte block size for its sectors. So I just tried to create one on a spare hard drive, and I don't understand the warning at the final prompt. See below.

~$ cat /sys/class/block/sda/queue/physical_block_size
4096
~$ cat /sys/class/block/sda/queue/logical_block_size
512
server@Server:~$ sudo parted /dev/sda
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA WDC WD30EFRX-68A (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted) mklabel gpt
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes                                                               
(parted) mkpart primary 4096B 3001GB
Warning: You requested a partition from 4096B to 3001GB.                  
The closest location we can manage is 17.4kB to 3001GB.
Is this still acceptable to you?
Yes/No? n

Why can't I just use a 4096 block size?

thomasrutter
  • 37,804
john smith
  • 3,161

4 Answers4

4

The physical and logical block (sector) sizes are both determined by your disk hardware and cannot be changed. The vast majority of hard disks today use 512-byte logical sectors, although I've heard of some high-end disks that now use 4096-byte logical sectors. Some external enclosures also re-map the logical sector size to be 4096 bytes.

The combination of 512-byte logical sectors with 4096-byte physical sectors can result in performance problems if partitions are not aligned on multiples of 8 sectors. Most partitioning tools today handle this automatically -- in fact, they typically align on multiples of 2048 sectors (1 MiB), which of course is a multiple of 8 sectors and so works well. (Using 2048-sector alignment also works with many RAID and SSD products that require alignment on power-of-2 values higher than 8, which is why 2048 is the default.) Older tools aligned on "cylinder" boundaries. In the distant past (1980s-ish), cylinder alignment produced performance benefits; but then "cylinders" became a convenient fiction, then an inconvenient fiction, then a serious problem. Linux tools adjusted to these changes rather slowly, but today all the major programs ignore cylinders and use 2048-sector alignment by default.

You can adjust the alignment value to anything you like with gdisk -- you must type x to get to the experts' menu, then type d to change the alignment value. Note that this option is on the experts' menu for a reason: If you don't fully understand what you're doing, you're more likely to cause problems than solve them by using this feature. Even if you're an expert, the space savings from changing from 2048- to 8-sector alignment will be trivial (under 1MiB), so even I almost never do this. (I'm gdisk's author.)

Rod Smith
  • 45,120
  • 7
  • 66
  • 108
1
Warning: You requested a partition from 4096B to 3001GB.                  
The closest location we can manage is 17.4kB to 3001GB.
Is this still acceptable to you?

What this is saying is that due to other things at the beginning of the drive (metadata about the partitioning scheme or similar) the closest it can get to the start of the disk is 17.4kB in. You don't want this; you want it to start on a 4KiB boundary. So you should cancel and try again, this time requesting to start the partition on the first 4096B boundary beyond that point (try 20480B).

The reason you have to go through this manually is you're using a low level partitioning tool. A higher level tool like gparted will automatically align the start of a partition to a round number for you. These days many such tools will align partitions to a multiple of 1MiB (1024x1024 bytes) as this neatly solves both the 512byte, 4096 byte boundaries as well as aligning with blocks on things like USB flash drives.

thomasrutter
  • 37,804
0

Simply leave the calculation to parted using percents as units:

mkpart primary 0% 100%

Which should result in aligned partition:

(parted) print                                                            
Model: ATA SAMSUNG MZ7LM3T8 (scsi)
Disk /dev/sdb: 3841GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  3841GB  3841GB               primary
Tombart
  • 999
0

GPT needs the first 34 sectors of your disk to store

  • the protective MBR in the first sector (LBA 0),
  • the primary GPT-header in the second sector (LBA 1),
  • and up to 128 partition table entries in the following 32 sectors (LBA 2 - LBA 33)

These sectors are reserved, no other data can be stored in these sectors, a partition can not start in any of them.

34 sectors with a size of 512B = 17408B = 17.4kB

That's why you get the warning The closest location we can manage is 17.4kB to 3001GB.

You should not proceed here, it would lead to a bad alignment of the partition, this is already covered in other answers you received.

Note that also the last 33 sectors of the disk are reserved to keep a copy of the primary GPT-header and the partition table entries.

https://en.wikipedia.org/wiki/GUID_Partition_Table

mook765
  • 18,644