kbdcontrol(1), kbdmap(1), keymap(5), vt(4), /usr/share/syscons/keymaps/ and kernel panic on demand

Found: <https://gist.github.com/bijanebrahi...how-to-panic-on-demand-when-system-is-freezed>

Debugging FreeBSD Kernel · GitHub ▶ How to panic on-demand when system is freezed

The head of my /usr/share/syscons/keymaps/uk.iso.kbd:

Code:
# $FreeBSD$
#                                                         alt
# scan                       cntrl          alt    alt   cntrl lock
# code  base   shift  cntrl  shift  alt    shift  cntrl  shift state
# ------------------------------------------------------------------
  000   nop    nop    nop    nop    nop    nop    nop    nop     O
  001   esc    boot   esc    esc    esc    esc    debug  panic   O

The manual page for kbdmap(1) is emphatic – Use the ISO standard version if available! – however when I run kbdmap -d there's no ISO variant for the UK, the closest I can find in the list is simply United Kingdom, which results in:

keymap="uk.kbd"

– a map file for which does not exist:

Code:
% file /usr/share/syscons/keymaps/uk.kbd
/usr/share/syscons/keymaps/uk.kbd: cannot open `/usr/share/syscons/keymaps/uk.kbd' (No such file or directory)
% ls -l /usr/share/syscons/keymaps/uk* | sort
-r--r--r--  1 root  wheel  7581  8 Jul 09:12 /usr/share/syscons/keymaps/uk.cp850-ctrl.kbd
-r--r--r--  1 root  wheel  7581  8 Jul 09:12 /usr/share/syscons/keymaps/uk.cp850.kbd
-r--r--r--  1 root  wheel  7581  8 Jul 09:12 /usr/share/syscons/keymaps/uk.iso-ctrl.kbd
-r--r--r--  1 root  wheel  7581  8 Jul 09:12 /usr/share/syscons/keymaps/uk.iso.kbd
-r--r--r--  1 root  wheel  7649  8 Jul 09:12 /usr/share/syscons/keymaps/uk.dvorak.kbd
%

The manual page for keymap(5) suggests sysctl machdep.enable_panic_key=1, which is consistent with what I found in GitHub.

From the manual page for vt(4) I see that I can also sysctl kern.vt.kbd_panic=1, no mention of this in GitHub.

I can kbdcontrol -l /usr/share/syscons/keymaps/uk.iso.kbd at e.g. ttyv1 however when I try the same in a desktop environment:

Code:
root@mowa219-gjp4-8570p:~ # kbdcontrol -l /usr/share/syscons/keymaps/uk.iso.kbd
kbdcontrol: setting keymap: Inappropriate ioctl for device
root@mowa219-gjp4-8570p:~ #

I can panic on demand, using the key chord, with machdep.enable_panic_key disabled (0). So, what's the purpose of this sysctl variable?

How can I avoid the need to manually use kbdcontrol(1)?

Is kbdmap bugged?

<https://www.freebsd.org/cgi/man.cgi?query=kbdcontrol&sektion=1&manpath=FreeBSD+13.0-RELEASE>
<https://www.freebsd.org/cgi/man.cgi?query=kbdmap&sektion=1&manpath=FreeBSD+13.0-RELEASE>
<https://www.freebsd.org/cgi/man.cgi?query=keymap&sektion=5&manpath=FreeBSD+13.0-RELEASE>
<https://www.freebsd.org/cgi/man.cgi?query=vt&sektion=4&manpath=FreeBSD+13.0-RELEASE>



Notes to self

<https://cgit.freebsd.org/src/commit/?id=43d7128c1450d36af259094b7cf39c0c4d17908c>

Expand kdb_alt_break a little, most commonly used with the option ALT_BREAK_TO_DEBUGGER. In addition to "Enter ~ ctrl-B" (to enter the debugger), there is now "Enter ~ ctrl-P" (force panic) and "Enter ~ ctrl-R" (request clean reboot, ala ctrl-alt-del on syscons). …
 
Hello Graham,
Glad you found my gist on Github useful but it was meant for the 9.2 Release. Sorry.

the kern.vt.kbd_panic tunable does the same as machdep.enable_panic_key but in the virtual terminal console driver VT(4) instead of the console driver SYSCONS(4). According to the FreeBSD Wiki NEWCONS page:

vt(4) is a new console driver implementation (dubbed the "Newcons" project) to replace syscons(4), adding the following features:
Also, the VT(4) history section confirms that:
The vt driver first appeared in FreeBSD 9.3.
Every time a key is pressed, the vt_kbdevent function in VT(4) driver code is called which reads the pressed key status and then processes it by calling vt_processkey in which it then calls the vt_machine_kbdevent to act on the special keys pressing. If the special key is the panic key defined by KBDMAP(5), it panics the kernel only when this kbd_panic tunable is enabled. Clearly, this information is missing on the KBDMAP(5) manpage.
 
I can kbdcontrol -l /usr/share/syscons/keymaps/uk.iso.kbd at e.g. ttyv1 however when I try the same in a desktop environment:
Code:
root@mowa219-gjp4-8570p:~ # kbdcontrol -l /usr/share/syscons/keymaps/uk.iso.kbd
kbdcontrol: setting keymap: Inappropriate ioctl for device
root@mowa219-gjp4-8570p:~ #

The kbdcontrol(1) is to set various keyboard-related options for the syscons(4) or vt(4) console driver, not the pseudo-terminal driver.

How can I avoid the need to manually use kbdcontrol(1)?
According to KEYBOARD CONFIGURATION section:
You may set variables in /etc/rc.conf or /etc/rc.conf.local in order to
configure the keyboard at boot time. The following is the list of rele-
vant variables.

keymap Specifies a keyboard map file for the -l option.
keyrate Sets the keyboard repeat rate for the -r option.
keychange Lists function key strings for the -f option.
So Just adding the following variable to rc.conf.local is equal to running kbdcontrol -l /usr/share/syscons/keymaps/uk.iso.kbd at boot time:

Code:
keymap=/usr/share/syscons/keymaps/uk.iso.kbd
 
Thanks!

My /etc/rc.conf previously included this, which was not effective:

keymap="uk.iso.kbd"

Specifying the full path is effective.
 
Back
Top