Subject: bug#63890: automatic alignment using 0% broken

From: Harald Dunkel <[email-masked]>
Date: Sun, 4 Jun 2023 12:09:12 +0200

Hi folks,

How comes that sometimes "mkpart test 0% ..." is properly aligned, and
sometimes it isn't? Sample:

{root@lola:code () 589} parted -a optimal /dev/sda
GNU Parted 3.5
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(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 test 0% 1%
(parted) u s p
Model: ASMT USB 3.0 TOSATA (scsi)
Disk /dev/sda: 976773168s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End       Size      File system  Name  Flags
  1      65535s  9764714s  9699180s               test

(parted) rm 1
(parted) mkpart test 0% 4GiB
Warning: The resulting partition is not properly aligned for best performance: 34s % 65535s != 0s
Ignore/Cancel? i
(parted) u s p
Model: ASMT USB 3.0 TOSATA (scsi)
Disk /dev/sda: 976773168s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End       Size      File system  Name  Flags
  1      34s    8388607s  8388574s               test

(parted)

{root@lola:code () 589} cat /sys/block/sda/queue/optimal_io_size
33553920
{root@lola:code () 590} cat /sys/block/sda/queue/minimum_io_size
512
{root@lola:code () 591} cat /sys/block/sda/alignment_offset
0
{root@lola:code () 592} cat /sys/block/sda/queue/physical_block_size
512

Why is the start of the partition not properly aligned for the 2nd mkpart?
It is "0%", as in the first case.

Is there some way to tell parted to *always* align start and end
properly, even if they were given in MiB instead of multiples of
65535s? I would be fine if parted adds a few sectors to the partition.

Regards
Harri