Repository navigation
usb(macOS): unmount a drive's volumes before connecting it to a VM - #8132
Closed
UTMapp-bot wants to merge 1 commit into
Closed
UTMapp-bot wants to merge 1 commit into
UTMapp-bot wants to merge 1 commit into
Conversation
Connecting a USB drive to a QEMU virtual machine takes the device away from macOS at once. A volume that was still mounted went away with it, as if the drive had been unplugged: macOS never got to unmount it, and for a volume that can be written to it warns that the disk was not ejected properly. Ask macOS to unmount the volumes of the device first, and connect it only when that worked. If a volume is in use, the device is left with macOS and the user is told which volume it is. UTM is not allowed to mount a volume again, so whether the device can be connected at all is checked before anything is unmounted. The idea and a first version are from giovariot in utmapp#7928. This version finds the device by vendor, product, bus, port and serial number, names the volume and not its device node in the message, and has no timeout of its own, since DiskArbitration always answers. Resolves utmapp#5650 Assisted-by: OpenCode:deepseek-v4.1-flash Assisted-by: Claude:claude-fable-5-2
This was referenced Nov 11, 2026
Author
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.
Connecting a USB drive to a QEMU virtual machine takes the device away from macOS at once. A volume that was still mounted went away with it, as if the drive had been unplugged: macOS never got to unmount it, which for a volume that can be written to gives the "Disk Not Ejected Properly" warning of #5650.
UTM now asks macOS to unmount the volumes of the device first and connects it only when that worked. If a volume is in use, the device is left with macOS and an alert names the volume. This happens on every way to connect a device on macOS: the USB menu, the prompt when a device is plugged in, auto connect on start, and scripting.
The idea and a first version are from @giovariot in #7928 and the commit is in their name. This is a rewrite: it finds the device by vendor, product, bus, port and serial number, names the volume and not its device node (
disk12s2) in the message, and has no timeout or error-text matching of its own.Resolves #5650
Testing
Tested by an AI agent on a MacBook Pro M2 Max, macOS 27.2 (26B123), with a Debug build of the macOS scheme.
Setup: a Seagate 4 TB drive (0bc2:ab28) on a 5 Gb/s link with one NTFS volume, "New Volume", which macOS mounts read-only. Guest: Ubuntu 26.04 arm64 on a USB 3.0 controller; the drive is connected with the scripting
connectcommand. A small DiskArbitration client outside UTM prints unmount requests, unmounts and disk disappearances, and can refuse unmount requests to stand in for a volume that is in use.main): on connect the disks disappear with the volume still mounted. There is no unmount request.connectfails with "'New Volume' could not be ejected because it is in use. Close anything that is using it and try again." The volume stays mounted on the Mac and the guest gets no disk.connectfails with CocoaSpice's "Cannot connect an already connected usb device" and nothing is unmounted.The static checks pass.
Not tested:
Notes from review
kDAReturnNotPrivileged). So before anything is unmounted,canRedirectUsbDeviceis asked whether the connect can work. If the connect still fails afterwards, the volume stays unmounted until the drive is replugged or mounted in Disk Utility. The same goes for a drive with several volumes when a later one is in use.