The Linux Page

Mouse gets stuck when working between VirtualBox VM and Host

Once in a while, I click on something and the mouse literally dies.

From what I've seen the last time it happened, Opera had a lock issue. It could not create a lock and went on and on about it. Killing Opera did not help, even though the issue happened when I clicked on a button in Opera.

That last click happened in Opera and that's when the mouse froze. This is why I thought killing Opera would help... The good thing, though, is that the keyboard is running.

On that day, I decided to reboot the whole computer anyway because it had been running for over 42 days and so I needed to refresh all sorts of things (VirtualBox, Kernel, etc.) So I started closing each window using the keyboard to go into a console and kill things or move to a window and hit Ctrl-Q.

At some point, I decided to shut down the VirtualBox VM where I was just before I clicked said Opera button... and once it was down, the mouse woke up and worked just fine!

There is the Right-Control key which can be used to catch/release the mouse in a VM. The fact is that I tried that first, many times, until I was sure that it was not that specific issue (which I have had a while back).

Note that there are many other answers about a mouse freeze. If you do not have VirtualBox VMs running, then it probably is a driver issue. In that case, you are likely to have to restart X-Windows. There are many solutions so you'd have to test each one available and see what works for you.

Freeze Reason → Solutions

  • VirtualBox VM + Click → Shutdown the VirtualBox VM and see whether that resolves the issue
  • X11 Only (no VM) →
    • Ctrl-Alt-F1 gets you out to your console, then do Ctrl-Alt-F71
    • If you have a "psmouse" module, remove and reload:
          modprobe -r psmouse
          modprobe psmouse
    • Restart GDM — that worked well on older systems, for some reasons, on my newer system (Ubuntu 18.04) it has never worked correctly:
          systemctl restart gdm
      (And maybe it did not work because we now have a gdm3 as well, so maybe doing systemctl restart gdm3 would work better?)
    • In the old days, we were running compiz, but I don't think you would still be running off of that environment anymore:
          pkill compiz
    • Regular shutdown Ctrl-Alt-Del
    • Kill the GUI session: Alt + SysRq + K2 (which apparently means Push and Hold the Alt key down, then Press & Release the SysRq key, then Press & Hold the K key, you can then release the Alt key).
    • Keyboard SysRq commands to save your state to disk and then reboot:
          Alt + SysRq + E — killall but give each process a chance to save their state.
          Alt + SysRq + U — write all buffered data to disk (flush memory caches)
          Alt + SysRq + B — reboot
      Please, wait long enough between each keystroke so that way most if not all the processes have time to finish up before you reboot.
    • Turn off the swap — watch out with that one... if your memory is really stressed, the whole system will freeze... not just your mouse:
          sudo swapoff -a
      The -a means all swap spaces will be removed. In most cases, if you have swap on a very slow drive, you certainly will get slowness issues. One way is to get a larger drive (i.e. 10Tb) and use a separate partition used just and only for the swap (i.e. don't use a file). Also avoid using an SSD drive because those are not so good for swap space... you'll kill your drive much sooner even though it will go faster.
  • 1. Note that the latest version of Ubuntu does not always work with Ctlr-Alt-F7, it may be F8 or just Ctrl-F8 or Alt-F7... just play with those until you see a flash on your screen)
  • 2. Note that you may need to allow the SysRq capability. This is done by setting a flag with the following two commands:
        sudo su -
        echo 1 > /proc/sys/kernel/sysrq