]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libfdisk: (gpt) align size of partition by default
authorKarel Zak <kzak@redhat.com>
Thu, 27 Jan 2022 09:50:45 +0000 (10:50 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 27 Jan 2022 11:35:01 +0000 (12:35 +0100)
commit921c7da55ec78350e4067b3fd6b7de6f299106ee
treeffd27896a54a7ace8a8468a36045acb3f709b5da
parent064604a3174e1d4057060256851ca26e801dba04
libfdisk: (gpt) align size of partition by default

LastUsableLBA (field in GPT header) is calculated to use all free
space on the device. The problem is that size of this area is
unaligned to optimal I/O (or physical sector size) on devices where
the logical sector is 512 bytes, but the physical sector size is 4K.
(Note that after LastUsableLBA is backup GPT header and size of this
backup is calculated by logical sectors.)

The problem is visible for the last partition on the device because
this partition ends on LastUsableLBA.

The ideal solution would be align directly LastUsableLBA number in the
GPT header. Unfortunately, this solution is useless for libfdisk,
because we have to be backwardly compatible with sfdisk scripts
generated by old versions where is explicitly specified partition
size.

It seems usable compromise is to align only last partition if the size
of the partition is unspecified or specified by relative number
(+100M) -- in this case we already align partition, so there is no
change in fdisk semantic (well, last partition will be smaller than in
previous libfdisk versions).

The unaligned partition size is a problem for dm-crypt where device
size is used dynamically, and when unaligned, DM uses 512-bytes with a
negative impact on performance.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2044108
Addresses: https://marc.info/?l=dm-crypt&m=164306225923513&w=2
Signed-off-by: Karel Zak <kzak@redhat.com>
13 files changed:
libfdisk/src/gpt.c
tests/expected/fdisk/gpt-resize
tests/expected/libfdisk/gpt-all-defaults
tests/expected/libfdisk/gpt-all-defaults-with-typo
tests/expected/libfdisk/mkpart-gpt
tests/expected/sfdisk/gpt-all-defaults
tests/expected/sfdisk/gpt-attrs
tests/expected/sfdisk/gpt-attrs-guid
tests/expected/sfdisk/gpt-attrs-space
tests/expected/sfdisk/gpt-attrs-with-typo
tests/expected/sfdisk/wipe-gpt-to-dos
tests/expected/sfdisk/wipe-gpt-to-dos-auto
tests/expected/sfdisk/wipe-partition