1

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?

4
  • Carefully reread: It's the start of the partition not the size block.
    – solsTiCe
    Nov 23, 2015 at 22:05
  • Oh. How do I set the block size? Also where can I find info about where to start my drive from? Surely it should just default to 0?
    – john smith
    Nov 23, 2015 at 22:16
  • You normally have to have space for gpt partitioning at beginning of drive. All new systems start now at sector 2048. Better to use gdisk or gparted as they automatically set everything correctly if you are not 100% sure of what you are doing. askubuntu.com/questions/201164/… And: rodsbooks.com/gdisk
    – oldfred
    Nov 23, 2015 at 22:38
  • Well I don't want to just "rely" on that. I want to understand how it works, and why my config is wrong.
    – john smith
    Nov 23, 2015 at 22:43

4 Answers 4

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.)

8
  • Wow, so glad you could share your help Rod. Given your understanding I'd like to elaborate on a few areas around this topic. Why does partitioning software measure computer units in mebibytes? Also, why do partitions align on multiples of 2048. I'm not sure what you mean by 2048 either, what is this referring to? The way I see it, is that surely if you have a 4096byte phsyical sector, you want your partitions to align at 4096 bytes?
    – john smith
    Nov 24, 2015 at 7:48
  • 1
    Nobody is saying 2048 bytes. On a drive with 4096 byte sectors, you want to align the starts of partitions to multiples of 4096 bytes, so that clusters in the partition begin on sector boundaries on the actual drive. You are getting confused by the part about 2048 sectors, so ignore that - the important part is that partitions begin on a multiple of 4096 bytes. You should consider using gparted so you don't need to worry about any of this. Nov 24, 2015 at 11:15
  • 1
    The mention of 2048 sectors was a passing reference to the fact that higher level partitioning tools tend to align partitions at 1MiB boundaries. Assuming the classic sector size of 512 bytes, that's 2048 sectors. You don't need to align at 1MiB boundaries in most cases; for old fashioned flash drives and SSDs without sector-level wear-levelling or dynamic reallocation it can help a little. Nov 24, 2015 at 11:33
  • John, disk storage is allocated in chunks of one sector (sometimes called a "block"), which has traditionally been 512 bytes in size. Thus, partition table data structures are defined in terms of sectors/blocks. To get sizes in bytes, you must multiply the number of sectors by the sector size (512 bytes). If you forget to do this, you'll become hopelessly confused. Advanced Format disks increase the physical sector size to 4096 bytes, but (to date) have maintained a 512-byte logical sector size for backwards compatibility purposes.
    – Rod Smith
    Nov 24, 2015 at 13:50
  • Concerning mebibyte units, see this page for information on SI vs. IEEE-1541 units. In brief, IEEE-1541 units are slightly larger than their closest SI counterparts, which leads to increasing confusion as disk sizes have grown.
    – Rod Smith
    Nov 24, 2015 at 13:52
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.

2
  • I don't understand this at all. Why would I want my partition to align at 2048bytes if I have a physical block size of 4096 bytes?
    – john smith
    Nov 24, 2015 at 7:50
  • I didn't say 2048 bytes. You want the start of your partition to be on a multiple of 4096 bytes. The first multiple of 4096 bytes you are allowed to use is 20480 bytes, since the first 17.4kB is reserved. That rules out using 0, 4096, 8192, 12288 or 16384, and so the next one is 20480. Nov 24, 2015 at 11:09
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
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

2
  • And what should you do instead? Mar 14, 2020 at 17:59
  • 1
    @IulianOnofrei Use better tools (like Gparted) to manage your partitions. You need proper background knowledge if you use command-line tools like parted, also you need to know the used commands well. Gparted takes care of proper alignment and takes care of filesystems inside the partitions. If you, for example, use parted to resize a partition, the filesystem would remain unchanged and you'd have to manage the filesystem size in an extra manual step.
    – mook765
    Mar 14, 2020 at 20:29

You must log in to answer this question.

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