17

First I create a properly aligned partition in a new GPT table using parted by specifying percentages for start and end of the partition:

# parted -a optimal /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Y
(parted) mkpart primary 0% 1%
(parted) p
Model: ATA WDC WD30EZRX-00M (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  2097kB  1049kB               primary

(parted) quit

Note that this disk is using Advanced Format, but correctly reports the physical sector size of 4096B to Parted. Let's look at it again, using sectors as the unit:

# parted -a optimal /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s
(parted) p
Model: ATA WDC WD30EZRX-00M (scsi)
Disk /dev/sdb: 5860533168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End    Size   File system  Name     Flags
 1      2048s  4095s  2048s               primary

(parted) quit
  • Why did it start the partition at 2048s and not 34s which is the first possible sector?
  • 34s is not a properly aligned start sector if the physical sector size is 4096B and the logical (which is the one you specify in Parted) sector size is 512B. A properly aligned start sector is one divisable by 8 (since physical sector size / logical sector size = 8). But that means 40s is the first properly aligned start sector, yet it's not used. Why?

If we try to create a properly aligned partition of 100MiB capacity starting at 40s in a fresh GPT partition table:

# parted -a optimal /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Y
(parted) mkpart primary 40s 204839s
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I
(parted) unit MiB
(parted) p
Model: ATA WDC WD30EZRX-00M (scsi)
Disk /dev/sdb: 2861588MiB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start    End     Size    File system  Name     Flags
 1      0.02MiB  100MiB  100MiB  fat32        primary

(parted)
(parted) unit s
(parted) p
Model: ATA WDC WD30EZRX-00M (scsi)
Disk /dev/sdb: 5860533168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End      Size     File system  Name     Flags
 1      40s    204839s  204800s  fat32        primary

(parted)
  • We still get the Warning: The resulting partition is not properly aligned for best performance. warning, even though 40s and 204840s (204839s + 1) are both divisable by 8. Why?

2 Answers 2

24

Parted is just being overly conservative. The usual practice these days is to align partitions on 1MiB (2048-sector) boundaries because this works on Advanced Format disks, on certain type of RAID setups that require alignment, and on most SSDs. For an Advanced Format disk, so long as the alignment is on a multiple of 8, you're fine, and 2048 is a multiple of 8. The lost disk space is puny -- 0.0000336% of your total disk space, if I did the math right and didn't mistype anything. So don't worry about it; just use the 1MiB alignment.

3
  • Yes the lost disk space doesn't matter to me. I just wanted to know that I understood things correctly. I'm checking Parted's source code at the moment, but it takes a bit longer than I have time. So I'll just go ahead and use 1MiB-alignment. Thanks for helping out yet again!
    – Deleted
    Oct 15, 2012 at 18:20
  • 1
    It's worth to mention this is not merely conservativeness of parted but rather a limitation of Linux block layer. ATA drives don't provide optimal_io_size hint. Hence, there's no way to distinguish between "legacy" ATA devices that do not provide alignment_offset and alignment_offset defaults to 0 and the ones that that have alignment_offset=0. fdisk/parted use 1MB partition alignment for such drives.
    – roolebo
    Jul 16, 2019 at 11:47
  • 1
    And the number itself - 1MB partition alignment seems to come from Windows Vista behavior, as referenced in the parted commit.
    – roolebo
    Jul 16, 2019 at 14:40
1

I shall probably add that on Linux one can come in a situation where parted may never pass an optimal and a minimal alignment check at the same time.

The reason for this is that parted ( at least as of version 3.2 ) relies on libblkid, which in turn reports values from /sys/block/<disk>/queue/minimum_io_size and /sys/block/<disk>/queue/optimal_io_size ( see io-limits.txt ).

So while for an Advanced Format disk the former is likely to be something like 4k, the latter can have some mad value -- e.g. 65535 * 512 == 33553920.

Now if we look at the source code -- "proper", or "best performance" alignment is defined by the formula in parted.c::partition_align_check():

part->geom.start % pa->grain_size == pa->offset, 

where grain_size comes from I/O block size above, geom.start is our partition offset, and alignment offset pa->offset is quite frequently zero.

By default, parted would assume 1 MiB to be an optimal, and ~4k to be the minimal ( not quite so, it is a bit of a simplification ) block size, so these values would correlate ; however, if libblkid decides otherwise, parted tends to trust it, and replace that default value of 1 MiB with the value found in /sys/block/<disk>/queue/optimal_io_size. ( At the same time, /sys/block/<disk>/queue/minimum_io_size will quite likely give you the same 4096 B. )

In that case, parted optimal check will never pass simultaneously with the minimal check, what could possibly be a little confusing.

With that in mind -- if in doubt, have a look at queue/optimal_io_size and queue/minimum_io_size, and if the former is not divisible by the latter, just ignore parted' warning, and decide for yourself whether do you want to go with an optimal or a minimal check.

You must log in to answer this question.

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