Make the keyboard work on a headless server (read also about t-shirts!)

Make the keyboard work on a headless server (read also about t-shirts!)

Last week I bought a computer from the fine folks at OEM Express.
It is a AMD Duron 900MHZ with 128MB RAM, a 32X CDROM, and a Maxtor 40GB 7200RPM UDMA133 drive. No keyboard.
No mouse. No monitor. This box is destined to be a server. Actually, it is destined to become a live
backup of this webserver. Over the weekend, 4.4 was installed from CD, cvsup was run to get the latest
sources, and then I built and installed world. It’s now on 4.4-STABLE.

The box appears to be quite fast. Here are the build times:

StepElapsed

build world

01:09

install world

00:11

build kernel

00:11

install kernel

00:01

That seems pretty damn fast to me!

The keyboard issue

I have more computers than I do keyboards and monitors. So the box I built doesn’t have a keyboard
attached most of the time. But I found that if I did attach a keyboard to the box, I couldn’t use it.
That is, I couldn’t use the keyboard if it was attached after the box was booted. Please note that I’m
using a PS/2 keyboard not a USB keyboard.

The solution is fairly easy. Look in your kernel configuration file for this entry:

device          atkbd0  at atkbdc? irq 1 flags 0x1

Change the above to this:

device          atkbd0  at atkbdc? irq 1

The reason you want to remove the flag is found in man atkbd:


bit 0 (FAIL_IF_NO_KBD)

By default the atkbd driver will install even if a keyboard is not
actually connected to the system. This option prevents the driver
from being installed in this situation.

I was confused by the above description. I was thinking in terms of the kernel, not the driver.
In the man page, “by default” refers to the driver, not the kernel. By default, the driver will
always install, even if the keyboard is not present. The GENERIC kernel, on the other hand, uses
flags 0x1, which unloads the driver if a keyboard is not found

After making the above changes and
building a custom kernel,
I rebooted without the keyboard attached. After the system started up, I reattached the keyboard and tried it.
It worked!

Well, that’s kind of stupid. Why not make that the default?

That was my thought initially. This is silly. Why not have GENERIC always load the keyboard driver?
I found the answer was unexpected. It is this way because of syscons
limitations. It cannot handle more than one keyboard at a time. Therefore, if atkbd doesn’t find a keyboard,
it goes away to allow the USB keyboard driver a chance to get the keyboard.

A similar problem exists with USB keyboards, but I don’t know how to fix that one.

My thanks to Doug White for explaining this to me.

T-Shirts

I’ve been toying with the idea of t-shirts for The FreeBSD Diary and for
FreshPorts. I think they’d go for
about US$19.95 plus shipping. That is slightly more than you’d pay for most
t-shirts, but you’ll be supporting the Diary/FreshPorts. I don’t mind writing
the articles, but I’d prefer the website to pay for itself.

If you’d like to know more about the t-shirts,
please read this message in the forum.

