17

My keyboard stops working for no apparent reason.

After using Ubuntu for 2.5 years as a virtual machine on a Windows host (VirtualBox) I finally took the plunge, reformatted my hard disk and built the system with Ubuntu yesterday. This morning I my keyboard stopped working.

I see many posts about Ubuntu and a USB keyboard or mouse ceasing to work randomly. They indicate that it is autosuspend turning off power to USB devices to save power, and when the USB device is not compatible in some, the USB does not 'wake-up' as it should.

I tried the suggestion posted in Fixing USB Autosuspend.

But no luck. I also tried another suggestion which was to boot without the keyboard and then plug it in once Ubuntu had started.

Here are some details:

  • I used the same Kinesis keyboard with Ubuntu as a virtual machine for the past two years, no problem.
  • The Kinesis has macros and triggering a macro triggers the problem 100% of the time. However, it happens when I am just typing (no macros) as well.
  • I tried the Kinesis on a laptop just now. This is a one-year-old machine that I put Ubuntu 16.04 on two weeks ago. Using a Kinesis keyboard macro did not reproduce the problem.

Problem Machine

  • Dell XPS, 6 years old, desktop
  • Installed Ubuntu 16.04 yesterday
  • Using Kinesis Advantage USB keyboard
  • Unplugging/re-plugging the keyboard has worked 9 out of 10 times
  • Rebooting works as well
  • I don't think it is a USB power problem as an LED on the keyboard stays lit and other USB devices keep working.
  • I have both a USB and a Bluetooth mouse attached to the machine. Both keep working even when the Kinesis stops.
  • I normally have a second regular Dell branded keyboard plugged in for non-Kinesis folks who need to use my computer. Earlier today this keyboard stopped working each time the Kinesis stopped working. However now, triggering the problem with a macro, the Dell keyboard keeps working.

The Kinesis, which I have had for 8 year now, has made it possible for me to keep keyboarding. If I can't resolve this I'll have to go back to Windows which would be a real bummer.

Any suggestions on things to try or ways to go about debugging this would be greatly appreciated.

I am digging into USB drivers, which on Linux I know nothing about. However, I have found that the laptop has both USB 2.0 and 3.0 ports. The desktop (with the problem) is USB 2.0 only. Still digging...

  • I used the same Kinesis keyboard with Ubuntu as a virtual machine for the past 2 years, no problem. Did you actually hand over the keyboard to the virtual machine? Otherwise it was going through the drivers of host OS and VirtualBox. – Melebius Aug 17 '16 at 12:31
  • For 3 years I used Ubuntu as a VM with a Windows host and had no problem with the keyboard. Now that the host is Ubuntu GNOME and the guest is Ubuntu GNOME as well, I'm having this problem. – klequis Aug 24 '16 at 22:50
  • Then you were not using your physical keyboard in the guest OS. Virtualbox presents a virtual keyboard to the guest OS by default. (so it does not matter if you used the same physical keyboard, as it was not the same) – karatedog Dec 11 '16 at 23:25
  • See this similar question: askubuntu.com/questions/688445/laptop-keyboard-stopped-working Installing package xserver-xorg-input-all worked for me when I upgraded to Ubuntu 17.04 – Lilás Jul 23 '17 at 2:20
7

I had the same problem with Ubuntu 16.04 (Xenial Xerus) and searched so much for any solution...

The solution is at the end of this answer if you don't care about the context story. Context could look like unuseful blabla (maybe it is), but I think that it could help readers to check if the problem I've solved on my PC is the same as their one.

CONTEXT

I desperately have unsuccessfully tested near every tips I've found on the web, rebooting after each try:

  • '/etc/default/grub' kernel boot usbcore.autosuspend=-1 parameter
  • laptop-mode's 'runtime-pm.conf' CONTROL_RUNTIME_AUTOSUSPEND=0
  • fully disabling Laptop Mode Tools from '/etc/laptop-mode/laptop-mode.conf' file, confirming that the problem isn't related to this kernel feature. I've checked different ways that laptop_mode wasn't running anymore to be sure. (Ref: man laptop-mode.conf & man laptop_mode)
  • I've read some tricks about '/etc/laptop-mode/conf.d/usb-autosuspend.conf', but this file doesn't exist in my version of Ubuntu 16.04 with laptop-mode-tools v1.68
  • powertop application uninstallation. It's often suspected in forums to cause autosuspend issues, and today I know that it was not true in my case as uninstalling it didn't fix anything.
  • options usbcore autosuspend=1 in '/etc/modprobe.d/usb.conf' has been inefficient too
  • '/etc/udev/rules.d/60-power.rules' script provided by Gentoo official Wiki
  • device-specific rules file for udev '/etc/udev/rules.d/usb-power.rules' recommended by Serge Y. Stroobandt

After having read all this technical stuff I only understood that the cause was related to my '/sys/module/usbcore/parameters/autosuspend' value stuck at two seconds, no matter what change I do to my configuration. You can check it with cat command:

$ cat /sys/module/usbcore/parameters/autosuspend
2

