Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
ChrisJ60
Posts: 5
Joined: 5. Dec 2023, 19:00

Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by ChrisJ60 »

I have an annoying situation:

VirtualBox 7.0.12 running on macOS Sonoma 14.1 on two separate but identical (and identically configured) Mac Mini 2018 (Intel) systems

One Mac mini (let's call it A) is connected to a Powercool UPS with USB monitoring.

The other Mac Mini (let's call it B) is connected to an APC UPS with USB monitoring.

On system A, if the UPS activates due to a power interruption, macOS does not react at all and everything continues blissfully unaware.

On system B, if the UPS activates due to a power interruption, macOS posts a system sleep event and then when power is restored macOS posts a system wake event. However the Mac itself does NOT sleep. Unfortunately, VirtualBox notices the host sleep event and automatically suspends any running VMs and then when the host posts the wake event it resumes the VMs. This is very annoying for me as it means that the VM hosted on this system becomes unavailable even though there is no reason for it be unavailable. Even worse, the VM in question (Windows 11 using bridged networking) often fails to regain network connectivity when it resumes, requiring a manual restart to fix it.

I don't know why macOS behaves differently in the two cases (I guess the UPS drivers are different for the two different UPS and maybe the is a factor) but I can't find any configuration options to control thsi behaviour at the macOS level.

Given that 99% of my power our=tages are of very short duration such that the UPS keeps everything running, I am wondering if there is some esoteric setting for VirtualBox to prevent it acting on the host suspend.resume events and thus avoiding the issue?

Thanks.
fth0
Volunteer
Posts: 5678
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by fth0 »

Funny thing is that usually VirtualBox users complain about the opposite, namely that host suspend/resume events are getting ignored when they shouldn't. ;)

Seriously, please provide a VBox.log file from a VM run with the suspend/resume events, and I'll have a look in the VirtualBox source code.
ChrisJ60
Posts: 5
Joined: 5. Dec 2023, 19:00

Re: Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by ChrisJ60 »

Thanks for the reply. I totally take your point that in general one does of course want VirtualBox to detect and react to the host sleeping and waking. My issue is that in this case the host does not actually sleep (or wake). These events seem to be bogus due to the UPS transition. This Mac is a 'server' and is on and awake 24x365 as it provides many services to my home network. The same is true for the VirtualBox VM (or at least it should be true, except for this issue). VBox.log file attached; look around line 1783 for one of the events that I described.
Attachments
VBox.log
(115.49 KiB) Downloaded 268 times
fth0
Volunteer
Posts: 5678
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by fth0 »

I've taken a look into the VirtualBox 7.0.12 source code:

VirtualBox unconditionally hooks into the host OS service for power management (e.g. IORegisterForSystemPower() on macOS hosts) and also unconditionally reacts on the corresponding events. With "unconditionally" I mean that there is no configuration item that would prevent it from happening. In consequence, you could only build a patched version of VirtualBox yourself or prevent the registration or events on the host OS's side.
ChrisJ60
Posts: 5
Joined: 5. Dec 2023, 19:00

Re: Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by ChrisJ60 »

Okay, many thanks for taking a look. Seems like I will have to approach this via a different route. There are ways that I can prevent the UPS notification reaching macOS (I can unplug the USB connection to the UPS!) but that is not necessarily a great solution. Anyway, I need to do some investigation.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by scottgus1 »

An idea pops to mind, try investigating this:
ChrisJ60 wrote: 5. Dec 2023, 19:02 VirtualBox 7.0.12 running on macOS Sonoma 14.1 on two separate but identical (and identically configured) Mac Mini 2018 (Intel) systems

One Mac mini (let's call it A) is connected to a Powercool UPS with USB monitoring.

The other Mac Mini (let's call it B) is connected to an APC UPS with USB monitoring.

On system A, if the UPS activates due to a power interruption, macOS does not react at all and everything continues blissfully unaware.

On system B, if the UPS activates due to a power interruption, macOS posts a system sleep event and then when power is restored macOS posts a system wake event.
Could it be differences in the UPS control apps, or something accidentally done differently when installing the apps?

One possible troubleshooting step: swap apps and UPS's between the Macs.
ChrisJ60
Posts: 5
Joined: 5. Dec 2023, 19:00

Re: Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by ChrisJ60 »

Yes, I am certain that it is indeed macOS reacting differently to the two UPS. However I do not have any 3rd party UPS control apps installed; this is all native macOS UPS support so I imagine I could log a bug with Apple (and maybe they will look at it sometime in the next decade perhaps).
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by scottgus1 »

ChrisJ60 wrote: 6. Dec 2023, 18:09 I do not have any 3rd party UPS control apps installed
I'm suggesting that the Powercool and APC apps might be behaving differently. I don't see any mention of a third app source in my suggestion.
ChrisJ60
Posts: 5
Joined: 5. Dec 2023, 19:00

Re: Is it possible to prevent VirtualBox VMs reacting to macOS host suspend/resume events?

Post by ChrisJ60 »

Yes, I know that is what you are suggesting. You said:
Could it be differences in the UPS control apps, or something accidentally done differently when installing the apps?

One possible troubleshooting step: swap apps and UPS's between the Macs.
I did not install any 'UPS apps'. There are no 'UPS apps' on either Mac, just the built in UPS support in macOS. I am 100% sure that if I switched the UPS around (which would be quite time consuming and disruptive) that the problem would move from one machine to the other.
Post Reply