bug: Add forceUnmountDisk function to handle APFS volumes on macOS#349
Open
billmcilhargey wants to merge 1 commit into
Open
bug: Add forceUnmountDisk function to handle APFS volumes on macOS#349billmcilhargey wants to merge 1 commit into
billmcilhargey wants to merge 1 commit into
Conversation
Contributor
|
A repository maintainer needs to approve these workflow run(s). To approve, maintainers can either: • Submit an approval review on this pull request, OR • Submit a review comment starting with Then re-run the failed job(s) via the Checks tab above. Reviews must be on the specific commit SHA of the workflow run to be considered. |
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.
Fix APFS-formatted drives hanging at "Starting" on macOS
Fixes balena-io/etcher#4490.
Problem
On macOS, flashing a drive that contains an APFS volume hangs indefinitely at the "Starting" stage. Users have worked around this by reformatting the drive to ExFAT or by manually deleting the APFS volume in Disk Utility before flashing.
Root cause
When opening a
BlockDevicefor write,BlockDevice._open(on non-Windows) callsmountutils.unmountDisk(device)before opening the raw device withO_EXLOCK.On macOS,
mountutils.unmountDiskis implemented with DiskArbitration:It is invoked against the parent BSD device (e.g. /dev/disk2). However, APFS volumes are exposed as a separate synthesized disk (e.g. /dev/disk3) backed by an APFS container partition on the parent. The whole-disk DADiskUnmount against the parent does not propagate to the synthesized APFS volumes, so they remain mounted. The subsequent O_EXLOCK open of the raw parent device then blocks/fails — which is what users see as the indefinite "Starting" hang.
This explains the reported workarounds: reformatting to ExFAT (no APFS container) and "Delete APFS Volume…" (removes the synthesized disk) both let mountutils succeed cleanly.
Errors from diskutil are intentionally swallowed (and logged via debug):
The preceding mountutils unmount may already have handled non-APFS volumes.
If the device truly cannot be unmounted, the subsequent open() will surface a meaningful error rather than masking it.