VirtualBox, Linux distributions, black screen after inactivity

Updated: October 30, 2024

Running operating systems as virtual machines is a pretty magical thing. You want to try something, but you don't have spare hardware? No issue. Power on a hypervisor, create a virtual machine, and then inside it, test whatever you need, be it Windows, Linux, DOS, or something even more arcane and ancient. This elegant magic brings in a few complexities of its own. Like display configuration, 3D acceleration, and associated problems.

I have already talked about the Linux black screen problem in VirtualBox a while back. That tutorial still stands. But now, I've encountered a brand new issue. This one manifests inside a running system, not on login. What happens is, you boot your distro, you let it be, you come back after a period of idleness. The screen will have timed out and turned dark/black in the guest operating system. The problem is, when you try to "wake" it, as any one action will normally do (e.g.: move your mouse cursor), the screen will stay black. A reboot helps, but that's no solution. Let's talk about this some more, shall we.

Linux display configuration

If you want to run a Linux distro as a guest system in VirtualBox, you have several configuration options. First, you can use 3D acceleration, or not. The former is available only if you install the Guest Additions. However, there are (security) scenarios where you might not want to do that, plus some distributions don't always cooperate nicely with the full stack of drivers that comes with the Additions. If you choose to run the virtual machine without 3D acceleration, the desktop will be rendered without any calls to the graphics card - it will all be done with software emulation.

That said, most distributions cope with the software-based graphics just fine. In some cases, this may even help with the desktop performance, believe it or not (other times, it may be detrimental). The choice to run with or without 3D acceleration will also affect the available range of display resolutions presented inside the guest operating system. But for the most part, things ought to be fine.

As a final note on the 3D setup, if you choose to run without, you may also want to disable Compositing in your specific desktop environment, to reduce the software rendering overhead. For instance, in Plasma, the Compositor normally uses OpenGL in the backend, and OpenGL is only really available when you activate 3D acceleration in VirtualBox. Thus, if you disable it, you may get a more response virtual machine.

And now the problem

Assuming you're running without 3D, you may encounter the following issue: You let the machine be. After a period of inactivity, the screen will go black - some distros may even use a screensaver, but this is quite rare nowadays. The problem manifests when you try to continue your session. Typically, something like moving the mouse cursor or hitting a keyboard key will make the screen wake up, and present you with the lock screen or the open desktop, depending on the configuration. This is what happens for physical systems, and the same ought to happen for guest operating systems inside VirtualBox. The issue is, it does not.

The virtual machine screen stays black, unresponsive. The only remedy is to restart the machine, which means you may lose a working session. I encountered this problem with several distributions, in all cases without 3D acceleration (for the 3D & black screen scenario, take a look at my tutorial above). The system logs show nothing at all. Well, let's fix this then.

Solution (or rather workaround)

I realized the issue only manifests with the default graphics controller - VMSVGA. To avoid the black screen problem, you need to change to a different controller. Open the settings window for the particular virtual machine, then go to Display > Screen. Here, set the Graphics Controller dropdown to show VBoxVGA. For me, this was the only viable option that allowed all the different distributions to boot seamlessly, allowed me to use the desktop with "normal" resolutions (other than default 800x600px), and offered a stable working session.

Controller options

You will notice the Settings window probably saying: Invalid settings detected. The reason is, it will "complain", and nudge you to switch back to the default option. But it will not prevent the use of the machine. The caveat is that you cannot use 3D acceleration with this controller.

Warning

Now boot your distro. Its resolution will go back to the default values. Change it - notice that the available range of resolutions and aspect ratios will be different than for VMSVGA. Select the one that works for you, and let the system idle. You will be able to resume your work, i.e., the virtual screen will wake up correctly. I still do not know what the actual underlying root cause for the problem is, but here be a little workaround.

Conclusion

There you go. Ideally, you would never have to face issues like this, but remember, this is magic. You can install operating systems inside operating systems, and go as deep as you like, or rather within the limitations of your memory and disk, but hey. I am also quite certain that some people may come across this guide, but their issue will be ever so slightly different. In essence, it boils down to the choice of 3D acceleration and the relevant controller.

See whether changing the defaults helps. Play with the settings until you find the optimal setup, including the available resolutions and the desktop speed. Last but not the least, all of this may completely change with the new major version of VirtualBox, and please make sure you use the Extensions Pack that matches your program version exactly. That's another source of potential conflicts, misconfigurations and weird glitches. And we're done here. I hope my writing was of help today. See you around, fellow nerds.

Cheers.