And yes, my mouse was disabled exactly after two seconds, so I knew I was on the right way. Of course I had tested the echo -1 command that I've seen here and there, -1 intended to disable autosuspend... but:

sudo echo -1 > sys/module/usbcore/parameters/autosuspend
bash: /sys/module/usbcore/parameters/autosuspend: Permission denied

I didn't understand why permission was denied even in sudo mode. I didn't try as root, because I just didn't think that it could be a problem. Here was the mistake :(

Thanks to Alex Dekker & Bryce comments, I've learnt how to disable autosuspend only for my mouse. But of course my first tries have failed with this bash: Permission denied error, so I had to wait for understanding of my root/sudo confusion before the echo -1 command suggested by Alex finally work.

I've also found a better way to execute a command as the root user without login as root. The difference between root shell and root commands usage is well explained in the official Ubuntu's RootSudo wiki page. I love to learn to these kind of things, but hey! Why does it have to be always learnt the painful way? LOL

OMG, it was a real headache, and it took lot of time for a noob like me to understand, as I usually say "no brain no gain". Mine visibly needs more training.

So let's stop talking about myself and go fix it! Please continue below...


I highly recommend the second solution for your idle external HDD to don't drain your laptop battery for nothing. But I give you both solutions, because who loves his/her own freedom should love each others freedom too :)

SOLUTION 1

To disable autosuspend on every USB devices/ports

  1. Open Terminal and execute:

    sudo sh -c "echo -1 > /sys/module/usbcore/parameters/autosuspend"
    
  2. This is indeed a temporary solution that allows you to instantly test if this command fixes your mouse or keyboard autosuspend issue.

  3. If your USB device(s) work fine now, just edit your '/etc/rc.local' script so it will run that command whenever the system is booted. This way you'll make the fix kind of permanent. Edit the file, for example with nano:

    sudo nano /etc/rc.local
    
  4. and put the echo -1 command in your '/etc/rc.local' file before the exit 0 line

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    (...)
    # By default this script does nothing.
    echo -1 > /sys/module/usbcore/parameters/autosuspend
    exit 0
    
  5. Restart your computer

(Please check the Important note at the end.)

.

SOLUTION 2

To disable autosuspend for a specific USB device/port

  1. The power options for a USB device are in /sys/bus/usb/devices/n-n/power. What n-n is for a given device requires a few manipulation to find out, but it's not complicated. The example below shows how I've determined that the USB port number of my wireless mouse receiver is 3-1, so please adapt this to your own situation:

    • Unplug your USB device, open Terminal and execute the sudo dmesg command

    • Connect your USB device back, and then execute sudo dmesg again in Terminal to check for changes

    • Here's what the end of my dmesg command output looks like after having plugged my mouse back in a slot:

      [40208.575249] usb 3-1: new full-speed USB device number 8 using xhci_hcd
      [40208.705233] usb 3-1: New USB device found, idVendor=062a, idProduct=4102
      [40208.705240] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
      [40208.705245] usb 3-1: Product: 2.4G Wireless Mouse
      [40208.705248] usb 3-1: Manufacturer: MOSART Semi.
      [40208.707679] input: MOSART Semi. 2.4G Wireless Mouse as /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/0003:062A:4102.0007/input/input24
      [40208.763946] hid-generic 0003:062A:4102.0007: input,hiddev0,hidraw0: USB HID v1.10 Mouse [MOSART Semi. 2.4G Wireless Mouse] on usb-0000:00:14.0-1/input0
      

    Now we can see that the port where my USB device has been plugged-in is identified as usb 3-1.

    **Note:** this trick concerns the USB port ID, not a device ID. For example, if I plug my mouse to the next USB port, it becomes identified as `usb 3-2` in the `dmesg` result. But this solution #2 remains very useful if you take the habit to always plug your mice or keyboard to the same port, and it's generally what people use to do unconsciously ;)
    
  2. Execute the following command in your Terminal, changing my port number 3-1 with the one you've found in your own dmesg result:

    sudo sh -c "echo -1 > /sys/bus/usb/devices/3-1/power/autosuspend_delay_ms"
    

    Note that autosuspend_delay_ms has replaced the deprecated autosuspend since kernel version 2.6.38, according to the Linux official documentation.

  3. This is indeed a temporary solution, but you can now easily test if this command fixed your mouse or keyboard autosuspend issue.

  4. If your USB device work fine now, just edit your '/etc/rc.local' script so it will run that command whenever the system is booted. This way you'll make the fix kind of permanent. Edit the file, for example with nano:

    sudo nano /etc/rc.local
    
  5. and put the echo -1 command in your '/etc/rc.local' file before the exit 0 line, once again don't forget to change port number n-n in the command:

        #!/bin/sh -e
        #
        # rc.local
        #
        # This script is executed at the end of each multiuser runlevel.
        (...)
        # By default this script does nothing.
        echo -1 > /sys/bus/usb/devices/3-1/power/autosuspend_delay_ms
        exit 0
    
  6. Restart your computer

.

