summaryrefslogtreecommitdiff
path: root/installer/configure-target-gpt-root.sh
diff options
context:
space:
mode:
authortranch <tranch.xiao@gmail.com>2026-09-13 19:18:04 +0800
committertranch <tranch.xiao@gmail.com>2026-09-13 19:18:04 +0800
commit796c6c8a70c92d4675df7c2ec2d25ecda139d723 (patch)
tree06c6d3e7788d7b2ad5ddd0565e2651c0c8d9d151 /installer/configure-target-gpt-root.sh
parentab070aec5f1d760a2539e14cb19da61593bded15 (diff)
parentd734f2c746632772b794143762f2fcea78e62011 (diff)
downloadAeroCore-OS-796c6c8a70c92d4675df7c2ec2d25ecda139d723.tar.gz
AeroCore-OS-796c6c8a70c92d4675df7c2ec2d25ecda139d723.zip
Merge testing into main for 44.x stable release44.20260913
Diffstat (limited to 'installer/configure-target-gpt-root.sh')
-rwxr-xr-xinstaller/configure-target-gpt-root.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/installer/configure-target-gpt-root.sh b/installer/configure-target-gpt-root.sh
new file mode 100755
index 0000000..6c1a2d1
--- /dev/null
+++ b/installer/configure-target-gpt-root.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+target_root=${1:?usage: configure-target-gpt-root.sh TARGET_ROOT}
+
+source_device="$(findmnt --nofsroot -no SOURCE --target "${target_root}")"
+# For a Btrfs subvolume, findmnt decorates the backing device with the
+# subvolume path (for example, /dev/vda3[/root]). lsblk and the partition
+# validation below require the undecorated block-device path.
+source_device="${source_device%%\[*}"
+# Anaconda can bind-mount the target at /mnt/sysroot. In that case findmnt's
+# human-readable SOURCE is "root", even though the mounted filesystem still
+# has the real target partition's device number. Resolve that number through
+# lsblk before requiring a partition-backed source.
+if [[ ! "${source_device}" =~ ^/dev/ ]]; then
+ source_maj_min="$(findmnt -no MAJ:MIN --target "${target_root}")"
+ source_device="$(lsblk -nrpo NAME,MAJ:MIN | awk -v wanted="${source_maj_min}" '$2 == wanted { print $1; exit }')"
+fi
+case "${source_device}" in
+ /dev/*[0-9]) ;;
+ *)
+ echo "Could not resolve a partition-backed target root: ${source_device}" >&2
+ exit 1
+ ;;
+esac
+
+parent_device="$(lsblk -no PKNAME "${source_device}")"
+partition_number="$(lsblk -no PARTN "${source_device}")"
+if [[ -z "${parent_device}" || -z "${partition_number}" ]]; then
+ echo "Could not resolve parent disk and partition number for ${source_device}" >&2
+ exit 1
+fi
+
+disk="/dev/${parent_device}"
+root_type_guid="4f68bce3-e8cd-4db1-96e7-fbcaf984b709"
+echo "Setting ${source_device} (partition ${partition_number} on ${disk}) to GPT root-x86-64 type ${root_type_guid}"
+sgdisk --typecode="${partition_number}:${root_type_guid}" "${disk}"
+partprobe "${disk}" || true