How To: Fix USB Keyboards Missing the First Keypress in Linux

I use my laptop as a desktop with an external monitor, mouse & keyboard, and found that recently the keyboard would keep missing the first character of input – and it was driving me nuts. After much googling I found a blog post over at wulftone.com that narrowed the issue down to a USB sleep problem, and described how to blacklist a USB keyboard from going into sleep mode – and it works great!

The way to fix this issue is:

1 – Find the details of your USB keyboard via the lsusb command, like this:

$ lsusb
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 1bcf:2885 Sunplus Innovation Technology Inc. ASUS Webcam
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 003 Device 002: ID 045e:00dd Microsoft Corp. Comfort Curve Keyboard 2000 V1.0  <--- Ch-ching!
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

2 – Once you can see your keyboard, if you can’t remember which way the vendor ID and product ID go (it’s that very order), you can get the details (in this case looking at the Microsoft keyboard on bus 003, device 002) like this:

$ lsusb -v -s 003:002
 
Bus 003 Device 002: ID 045e:00dd Microsoft Corp. Comfort Curve Keyboard 2000 V1.0
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x045e Microsoft Corp.                   <--- Vendor ID.  Do not take the 0x prefix.
  idProduct          0x00dd Comfort Curve Keyboard 2000 V1.0  <--- Product ID. Do not take the 0x prefix.
  bcdDevice            1.73
  ... More details than most people are interested in ...

3 – Next, edit (or create if necessary) the file: /etc/udev/rules.d/91-local.rules and place the following contents into it:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="YOUR-KEYBOARD-VENDOR-ID", ATTR{idProduct}=="YOUR-KEYBOARD-PRODUCT_ID", TEST=="power/control", ATTR{power/control}="on"

So for my USB keyboard I entered:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="045E", ATTR{idProduct}=="00DD", TEST=="power/control", ATTR{power/control}="on"

4 – Finally, with that done you can reload the udev rules with the following and you should be all set:

sudo udevadm control --reload-rules

As a final note, I found that this (bizarrely) didn’t work when I used the lowercase hex codes (i.e. 045e & 00dd) – I had to put them to uppercase (045E & 00DD) for it to kick in!

Sanity restored! =D

P.S. If you want to disable your first (i.e. laptop) keyboard and/or are using laptop-mode-tools then the wulftone article has you covered. So many thanks to Trevor Bortin for this fix!

How To: Create a Bootable Linux Live CD without using Unetbootin

Burned an ISO to USB with unetbootin and it’s not bootin’? Me too. Researching a little shows that a number of people are having this issue trying to make a bootable USB of Ubuntu 13.04 onwards (I was trying 13.10). So, how can we create a bootable USB in Linux without using unetbootin? Pretty easily as it turns out…

Identify your USB drive

Insert a USB stick into your machine (don’t mount it or click on any pop-up – just have the system recognise that the stick is there) and type:

df -h

From this output you should be able to find your USB drive, make a note of or remember the drive letter. In my case, I get the following output:

Filesystem                      Size  Used Avail Use% Mounted on
/dev/sda8                        18G  6.1G   11G  37% /
dev                             7.9G     0  7.9G   0% /dev
run                             7.9G  948K  7.9G   1% /run
tmpfs                           7.9G  3.0M  7.9G   1% /dev/shm
tmpfs                           7.9G     0  7.9G   0% /sys/fs/cgroup
tmpfs                           7.9G  140K  7.9G   1% /tmp
tmpfs                           7.9G  856K  7.9G   1% /etc/pacman.d/gnupg
/dev/sda6                       475G  399G   52G  89% /home
/dev/sdb1                       1.9G     0  1.9G   0% /run/media/r3dux/R3DUSB

From which you can see that /dev/sdb is the USB stick (we don’t care about the partition number of the drive i.e. sdb1 – we’re just interested in the drive letter).

Be aware that you’ll lose any data on the USB stick once you perform the copy – so if your sticks empty or you don’t care about losing whatever’s on it, we can move onto the next part, which is the…

Binary Copy

Now that you have your drive letter (and you’re ABSOLUTELY sure it’s the correct drive letter – you do NOT want to overwrite any other partitions!), carefully type the following and make the following substitutions:

/path/to/your/image.iso is obviously the path to the iso you want to make a bootable USB stick with, and
– The X in sdX is the drive letter we just identified for your USB stick.

sudo dd bs=4M if=/path/to/your/image.iso of=/dev/sdX && sync

So in my case, I typed:

sudo  dd bs=4M if=~/Downloads/ubuntu-13.10-desktop-i386.iso of=/dev/sdb && sync

Let it go for a minute or two, then you’re done. Boot away!

The only caveat with this method of making a bootable USB stick is that you can’t use the rest of the space on the USB stick to store files like you often can when using a Live USB Stick creation tool. But if you just wanted the darn thing to work, as I did, dd will do the job nicely.