Important: don't forget that you'll have to execute the sudo sh -c "temporary" command again manually if you disconnect/reconnect your USB device while your desktop environment is already started, even if you plug it back on the same USB plug. Normal, just because the '/etc/rc.local' file is called only once at system startup.

Anyway, workarounds are possible. Better skilled peoples may have more clever methods, but I've configured port-specific aliases in Ubuntu. It allows me to use the simple usb1 or usb2 commands selectively if I have to unplug/replug my USB device here or there. You too! You could also create commands aliases to play with short words instead of typing the full command. It's easy to set in less than two minutes and also works with Alt + F2 :)

More ideas to make it easier would be also very welcome.

  • thank you for this answer. Unfortunately, I cannot test to confirm this is the answer. Therefore, not sure if I should mark as answer. – klequis Jul 26 '17 at 17:51
  • I tried and it not help on Ubuntu 16.0.4.2 VirtualBox 5.1.26 – Pavlo Aug 11 '17 at 8:11
1

I had the exact same issue (Kinesis keyboard, stopped working after a reboot).

I eventually figured out it was related to a kernel upgrade

  • before the reboot I was on version 4.4.0-31-generic
  • after the reboot it was 4.4.0-38-generic

Booting using the older 4.4.0-31 kernel fixed the issue for me.

This post includes instructions on how to boot using an older kernel (allowing you to see if the older kernel does the trick for you).

  • it very likely that my freshly built machine had a newer kernel than the virtual machine I was using. However, my problem was not that keyboard stopped working after reboot, it worked fine until I ran a macro, at which point it turned-off. Most of my use of macros was for common programming keys. I now use Atom editor and its shortcuts/auto-type (whatever they call it) does most of what I need so I'm in happy land with that. – klequis Sep 25 '16 at 13:36
0

If you have laptop-mode-tools it may be possible to fully disable usb auto-suspend by changing:

AUTOSUSPEND_TIMEOUT=2

in

/etc/laptop-mode/conf.d/runtime-pm.conf

to

AUTOSUSPEND_TIMEOUT=-1

Take note that there is a commented option in this file

untime-pm.conf:# Example: AUTOSUSPEND_DEVID_BLACKLIST="usbhid usb-storage"

You might try toying around with this option if you want to fine tune your power management settings.

NOTES:

  • usbcore is compiled in to the kernel.
  • using systemd
  • Ubuntu 16.10
  • Linux kernel 4.8.0-41-generic #44-Ubuntu
  • I have also noted that in: – Antonio Medina Mar 14 '17 at 5:32
  • Not a laptop and I have learned to live without, but thank you for you suggestion. – klequis Mar 21 '17 at 18:49
  • Whether or not laptop-mode-tools is running has little to do with whether or not the system is a laptop. My always plugged into the wall A/C server was running it, and setting the AUTOSUSPEND_TIMEOUT=-1 in the /etc/laptop-mode/conf.d/runtime-pm.conf file was what finally fixed it for me, after struggling with this ever since I updated to 16.04 from 14.04. – Rezty Felty Nov 6 '19 at 18:55
0

I had this same problem. For me, the solution was simple, while the actual reason was left unknown.

Yesterday I plugged a second mouse to my pc. Everything worked fine. Today, when I booted, keyboard did not function in the login screen or in the desktop. It worked during boot, for example I got into bios.

Keyboard started working after I unplugged the new mouse and replugged all usb wires.

  • It could be the total number of USB devices (a maximum of two). I have such a system. It may or may not be related to the type of USB port, USB 2 vs. USB 3. Unfortunately, I don't have that many options in the BIOS to try to work around it. – Peter Mortensen Dec 2 '19 at 22:16
0

I have read this and other reports over and over again for the past year, and in the end just gave up using the keyboard that was causing problems and switched to a wireless keyboard.

Until it struck me that the problem started around the time I built a new PC, and it might be a power issue. So I bought a powered USB hub to connect the keyboard to. It solved the problem! It was not a software issue after all, but apparently my new computer has under-powered USB outputs (or so my keyboard thinks).

This might be worth a try if you are suffering from intermittent keyboard outages as described above and nothing on the software side has worked. A powered USB hub does not need to be expensive.

0

This isn't the answer I was looking for but ... I spent two days and many hours trying to solve this problem. I purchased a PCIe USB 3.0 hub to see if that would work - it didn't.

My conclusion is that this problem isn't worth solving, and there are better ways to the same end.

My solution/workaround is to rely on my text editor's snippets function. It means I'll invest and rely more on a specific editor (will most likely be Atom), but this will be even better than what I had with the keyboard macros as snippets are easier to maintain than keyboard macros.

I learned a lot about USB from Resetting the USB Subsystem.

  • I purchased a Kinesis Advantage2 about 3 months ago. Just wore the 10 y/o one out. It works fine. Not having the problem discussed in this issue. – klequis Jun 5 '19 at 21:32
  • Snippets (text templates) are extremely useful, but they can't do control key combinations, only pure text(?). E.g. Shift + Ctrl + Tab (for moving to the next tab to the left in Firefox) can not be put into a snippet – Peter Mortensen Dec 2 '19 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.