UKBD(4)

πŸ’– UKBD β€” the USB keyboard driver, bestie πŸ’–

okay so this is ukbd(4) from the Kernel Interfaces Manual, and it's literally the driver that makes your keyboard work when you plug it into a USB port. iconic behavior honestly. let's get into it πŸŽ€


✨ NAME ✨

ukbd β€” the USB keyboard driver. that's it, that's the vibe. πŸ‘‘


🌸 SYNOPSIS 🌸

so you wanna get this driver into your kernel? two ways, pick your fighter:

option one β€” bake it into the kernel. drop this line in your kernel configuration file:

device ukbd

option two β€” load it as a module at boot time. put this line in loader.conf(5):

ukbd_load="YES"

slay, either way works πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

the ukbd driver provides support for keyboards that attach to the USB port. no cap, that's its whole job.

⚠️ but listen β€” usb(4) AND one of uhci(4) or ohci(4) must be configured in the kernel as well. you can't just have ukbd sitting there all alone, it needs its friends fr fr.

🌈 CONFIGURATION 🌈

okay so here's the tea: by default, the keyboard subsystem does not create the appropriate devices yet. so make sure you reconfigure your kernel with the following option in the kernel config file:

options KBD_INSTALL_CDEV

now, if both an AT keyboard and USB keyboards are used at the same time β€” the AT keyboard will appear as kbd0 in /dev. and the USB keyboards will be kbd1, kbd2, etc. that's just the order of things bestie.

you can peek at some info about the keyboard with this command:

kbdcontrol -i < /dev/kbd1

or load a keymap with:

kbdcontrol -l keymaps/pt.iso < /dev/kbd1

see kbdcontrol(1) for more possible options ✨

you can swap console keyboards by using the command:

kbdcontrol -k /dev/kbd1

from this point on, the first USB keyboard will be the keyboard to be used by the console. main character promotion πŸŽ€


now β€” if you want to use a USB keyboard as your default and not use an AT keyboard at all, you will have to remove the device atkbd line from the kernel configuration file. because of the device initialization order, the USB keyboard will be detected after the console driver initializes itself, and you have to explicitly tell the console driver to use the existence of the USB keyboard. this can be done in one of the following two ways:

way 1: run the following command as a part of system initialization:

kbdcontrol -k /dev/kbd0 < /dev/ttyv0 > /dev/null

(note that as the USB keyboard is the only keyboard, it is accessed as /dev/kbd0 πŸ’‘)

way 2: otherwise tell the console driver to periodically look for a keyboard by setting a flag in the kernel configuration file:

device sc0 at isa? flags 0x100

with the above flag, the console driver will try to detect any keyboard in the system if it did not detect one while it was initialized at boot time. she's persistent, we love her 🫢


πŸ’… DRIVER CONFIGURATION πŸ’…

options KBD_INSTALL_CDEV

make the keyboards available through a character device in /dev. periodt.


options UKBD_DFLT_KEYMAP
makeoptions UKBD_DFLT_KEYMAP=fr.iso

the above lines will put the French ISO keymap in the ukbd driver. you can specify any keymap in /usr/share/syscons/keymaps or /usr/share/vt/keymaps (depending on the console driver being used) with this option. so many keymaps, so little time 😭


options KBD_DISABLE_KEYMAP_LOADING

do not allow the user to change the keymap. πŸ”’

note that these options also affect the AT keyboard driver, atkbd(4). yeah, they share. iykyk.

⭐ SYSCTL VARIABLES ⭐

the following variables are available as both sysctl(8) variables and loader(8) tunables:

  • hw.usb.ukbd.debug β€” Debug output level, where 0 is debugging disabled and larger values increase debug message verbosity. Default is 0.

πŸ“ FILES πŸ“

  • /dev/kbd* β€” blocking device nodes

πŸ”₯ EXAMPLES πŸ”₯

device ukbd

Add the ukbd driver to the kernel. boom. done. ✨


πŸ‘‘ SEE ALSO πŸ‘‘

kbdcontrol(1), ohci(4), syscons(4), uhci(4), usb(4), vt(4), config(8)


πŸ’œ AUTHORS πŸ’œ

the ukbd driver was written by Lennart Augustsson <augustss@cs.chalmers.se> for NetBSD and was substantially rewritten for FreeBSD by Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>. legends, both of them 🫑

this manual page was written by Nick Hibma <n_hibma@FreeBSD.org> with a large amount of input from Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>. collab of the century tbh πŸŽ€


and that's the whole page bestie!! this one's from the Debian crew, dated April 24, 2018, filed under UKBD(4) in the Kernel Interfaces Manual. go forth and type fabulously πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from