5

I have a machine I netinstalled, with german keyboard set, but it ignored my setting, and it is installed with US keyboard. I'm sure I set it, because if I don't set it, it asks interactively, but I wanted an unattended install.

It's Ubuntu 12.04.3

So now afterwards, i want to script a fix to make it the german keyboard.

So first I interactively set the settings on one machine, then read the settings to see their values, and then on another machine, I set the selections with:

debconf-set-selections <<< "keyboard-configuration keyboard-configuration/altgr select The default for the keyboard layout"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/compose select No compose key"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/ctrl_alt_bksp boolean false"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/layoutcode string de"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/layout select German"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/modelcode string pc105"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/model select Generic 105-key (Intl) PC"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/optionscode string "
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/store_defaults_in_debconf_db boolean true"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/switch select No temporary switch"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/toggle select No toggling"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/unsupported_config_layout boolean true"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/unsupported_config_options boolean true"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/unsupported_layout boolean true"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/unsupported_options boolean true"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/variantcode string "
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/variant select German"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/xkb-keymap select "

Then I show the selections with:

debconf-show keyboard-configuration

And here is the output:

* keyboard-configuration/modelcode: pc105
* keyboard-configuration/unsupported_config_options: true
* keyboard-configuration/unsupported_config_layout: true
* keyboard-configuration/toggle: No toggling
* keyboard-configuration/compose: No compose key
* keyboard-configuration/layout: German
* keyboard-configuration/xkb-keymap:
* keyboard-configuration/variant: German
  debian-installer/console-setup-udeb/title:
* keyboard-configuration/switch: No temporary switch
* keyboard-configuration/unsupported_options: true
  console-setup/detect:
  console-setup/detected:
* keyboard-configuration/altgr: The default for the keyboard layout
* keyboard-configuration/ctrl_alt_bksp: false
* keyboard-configuration/unsupported_layout: true
* keyboard-configuration/variantcode:
* keyboard-configuration/model: Generic 105-key (Intl) PC
* console-setup/ask_detect: false
* keyboard-configuration/layoutcode: de
  keyboard-configuration/other:
* keyboard-configuration/store_defaults_in_debconf_db: true
* keyboard-configuration/optionscode:

And then to reconfigure the package to make the system actually use the settings, I run:

DEBIAN_FRONTEND=noninteractive dpkg-reconfigure keyboard-configuration

And here is the output:

update-initramfs: deferring update (trigger activated)

And then to check what happened, I check the settings again:

debconf-show keyboard-configuration

And here is the output:

* keyboard-configuration/modelcode: a4techKB21
  keyboard-configuration/unsupported_config_options: true
  keyboard-configuration/unsupported_config_layout: true
* keyboard-configuration/toggle: Caps Lock
* keyboard-configuration/compose: No compose key
* keyboard-configuration/layout: Afghani
* keyboard-configuration/xkb-keymap: af
* keyboard-configuration/variant: Afghani
  debian-installer/console-setup-udeb/title:
* keyboard-configuration/switch: No temporary switch
  keyboard-configuration/unsupported_options: true
  console-setup/detect:
  console-setup/detected:
* keyboard-configuration/altgr: The default for the keyboard layout
* keyboard-configuration/ctrl_alt_bksp: false
  keyboard-configuration/unsupported_layout: true
* keyboard-configuration/variantcode: ,
* keyboard-configuration/model: A4Tech KB-21
* console-setup/ask_detect: false
* keyboard-configuration/layoutcode: us,af
  keyboard-configuration/other:
* keyboard-configuration/store_defaults_in_debconf_db: true
* keyboard-configuration/optionscode: grp:caps_toggle,grp_led:scroll

Why oh why did it turn it into an Afghani layout (selected first in the alphabetical list for every question)? Why can't it just use my settings, or at least ignore, them, not set them with bogus values!

And in the past, I have used something more like this instead, but with other things (like postfix, etc.):

apt-get install --reinstall keyboard-configuration

But in this case with keyboard-configuration, it does the same as

DEBIAN_FRONTEND=noninteractive dpkg-reconfigure.

I also compared the interactively set up machine to the one scripted with the above before the reconfigure, and the entire machine's debconf is identical except for "grub-pc grub-pc/install_devices ..." which has an id, and is obviously not relevant. And if I run the scripted method on the interactively installed machine, it doesn't reset to Afghani, so the systems act different despite identical debconf.

Is there a solution to this?

I have already seen:

What does "dpkg-reconfigure keyboard-configuration" actually do? http://ubuntuforums.org/showthread.php?t=1793250 automate dpkg-reconfigure tzdata