13 thoughts on “Make the keyboard work on a headless server (read also about t-shirts!)”

  1. Christopher Smith

    Dan, just so that you’re aware, hot plugging PS/2 keyboards is not a good idea unless you really have to. It’s possible to fry the keyboard controller chip on your motherboard, thus rendering all your PS/2 ports dead.

    I highly recommend spending a few dollars on a USB keyboard if you plan to hot plug often. Frying PS/2 controllers isn’t particularly common, but it can (and does) happen.

  2. I have a bunch of headless servers. What I did was hook one of them up with a monitor keyboard and then configure all the others to use the serial port as the console. Then just run a bunch of null modem serial cables from each machine to the one with the monitor/keyboard. When I want to get on the console of one I just swap cables around…

    works pretty well for me.

    1. I’ve heard about serial consoles many times. I’ve never tried them though. One day….

      I bet you could get a switch to toggle between the serial ports so you didn’t have to swap cables?

    2. Yeah, you can, but they can get expensive… and I find that I do it so rarely it’s not that big of a deal to just swap them. It *is* nice when I do need them though 🙂

    3. Doh, a flag in the kernel config! That’s interesting. I wish I’d known that before I spent HKD$1400 (about US$200) on a funky KVM switch and cables!

      Actually I needed the switch for my other machines anyway 🙂 and thought I might as well plug the FreeBSD box into it to kill another bird while I was throwing stones but it’s nice to find out WHY it wasn’t working.

      Nice article!

      Aside: my switch really is funky. You can switch screens from the keyboard. Control+Alt+Shift then X then Enter where X is the number of the display you want. Very nice…

    4. I don’t have the URL anymore, but somewhere out there a guy built his own keyboard switcher that was really funky. He made is own switcher box that in addition to keyboard/video also took serial inputs from all the machines. He then wrote an application for each machine (windows, mac, and unix) that put a little box in each bottom corner of the screen. Move the mouse into that corner and it would send a signal on the serial port to the switcher and switch you to the machine "on that side".

      Pretty crazy 🙂

    5. Thank God, I found this article…..

      Man I thought I was gonna have to spend $1400.00 myself.
      FreeBSD Diary is were it is at.

      Thanks for the money saved.

      You4eea

  3. After a bit of experimentation I’ve found that you can (ab)use usbd to reset the console keyboard for you.

    Insert a block like this into /etc/usbd.conf then kill -HUP usbd:

    Device "Keyboard"
    devname "ukbd[0-9]+"
    attach "/usr/sbin/kbdcontrol -k /dev/kbd1 < /dev/console"

    This causes usbd to reset the console keyboard to kbd1, which is usually always the USB keyboard you’ve just plugged in. If you plug in multiple USB keyboards then you’ll have to switch them manually, but I don’t exactly find that a common configuration. 🙂 Some creative scripting could improve the intelligence if you regularly use lots of USB keyboards.

    When you unplug the keyboard, syscons automatically reverts to kbd0, which will be the atkbd if you’ve cleared the flags on it.

    More information can be found on the usbd.conf(5) man page.

    1. I haven’t gotten this to work.

      I get usbd to dump core each time. Running usbd in debug mode gives me this.

      [/usr/home/paul]# usbd -vvvvvvvvvvvv
      usbd: opened /dev/usb0
      usbd: reading configuration file /etc/usbd.conf
      usbd: action 1: ActiveWire board, firmware download
      vndr=0x0854 prdct=0x0100 rlse=0x0000
      attach=’/usr/local/bin/ezdownload -f /usr/local/share/usb/firmware/0854.0100.0_01.hex ${DEVNAME}’
      usbd: action 2: Entrega Serial with UART
      vndr=0x1645 prdct=0x8001 rlse=0x0101
      attach=’/usr/sbin/ezdownload -v -f /usr/share/usb/firmware/1645.8001.0101 /dev/${DEVNAME}’
      usbd: action 3: USB ethernet
      devname: [ack]ue[0-9]+
      attach=’/etc/pccard_ether ${DEVNAME} start’
      detach=’/etc/pccard_ether ${DEVNAME} stop’
      usbd: action 4: Handspring Visor
      vndr=0x082d prdct=0x0100 rlse=0x0100
      devname: ugen[0-9]+
      attach=’/usr/local/bin/coldsync -md -p /dev/${DEVNAME} -t usb’
      usbd: action 5: Mouse
      devname: ums[0-9]+
      attach=’/usr/sbin/moused -p /dev/${DEVNAME} -I /var/run/moused.${DEVNAME}.pid ; /usr/sbin/vidcontrol -m on’
      usbd: action 6: USB device
      usbd: 6 actions
      usbd: opened /dev/usb

      here’s what I added:

      device "Keyboard"
      devname "ukbd[0-9]+"
      attach "/usr/sbin/kbdcontrol -k /dev/kbd0 < /dev/console"

      and here’s what I get:

      [/usr/home/paul]# usbd -vvvvvvvvvvvv
      usbd: opened /dev/usb0
      usbd: reading configuration file /etc/usbd.conf
      Segmentation fault (core dumped)

      I tried kdb1 as well: some deal.

      Any ideas?

  4. Hi,

    I’ve read that FreeBSD does not allow you to plug in a PS/2 keyboard after bootup to protect the motherboard. PS/2 is not designed for hot-swapping devices, so in a freak accident you could blow a part of your motherboard by connecting a keyboard when the machine is up. I think there’s a reference on the FreeBSD questions mailing list archive.

    1. Mario wrote:

      > I’ve read that FreeBSD does not allow you to plug in a PS/2
      > keyboard after bootup to protect the motherboard.

      I’ve read, and been told, differently. That that is not the reason, but rather a side effect. I detail that in the section titled "Well, that’s kind of stupid. Why not make that the default?". It’s a side effect of another choice AFAIK.

      > PS/2 is not
      > designed for hot-swapping devices, so in a freak accident you
      > could blow a part of your motherboard by connecting a
      > keyboard when the machine is up.

      I’ve heard that.

      > I think there’s a reference
      > on the FreeBSD questions mailing list archive.

      No doubt. I’d love to see it.

      Thanks.

Leave a Comment

Scroll to Top