Return to Linux Home Page.

Erratic Mouse Behavior with Mouse on Linux and Belkin KVM Switch

by Jeff Hunter, Sr. Database Administrator


  1. Introduction
  2. Older Linux Kernels
  3. Newer Linux Kernels (2.6 and higher)


When using a Belkin KVM switch (and several others), you may notice erratic behavior with the PS/2 mouse when switching back and forth to a Linux machine running Red Hat Linux (and Mandrake 10). The PS/2 mouse will simply go nuts; jumping all around the screen with random button clicks when you try to move it anywhere! Often times, switching to a USB mouse will resolve the problem. Another solution is to reboot the system every time you switch to the Linux machine and get back into your X Windows session. This gets old real quick!

The root cause for this erratic behavior with the mouse rests in the fact that the PS/2 specification was not designed to be hot-pluggable. So, why is this a problem? Read on.

All PS/2 mice can work in what we will call "Basic PS/2 Mouse Mode" — no scroll wheel and only 2 or three buttons work. This is the default mode when the mouse initially gets power. To activate the scroll wheel and/or any extra buttons, the mouse must receive a special reset code. This switches the mouse to "Advanced Mouse Mode" and changes the mouse data protocol a little.

Several KVM switches (Belkin and Rose Electronics for example) stop feeding power to the mouse when switching from one system to another. This causes the mouse to reset to "Basic PS/2 Mouse Mode". The system has no way of detecting that the mouse was reverted back to the basic mode. If the system was in a state where it had detected the mouse with "Advanced" capabilities and had sent it the appropriate reset code, it will expect the mouse to still be in "Advanced" mode and will misinterpret the mouse data (remember the mouse data protocol is different between Advanced and Basic mouse mode).

One of the most practical solutions is to upgrade from using Belkin and Rose Electronics KVM switches to a far superior line of KVM switches like those offered by Avocent Corporation. The following KVM switches, for example, offer advanced capabilities for both home and the enterprise at an exceptionally economical price:

  SwitchView® 1000 8-port KVM Switch
  AutoView® 1415 KVM Switch

For a more detailed discussion on the above mentioned KVM switches, please review the article "KVM Switches For the Home and the Enterprise - (Avocent)".

This article provides several solutions that I have used to resolve the erratic mouse behavior inherent with the Belkin and Rose line of KVM Switches.

Older Linux Kernels

With Linux 2.4, there is a simple way to force the system to reset the mouse. Just switch to the text console mode by pressing CTRL-ALT F5, release all keys, and then return to the graphics mode by pressing CTRL-ALT F7. The return to the graphics mode will cause the mouse to be reset, and the mouse will work again.

Another way to force a mouse reset on Linux 2.4 is to restart the text-mode mouse service — the "gpm" daemon. In most cases, this can be done using the following command:

# sh /etc/init.d/gpm restart
That should get the mouse back working again!

Newer Linux Kernels (2.6 and higher)

With the newer 2.6 series kernels, there is a way to eliminate the problem altogether. The "psmouse" kernel module can be made to reset the mouse automatically if it detects invalid mouse protocol packets, or it can be forced to ignore the existence of "Advanced PS/2 Mouse Modes" and to use the "Basic PS/2 Mouse Mode" only. Keep in mind that if you elect to configure the system for "Basic PS/2 Mouse Mode", options like the scroll wheel and extra buttons will be disabled, however this will be the end of the erratic mouse behavior!

One of the first tasks is to determine if "psmouse" mouse driver is running as a kernel module or build right into the kernel. To determine if psmouse is running as a kernel module, you can use the "lsmod" command as follows:

# lsmod | grep psmouse
psmouse                43496  0
If the above command does not return anything, then psmouse is built right into the kernel. If the above command does return something similar to the above example, then psmouse is loaded as a kernel module. Why does this matter? Because this determines where the options for the psmouse driver will be configured. If psmouse is loaded as a kernel module, then all configuration parameters can be placed in /etc/modprobe.conf. If psmouse is built into the kernel, then options to the psmouse driver will need to be placed in your boot loader file (i.e. /etc/grub.conf).

One of the things I like to do is determine which functions are available for psmouse and the kernel. If psmouse is loaded as a kernel module, run the following command. Look for parameters named "resetafter" and "proto":

# modinfo psmouse
If psmouse is built into the kernel, the above command will fail to provide any details.

The following instructions will configure your Linux system to load the psmouse driver in "Basic PS/2 Mouse Mode". Although this disables any of the advanced features (scroll wheel and extra buttons), it is one of the most successful methods for getting the mouse to work between switches on the KVM. If the psmouse driver is loaded as a kernel module, try the following as the root user. Note that the modprobe command is generally found in the /sbin directory:

# modprobe -r psmouse  # Unloads the driver; your mouse will stop working at this point
# modprobe psmouse proto=bare    # Re-load the driver using the correct parameter
If the above commands work for you, then add the following line to your /etc/modprobe.conf file to make the change permanent:
options psmouse proto=bare

If psmouse is not a kernel module and built right into the kernel then you'll have to edit your boot loader file. With most distributions the boot loader is "grub" in which case the configuration file is either /etc/grub.conf or /boot/grub/menu.lst. Find the stanza that corresponds to your kernel. At the end of the "kernel" line, add a space, and then the following:

After modifying the boot loader configuration file the system will need to be rebooted. You shouldn't get any errors, but if you do, you can use grub's boot line editing capabilities to remove the psmouse.proto=bare option so that you can at least boot. Here is a copy of my new boot loader configuration file after adding the psmouse.proto=bare option:

Example /etc/grub.conf File
# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
#          initrd /initrd-version.img
title CentOS-4 i386 (2.6.9-42.EL)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-42.EL ro root=/dev/VolGroup00/LogVol00 rhgb quiet psmouse.proto=bare
        initrd /initrd-2.6.9-42.EL.img

Although the above steps work by configuring the system to use "Basic PS/2 Mouse Mode" in Linux, it is frustrating to loose the advanced functionality of the mouse (i.e. scroll wheel and extra buttons). There are several more options available to the psmouse drive that may provide the best of both worlds — no erratic mouse behavior and advanced mouse functionality. Please note that in my case, I could never get these to work on my system.

  Note that the options provided above are specified for use in the boot loader file (i.e. /etc/grub.conf). If the psmouse driver is a loadable kernel module, remember to remove the period "." after psmouse when including it in the /etc/modprobe.conf file. For example, psmouse.proto=exps would be included in the /etc/modprobe.conf file as:
options psmouse proto=exps

Last modified on: Saturday, 18-Sep-2010 18:21:12 EDT
Page Count: 39595