4

I understand your frustration on this one. Here is how I deal with this in similar context (vagrant provisions), so hopefully the day has come.

The key is to use debconf-utils in order to describe the configuration. First:

sudo apt-get install debconf-utils

You can see the current configuration with:

debconf-get-selections | grep keyboard-configuration

Dealing with all these configuration options can be a bit tedious, so you might want to perform an interactive dpkg-reconfigure keyboard-configuration on one machine, as in the proposed solution. Then, export the new settings with the command above to a new file, say file.conf.

Transfer the file to the machines that need configuration and:

debconf-set-selections < file.conf
dpkg-reconfigure keyboard-configuration -f noninteractive

That's it really.

BONUS: Ansible tasks

In case you use Ansible, here is a piece of my playbook for this matter:

- name: Configuring keyboard [creating file]
  template: src=templates/deb-keyboard.conf.j2 dest=/home/vagrant/.deb-keybard.conf
  register: debconf_template

- name: Configuring keyboard [setting selections]
  shell: debconf-set-selections < /home/vagrant/.deb-keybard.conf
  become: true
  when: debconf_template.changed
  # or use handlers

- name: Configuring keyboard [reconfiguring dpkg]
  command: dpkg-reconfigure keyboard-configuration -f noninteractive
  become: true
  when: debconf_template.changed
| improve this answer | |
3

So ... hopefully some day someone else will have a proper answer, but here's what I ended up doing, which is the same thing I did years ago without preseed:

interactive keyboard setup on one node:

dpkg-reconfigure keyboard-configuration

Then when that's done, copy the console setup stuff

cd
tar czf console-setup.tgz /etc/console-setup

Then send that file to all nodes, or put it on http somewhere.

Then install it on every node with a script, rather than interactively one at a time:

cd
wget http://somewebserver/console-setup.gz -O ~/console-setup.tgz
cd /
mv /etc/console-setup /etc/console-setup.bak
tar xzf ~/console-setup.tgz
gunzip -c /etc/console-setup/cached.kmap.gz | loadkeys

And as long as you don't reconfigure the keyboard some other way, it'll probably remain this way (as it has for years on the previous install). But maybe there are some things that would mess again, such as:

DEBIAN_FRONTEND=noninteractive dpkg-reconfigure keyboard-configuration
| improve this answer | |
  • Great workaround this one. – Wtower Feb 1 '16 at 15:54
0

Turned out that in my case, I'd not specified the correct type for the debconf modules in Ansible. If anyone else is trying to do this with Ansible, then in your "template" machine (the one you're using to get all the right settings in the first place) install debconf-utils and run debconf-get-selections | grep keyboard-config then run debconf-show keyboard-configuration. This gives you a list of the things which are changed (items with the *'s next to them). Note that the items in the debconf-get-selections tell you what type they are.

For me to set them to English (UK) I needed the following ansible playbook task:

- name: Set keyboard layout debconf: name: "keyboard-configuration" question: "keyboard-configuration/{{ item.key }}" value: "{{ item.value }}" vtype: "{{ item.type|default('string') }}" with_items: - { key: "altgr", value: "The default for the keyboard layout", vtype: "select" } - { key: "compose", value: "No compose key", vtype: "select" } - { key: "ctrl_alt_bksp", value: "false", type: "boolean" } - { key: "variant", value: "English (UK)", vtype: "select" } - { key: "layout", value: "English (UK)", vtype: "select" } - { key: "model", value: "Generic 105-key PC (intl.)", vtype: "select" }

Here's two sample lines from the debconf-* commands I referenced above:

  • (debconf-get-selections) keyboard-configuration keyboard-configuration/layout select English (UK)
  • (debconf-show) * keyboard-configuration/layout: English (UK)
| improve this answer | |
0

I used the answers here, to get it running with saltstack:

I used a jinja template for the configuration (I removed some entries to get it shorter):

{% if grains["domain"] == "mydomain.de" %}
{% load_yaml as keyboard_data %}
  "keyboard-configuration/layoutcode":
    "type": "string"
    "value": "de"
  "keyboard-configuration/layout":
    "type": "select"
    "value": "German"
{% endload %}
{% else %}
{% load_yaml as keyboard_data %}
  "keyboard-configuration/layoutcode":
    "type": "string"
    "value": "us"
  "keyboard-configuration/layout":
    "type": "select"
    "value": "English (US)"
{% endload %}
{% endif %}

and now my state is like this:

keyboard_conf:
  debconf.set:
  - name: "keyboard-configuration"
  - data: {{ keyboard_data }}
| improve this answer | |

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.