Repository navigation
update: warn before reboot when root Btrfs spans a second LUKS device #12932
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
Open
kvnloo
wants to merge
16
commits into
omacom:quattro
Choose a base branch
from
kvnloo:salvage/t1-install-arch-recut-20260922
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+268
−0
Open
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4b92921
feat(update): detect extra encrypted Btrfs root members
kvnloo f3673ab
feat(update): surface encrypted multi-device Btrfs risk
kvnloo 66bfee2
test(btrfs): distinguish extra LUKS from same-container members
kvnloo 8fe1ec1
feat(menu): add x86_64 hardware predicate
kvnloo 65eb801
fix(menu): hide unavailable x86-only installers on ARM
kvnloo 63cde0f
test(menu): pin current architecture-gated installer set
kvnloo a884685
test(hw): cover x86_64 architecture predicate
kvnloo 5f7584a
fix(bin): mark install/arch salvage helpers executable
kvnloo fb1ba61
fix(test): repair root-btrfs-extra-luks suite from #11023
kvnloo ee35e98
fix(storage): compare flat LUKS ancestor names
kvnloo eb8c5cb
test(storage): detect tree-form LUKS false warnings
kvnloo 5b90667
Merge current quattro; retain focused Btrfs extra-LUKS warning
kvnloo c23d9f1
fix(storage): use authorized noninteractive sudo and conditional guid…
kvnloo d9798e7
test(storage): require sudo -n and fail open without authorization
kvnloo 845674b
test(storage): assert the updated conditional warning wording
kvnloo f8a31ac
test(storage): exercise unencrypted Btrfs member instead of empty fix…
kvnloo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Warn when the root Btrfs spans extra LUKS devices the initramfs cannot unlock | ||
| # omarchy:hidden=true | ||
|
|
||
| # Stock encrypt opens one cryptdevice=. A second LUKS-backed Btrfs member is | ||
| # committed by `btrfs device add` immediately, so the next reboot drops to | ||
| # initramfs. Fail-open when the tools that would prove that are missing. | ||
| if omarchy-cmd-missing btrfs || omarchy-cmd-missing lsblk || omarchy-cmd-missing findmnt; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| fstype=$(findmnt -no FSTYPE / 2>/dev/null) || exit 0 | ||
| if [[ $fstype != "btrfs" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| src=$(findmnt -no SOURCE / 2>/dev/null) || exit 0 | ||
| src=${src%%\[*} | ||
| if [[ -z $src ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| show=$(btrfs filesystem show / 2>/dev/null) || exit 0 | ||
|
|
||
| members=() | ||
| while IFS= read -r line; do | ||
| if [[ $line =~ devid[[:space:]]+[0-9]+.*path[[:space:]]+([^[:space:]]+) ]]; then | ||
| members+=("${BASH_REMATCH[1]}") | ||
| fi | ||
| done <<<"$show" | ||
|
|
||
| if (( ${#members[@]} < 2 )); then | ||
| exit 0 | ||
| fi | ||
|
|
||
| first_luks_ancestor() { | ||
| local device=$1 name member_fstype | ||
|
|
||
| while read -r name member_fstype; do | ||
| if [[ $member_fstype == "crypto_LUKS" ]]; then | ||
| printf '%s\n' "$name" | ||
| return 0 | ||
| fi | ||
| done < <(lsblk -nslpo NAME,FSTYPE "$device" 2>/dev/null) | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| root_luks=$(first_luks_ancestor "$src" || true) | ||
|
|
||
| extra_luks=0 | ||
| for member in "${members[@]}"; do | ||
| member_luks=$(first_luks_ancestor "$member" || true) | ||
| if [[ -n $member_luks && $member_luks != "$root_luks" ]]; then | ||
| extra_luks=1 | ||
| break | ||
| fi | ||
| done | ||
|
|
||
| if (( extra_luks )); then | ||
| echo -e '\e[33mWarning: root Btrfs spans extra LUKS devices the initramfs cannot unlock. Stock encrypt opens only cryptdevice=, so the next reboot will drop to initramfs. Remove the extra member before rebooting.\e[0m' >&2 | ||
| exit 1 | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| helper="$ROOT/bin/omarchy-root-btrfs-extra-luks" | ||
| analyze_logs="$ROOT/bin/omarchy-update-analyze-logs" | ||
| hooks="$ROOT/etc/mkinitcpio.conf.d/00-omarchy-hooks.conf" | ||
|
|
||
| [[ -x $helper ]] || fail "extra-LUKS helper exists" "missing $helper" | ||
| pass "extra-LUKS helper exists" | ||
|
|
||
| grep -q 'omarchy-root-btrfs-extra-luks' "$analyze_logs" || | ||
| fail "update-analyze-logs calls the extra-LUKS helper" | ||
| pass "update-analyze-logs calls the extra-LUKS helper" | ||
|
|
||
| grep -q 'omarchy-root-btrfs-extra-luks || true' "$analyze_logs" || | ||
| fail "update-analyze-logs does not block reboot on extra LUKS" | ||
| pass "update-analyze-logs does not block reboot on extra LUKS" | ||
|
|
||
| grep -q 'block encrypt filesystems' "$hooks" || fail "non-Apple busybox baseline still uses classic encrypt" | ||
| pass "non-Apple busybox baseline still uses classic encrypt" | ||
|
|
||
| test_tmp=$(mktemp -d) | ||
| trap 'rm -rf "$test_tmp"' EXIT | ||
|
|
||
| stub_bin="$test_tmp/bin" | ||
| mkdir -p "$stub_bin" | ||
|
|
||
| write_stub() { | ||
| local name="$1" | ||
| local body="$2" | ||
|
|
||
| cat >"$stub_bin/$name" <<SH | ||
| #!/bin/bash | ||
| $body | ||
| SH | ||
| chmod +x "$stub_bin/$name" | ||
| } | ||
|
|
||
| run_helper() { | ||
| PATH="$stub_bin:$ROOT/bin:$PATH" \ | ||
| "$helper" >"$test_tmp/out" 2>"$test_tmp/err" | ||
| } | ||
|
|
||
| write_stub findmnt ' | ||
| case " $* " in | ||
| *" FSTYPE "*) printf "%s\n" "${TEST_FSTYPE:-btrfs}" ;; | ||
| *" SOURCE "*) printf "%s\n" "${TEST_SOURCE:-/dev/mapper/root}" ;; | ||
| *) exit 1 ;; | ||
| esac | ||
| ' | ||
|
|
||
| write_stub btrfs ' | ||
| if [[ ${1:-} == "filesystem" && ${2:-} == "show" ]]; then | ||
| printf "%s\n" "$TEST_BTRFS_SHOW" | ||
| exit 0 | ||
| fi | ||
| exit 1 | ||
| ' | ||
|
|
||
| write_stub lsblk ' | ||
| # List mode suppresses tree prefixes that otherwise change ancestor names. | ||
| device=${*: -1} | ||
| case $device in | ||
| /dev/mapper/root|/dev/dm-0) | ||
| printf "/dev/mapper/root btrfs\n" | ||
| printf "/dev/nvme0n1p2 crypto_LUKS\n" | ||
| ;; | ||
| /dev/mapper/extra) | ||
| printf "/dev/mapper/extra btrfs\n" | ||
| printf "/dev/loop1 crypto_LUKS\n" | ||
| ;; | ||
| /dev/mapper/extra-same) | ||
| printf "/dev/mapper/extra-same btrfs\n" | ||
| if [[ ${1:-} == "-nslpo" ]]; then | ||
| printf "/dev/nvme0n1p2 crypto_LUKS\n" | ||
| else | ||
| printf "└─/dev/nvme0n1p2 crypto_LUKS\n" | ||
| fi | ||
| ;; | ||
| /dev/sdb) | ||
| printf "/dev/sdb btrfs\n" | ||
| ;; | ||
| *) | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| ' | ||
|
|
||
| two_device_show=$'Label: none uuid: 00000000-0000-0000-0000-000000000000\n Total devices 2 FS bytes used 1.00GiB\n devid 1 size 10.00GiB used 2.00GiB path /dev/mapper/root\n devid 2 size 10.00GiB used 0.00GiB path /dev/mapper/extra' | ||
|
|
||
| single_device_show=$'Label: none uuid: 00000000-0000-0000-0000-000000000000\n Total devices 1 FS bytes used 1.00GiB\n devid 1 size 10.00GiB used 2.00GiB path /dev/mapper/root' | ||
|
|
||
| same_luks_members_show=$'Label: none uuid: 00000000-0000-0000-0000-000000000000\n Total devices 2 FS bytes used 1.00GiB\n devid 1 size 10.00GiB used 2.00GiB path /dev/mapper/root\n devid 2 size 10.00GiB used 0.00GiB path /dev/mapper/extra-same' | ||
|
|
||
|
|
||
| plain_extra_show= | ||
| set +e | ||
| TEST_BTRFS_SHOW="$two_device_show" run_helper | ||
| status=$? | ||
| set -e | ||
| (( status == 1 )) || fail "two-device extra LUKS exits 1" "status=$status" | ||
| [[ -z $(<"$test_tmp/out") ]] || fail "two-device extra LUKS is silent on stdout" | ||
| grep -q "root Btrfs spans extra LUKS devices" "$test_tmp/err" || | ||
| fail "two-device extra LUKS prints a warning" "$(<"$test_tmp/err")" | ||
| pass "two-device extra LUKS warns and exits 1" | ||
|
|
||
| set +e | ||
| TEST_BTRFS_SHOW="$single_device_show" run_helper | ||
| status=$? | ||
| set -e | ||
| (( status == 0 )) || fail "single-device root is silent" "status=$status" | ||
| [[ -z $(<"$test_tmp/out") && -z $(<"$test_tmp/err") ]] || | ||
| fail "single-device root emits nothing" "out=$(<"$test_tmp/out") err=$(<"$test_tmp/err")" | ||
| pass "single-device root is silent" | ||
|
|
||
| set +e | ||
| TEST_BTRFS_SHOW="$plain_extra_show" run_helper | ||
| status=$? | ||
| set -e | ||
| (( status == 0 )) || fail "plain extra member is silent" "status=$status" | ||
| [[ -z $(<"$test_tmp/out") && -z $(<"$test_tmp/err") ]] || | ||
| fail "plain extra member emits nothing" | ||
| pass "plain extra member is silent" | ||
|
|
||
| set +e | ||
| TEST_BTRFS_SHOW="$same_luks_members_show" run_helper | ||
| status=$? | ||
| set -e | ||
| (( status == 0 )) || fail "members behind one LUKS mapping are safe" "status=$status" | ||
| [[ -z $(<"$test_tmp/out") && -z $(<"$test_tmp/err") ]] || | ||
| fail "same-LUKS members emit nothing" "out=$(<"$test_tmp/out") err=$(<"$test_tmp/err")" | ||
| pass "multiple Btrfs members behind the same LUKS container are silent" | ||
|
|
||
| missing_bin="$test_tmp/missing" | ||
| mkdir -p "$missing_bin" | ||
| set +e | ||
| PATH="$missing_bin:$ROOT/bin" "$helper" >"$test_tmp/out" 2>"$test_tmp/err" | ||
| status=$? | ||
| set -e | ||
| (( status == 0 )) || fail "missing btrfs is fail-open" "status=$status" | ||
| [[ -z $(<"$test_tmp/out") && -z $(<"$test_tmp/err") ]] || | ||
| fail "missing btrfs stays silent" | ||
| pass "missing btrfs is fail-open and silent" | ||
|
|
||
| set +e | ||
| TEST_FSTYPE=ext4 TEST_BTRFS_SHOW="$two_device_show" run_helper | ||
| status=$? | ||
| set -e | ||
| (( status == 0 )) || fail "non-btrfs root is silent" "status=$status" | ||
| pass "non-btrfs root is silent" | ||
|
|
||
| # findmnt SOURCE can be /dev/dm-N while `btrfs filesystem show` prints the | ||
| # mapper name; both still sit on the same crypto_LUKS ancestor. | ||
| same_luks_aliased_show=$'Label: none uuid: 00000000-0000-0000-0000-000000000000\n Total devices 2 FS bytes used 1.00GiB\n devid 1 size 10.00GiB used 2.00GiB path /dev/mapper/root\n devid 2 size 10.00GiB used 0.00GiB path /dev/sdb' | ||
| set +e | ||
| TEST_SOURCE=/dev/dm-0 TEST_BTRFS_SHOW="$same_luks_aliased_show" run_helper | ||
| status=$? | ||
| set -e | ||
| (( status == 0 )) || fail "same-LUKS mapper alias is silent" "status=$status" | ||
| [[ -z $(<"$test_tmp/out") && -z $(<"$test_tmp/err") ]] || | ||
| fail "same-LUKS mapper alias emits nothing" | ||
| pass "same-LUKS mapper alias is silent" | ||
|
|
||
| set +e | ||
| TEST_SOURCE=/dev/dm-0 TEST_BTRFS_SHOW="$two_device_show" run_helper | ||
| status=$? | ||
| set -e | ||
| (( status == 1 )) || fail "aliased root still warns on extra LUKS" "status=$status" | ||
| grep -q "root Btrfs spans extra LUKS devices" "$test_tmp/err" || | ||
| fail "aliased root still prints the extra-LUKS warning" | ||
| pass "aliased root still warns on extra LUKS" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.