Skip to content

usb(macOS): connect a saved USB device when it is plugged in again - #8133

Open
UTMapp-bot wants to merge 1 commit into
mainfrom
usb/reconnect-saved-device
Open

UTMapp-bot wants to merge 1 commit into
mainfrom
usb/reconnect-saved-device

Conversation

@UTMapp-bot

@UTMapp-bot UTMapp-bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Stack 2/2 — stacked on #8134; merge the stack bottom-up.

A USB device set to "Auto connect on start" was only connected when the virtual machine started. When it was unplugged and plugged in again while the VM ran, or restarted itself as a device does after a firmware update, UTM asked whether to connect it, or did nothing when the prompt is turned off or the VM window is not in front.

Such a device is now connected when it appears, without asking. A device that another VM has, or that this VM has no room for, is left alone without an alert. The menu item keeps its name.

The idea and a first version are from @giovariot in #7928 and the commit is in their name. Differences from that version: whether a device is saved is looked up off the main thread (it reads the device's descriptors, and this now runs for every device that is plugged in), a secondary window that gets the event hands the connect to the primary one, and a device this VM already has is skipped.

Testing

Tested by an AI agent on a MacBook Pro M2 Max, macOS 27.2 (26B123), with Debug builds of the macOS scheme. A person unplugged and plugged in the drive when the test asked for it.

Setup: a Seagate 4 TB drive (0bc2:ab28) on a 5 Gb/s link, an Ubuntu 26.04 arm64 guest on a USB 3.0 controller. I cannot click the "Auto connect on start" menu item, so both builds had a temporary change (not in this PR) that makes isAutoConnect true for this drive. The VM is started, which connects the drive (auto connect on start), then the drive is unplugged for about 5 s and plugged in again.

  • Before (usb(macOS): unmount a drive's volumes before connecting it to a VM #8134 without this commit): after the replug the guest has no disk, the volume is mounted on the Mac again, and the VM window shows "Would you like to connect 'BUP BK (2:2)' to this virtual machine?".
  • After: 10 s after the replug the guest has the 3.6 TB disk again (new SuperSpeed USB device number 3 using xhci_hcd) and reads from it at 117 MB/s. No prompt. Run twice, once before and once after the changes from review.
  • After, a disconnect by hand (the scripting disconnect command): 25 s later the drive is still with the Mac and its volume is mounted. A saved device that is handed back does not come back by itself.
  • Auto connect on start works as before in both builds.

The static checks pass.

Not tested: a VM with a second display or serial window (the case the secondary-window change is for), a device that restarts itself, two VMs with the same saved device, and the real menu setting (the temporary change stood in for it).

Notes from review

  • A saved device that is plugged in while the VM is paused is not connected when the VM resumes.
  • A second device of the same model with no serial number is connected without a prompt, as it already is on start.
  • The connect now starts as soon as the device appears, before macOS has mounted its volumes, so there is usually nothing to unmount.

A USB device set to "Auto connect on start" was only connected when the
virtual machine started. When it was unplugged and plugged in again while
the virtual machine ran, or restarted itself as a device does after a
firmware update, UTM asked whether to connect it, or did nothing when
the prompt is turned off or the window is not in front.

Connect such a device when it appears, without asking. A device that
another virtual machine has, or that this one has no room for, is left
alone without an alert.

The idea and a first version are from giovariot in #7928.

Assisted-by: OpenCode:deepseek-v4.1-flash
Assisted-by: Claude:claude-fable-5-2
@osy
osy force-pushed the usb/reconnect-saved-device branch from c848ba9 to c0c4100 Compare November 12, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants