[mount] Fix Btrfs subvolume collisions and implement safe mount rollback on failure - #248
Open
beyondbrokkoli wants to merge 1 commit into
Open
[mount] Fix Btrfs subvolume collisions and implement safe mount rollback on failure#248beyondbrokkoli wants to merge 1 commit into
beyondbrokkoli wants to merge 1 commit into
Conversation
beyondbrokkoli
force-pushed
the
patch-1
branch
3 times, most recently
from
July 14, 2026 10:57
d686744 to
35e3177
Compare
Fixes fatal unmount errors and live-environment corruption caused by nested Btrfs subvolume collisions during manual partitioning. - Isolates Btrfs subvolume creation inside a temporary sandbox directory. - Separates mount logic into two distinct passes: physical partitions first, virtual extra_mounts second. - Implements reverse-lexical error unwinding to guarantee clean unmounts and unlock drives upon failure. - Adds target directory verification and filesystem compatibility checks to prevent silent data destruction. - Removes unused Btrfs swap-to-file and raw Btrfs root mount logic (disabled in CachyOS) to streamline subvolume iteration.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes fatal installer crashes caused by Btrfs subvolume collisions with custom manual partitions (e.g., placing
/varon a separate drive). It introduces a major refactor to the mount module to enforce strict state-machine safety, including an isolated Btrfs creation sandbox, a two-phase mounting sequence, and reliable rollback mechanisms for failed installs.(Note: This replaces closed PR #166. Changes have been squashed into a single commit for a clean, linear history).
Motivation: Why this is necessary for Manual Partitioning
While standard layouts execute without issue, the current mount logic lacks the defensive guardrails necessary to safely process complex manual partitioning. To ensure strict damage control and prevent custom layouts from causing unrecoverable state failures, this refactor addresses the following structural limitations:
/var(e.g., an XFS drive), the installer fails to check for nested paths. It attempts to create/@cacheand/@logsubvolumes anyway, which either fails against the incompatible filesystem or shadows the mount points entirely, crashing the installation./proc,/sys,/dev) into a single array and sorts them lexically. This leads to unpredictable mount orders where API filesystems can be bound before their parent physical directories are ready.The Implementation
This refactor structurally isolates Btrfs creation, separates mount phases, and guarantees that installation failures cleanly release all block devices—sparing the user from having to reboot the live ISO just to try again.
calam-btrfs-). The script verifies targets do not already exist, creates them, unmounts the sandbox, and only then safely mounts the/@root.extra_mounts) are strictly mounted afterward to respect standard hierarchy and prevent remount tangling.active_mounts): Introduced a centralizederr()function. On any failure, it walks theactive_mountstracker in reverse order, safely unwinding and unmounting everything so drives are never locked./homeand/srv) are now strictly checked for pre-existing data (ignoring standard cross-platform metadata likelost+found). Incompatible filesystems (e.g.,ext3,fat16on root) are explicitly trapped and blocked early in the validation phase.Testing Methodology
I spent two weeks heavily testing this logic across bare-metal environments and Proxmox VMs, intentionally passing hostile layouts to break the installer:
/homeoverwrites still function as intended, while dirty system targets properly abort the install safely.zfs.confdataset structure inherently restrict reliable ZFS deployment to the/root. Rather than expanding the scope of this PR to completely rewrite the ZFS module, I systematically verified that standard ZFS root installations remain fully functional and can now safely coexist with custom manual mount points on other filesystems.Design Philosophy & Error Handling
raise Exception). By avoiding manual error-checking boilerplate, we guarantee that the millisecond a data constraint or mount operation fails, execution is strictly halted. This ensures no downstream code can silently execute due to a missed return check, prioritizing absolute data safety over a cosmetically pretty GUI pop-up. The resulting stack trace provides highly precise, immediate feedback on exactly which partitioning rule was violated.err()function handles its own teardown state by reversing throughactive_mountsbefore throwing the final exception. This decouples the safety of the block devices from the upstream C++ error handlers. By cleaning up the mounts autonomously at the exact point of failure, we guarantee the drives are instantly unlocked and the live environment remains perfectly usable, regardless of how the installer's front-end reacts to the exception.