From 1fd59fcb26574c733736970077ef02a7ebb1d5b5 Mon Sep 17 00:00:00 2001 From: Nikita Dubrovskii Date: Thu, 30 Sep 2021 10:44:30 +0200 Subject: [PATCH] overlay.d: abort booting if system has more than 1 'boot' partition Inspired by: https://github.com/coreos/fedora-coreos-tracker/issues/976 Signed-off-by: Nikita Dubrovskii --- .../coreos-ensure-single-partition.sh | 17 +++++++++++++++++ .../35coreos-ignition/coreos-gpt-setup.service | 1 + .../modules.d/35coreos-ignition/module-setup.sh | 3 +++ 3 files changed, 21 insertions(+) create mode 100755 overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-ensure-single-partition.sh diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-ensure-single-partition.sh b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-ensure-single-partition.sh new file mode 100755 index 0000000000..a3d1c8fe2d --- /dev/null +++ b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-ensure-single-partition.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# checks and aborts the boot if system has several partitions with label specified by $1 + +set -euo pipefail + +PARTITIONS=() +mapfile -t PARTITIONS < <(lsblk -o LABEL,NAME --pairs --paths --noheadings | grep "LABEL=\""$1"\"") + +LENGTH=${#PARTITIONS[@]} +if [[ ${LENGTH} -gt 1 ]]; then + echo "System has "${LENGTH}" partitions with '"$1"' label:" + for PT in "${PARTITIONS[@]}"; do + echo "${PT}" + done + echo "Please 'wipefs' other partitions/disks and reboot. Aborting..." + exit 1 +fi diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-gpt-setup.service b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-gpt-setup.service index f14f2e72f5..28cd4f2d68 100644 --- a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-gpt-setup.service +++ b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-gpt-setup.service @@ -33,4 +33,5 @@ OnFailureJobMode=isolate [Service] Type=oneshot RemainAfterExit=yes +ExecStartPre=/usr/sbin/coreos-ensure-single-partition boot ExecStart=/usr/sbin/coreos-gpt-setup /dev/disk/by-label/boot diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/module-setup.sh b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/module-setup.sh index a42bcc3724..3671cb2f4f 100755 --- a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/module-setup.sh +++ b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/module-setup.sh @@ -30,6 +30,9 @@ install() { inst_script "$moddir/coreos-gpt-setup.sh" \ "/usr/sbin/coreos-gpt-setup" + inst_script "$moddir/coreos-ensure-single-partition.sh" \ + "/usr/sbin/coreos-ensure-single-partition" + inst_script "$moddir/coreos-ignition-setup-user.sh" \ "/usr/sbin/coreos-ignition-setup-user"