Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

growfs: workaround sfdisk + LUKS incompatibility on 512e disks #3033

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,28 @@ while true; do
part)
eval $(udevadm info --query property --export "${current_blkdev}" | grep ^DM_ || :)
if [ -n "${DM_MPATH:-}" ]; then
PKNAME=/dev/mapper/${DM_MPATH}
partnum=${DM_PART}
# Since growpart does not understand device mapper, we have to use sfdisk.
echo ", +" | sfdisk --no-reread --no-tell-kernel --force -N "${DM_PART}" "/dev/mapper/${DM_MPATH}"
echo ", +" | sfdisk --no-reread --no-tell-kernel --force -N "${partnum}" "${PKNAME}"
udevadm settle || : # Wait for udev-triggered kpartx to update mappings
else
partnum=$(cat "/sys/dev/block/${MAJMIN}/partition")
# XXX: ideally this'd be idempotent and we wouldn't `|| :`
growpart "${PKNAME}" "${partnum}" || :
fi
# If this is a 512e disk, then ensure the partition end is 4K
# aligned to be compatible with LUKS. If it's a 4Kn disk, `size`
# necessarily must be 4K aligned (note the sysfs value is always
# reported in 512b sizes). We should be able to drop this once
# https://github.com/util-linux/util-linux/issues/2140 is fixed.
size=$(cat "/sys/dev/block/${MAJMIN}/size")
phy_sec=$(blockdev --getpbsz "${PKNAME}")
if [ "$((size % 8))" != 0 ] && [ "${phy_sec:-}" = 4096 ]; then
size=$(((size >> 3) << 3)) # round down to nearest 4K boundary
echo ", ${size}" | sfdisk --no-reread --force -N "${partnum}" "${PKNAME}"
partx --update --nr "${partnum}" "${PKNAME}"
fi
;;
crypt)
# XXX: yuck... we need to expose this sanely in clevis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ install() {
inst_multiple \
basename \
blkid \
blockdev \
cat \
dirname \
findmnt \
Expand Down
1 change: 1 addition & 0 deletions tests/kola/root-reprovision/luks/512e/config.ign
1 change: 1 addition & 0 deletions tests/kola/root-reprovision/luks/512e/data
36 changes: 36 additions & 0 deletions tests/kola/root-reprovision/luks/512e/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
## kola:
## # This test reprovisions the rootfs.
## tags: "reprovision"
## # This uses additionalDisks, which is QEMU only
## platforms: qemu
## # Root reprovisioning requires at least 4GiB of memory.
## minMemory: 4096
## # A TPM backend device is not available on s390x to suport TPM.
## architectures: "! s390x"
## # This test includes a lot of disk I/O and needs a higher
## # timeout value than the default.
## timeoutMin: 15
## description: Verify that LUKS on a 512e disks works.
## primaryDisk: ":512e"

set -xeuo pipefail

# shellcheck disable=SC1091
. "$KOLA_EXT_DATA/commonlib.sh"

# sanity-check that it's a 512e disk
phy_sec=$(blockdev --getpbsz /dev/disk/by-id/virtio-primary-disk)
log_sec=$(blockdev --getss /dev/disk/by-id/virtio-primary-disk)
if [ "${phy_sec}" != 4096 ] || [ "${log_sec}" != 512 ]; then
fatal "root device isn't 512e"
fi

# sanity-check that LUKS chose a 4096 sector size
luks_sec=$(blockdev --getss /dev/mapper/myluksdev)
if [ "${luks_sec}" != 4096 ]; then
fatal "root LUKS device isn't 4k"
fi

# run the rest of the tests
. $KOLA_EXT_DATA/luks-test.sh
Loading