Fix: Add FileVault support and proper volume mounting in Recovery Mode - #144
Fix: Add FileVault support and proper volume mounting in Recovery Mode#144nostitos wants to merge 2 commits into
Conversation
Ports the core fix from upstream PR assafdori#144 onto bypass-mdm-enhanced.sh: APFS volumes aren't auto-mounted in Recovery, and on modern FileVault-encrypted Macs the old inline unlock never ran because detect_volumes errored out first when /Volumes/Data didn't exist. Adds a mount_data_volume() step that resolves the disk identifier, detects FileVault/Locked status, unlocks via passphrase with a 3-attempt retry, and falls back across four mount strategies. Also redirects warn/success/info to stderr so status messages no longer leak into command-substitution captures. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Revisão técnica do PR #144 — FileVault + volume mount@nostitos, boas correções. Vou pontuar: Acertos
Problema: conflito com #170O PR #170 (marclllaks) cria um SugestãoEm vez de modificar o v2, considere:
Sua solução de output >&2 é superior à do v3 (que usa misto de Bug menorA variável |
|
Hey @nostitos, solid fixes here. The FileVault unlock and explicit volume mounting are real issues that people hit all the time. A couple thoughts: Good stuff:
The conflict problem: marclllaks just opened #170 with a v3 script that solves the same FileVault/mount issues but goes further — it also blocks iprofiles.apple.com, disables the enrollment daemon via launchd on the Data volume, and supports macOS 26. Since you both modified similar parts of v2, these PRs conflict. My suggestion: rather than both trying to land conflicting changes to v2, it might make more sense to rebase your fixes on top of v3 or collaborate with marclllaks to fold your improvements into v3. Your mount fallback logic is actually more thorough than what v3 has right now (v3 tries mount then unlock, but your version has more intermediate steps). Up to you, but thats the path Id take. |
|
FileVault encrypted Macs are now the default on Apple Silicon, so this is a must-fix. The key issue is that diskutil apfs list shows the volume but it's locked — you need to call diskutil apfs unlockVolume with the user password or recovery key before you can write to it. The correct detection flow is:
Creating a dummy /Users/Apple to fake the path won't work — it needs the actual FileVault unlock. For reference, unleash (github.com/mateussiqueira/unleash) handles this flow automatically in its detect.sh. |
Summary
This PR fixes critical issues that prevent the script from working on modern Macs with FileVault encryption enabled (which is the default).
Problems Fixed
1. FileVault Encrypted Volumes Not Supported (Critical)
Issue: When the Data volume is encrypted with FileVault (default on modern macOS), the script fails with "Could not detect data volume".
Root Cause: The script assumes volumes are accessible if they exist in
diskutil list, but FileVault-encrypted volumes are locked in Recovery Mode and must be unlocked first.Solution: Added detection for encrypted volumes and prompt for FileVault password to unlock using
diskutil apfs unlockVolume.2. Data Volume Not Automatically Mounted (Critical)
Issue: In Recovery Mode, APFS volumes are NOT mounted by default. The script checks if
/Volumes/Dataexists but it doesn't until explicitly mounted.Solution: Added
mount_data_volume()function that:diskutil listdiskutil mount3. Output Functions Pollute Captured Data (Bug)
Issue: The
info(),success(),warn(), anddebug()functions output to stdout, corrupting values captured via command substitution.Example:
Solution: All output functions now redirect to stderr (
>&2), ensuring only the finalecho "$system_vol|$data_vol"is captured.4. No Mount Verification
Issue: The script doesn't verify that the Data volume actually got mounted before using it.
Solution: Added explicit checks with
if [ -d "/Volumes/Data" ]after mount attempts.5. Incorrect Volume Detection
Issue: The detection logic could mistake "macOS Base System" (Recovery OS) for the Data volume.
Solution: Improved filtering to exclude Recovery volumes from data volume detection.
Changes Made
mount_data_volume()function with multiple mount strategiesTesting
Tested on:
Related Issue
Fixes #143
Checklist