AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 539911
Accepted
Peter
Peter
Asked: 2013-09-19 05:29:19 +0800 CST2013-09-19 05:29:19 +0800 CST 2013-09-19 05:29:19 +0800 CST

为键盘配置设置 debconf 选择失败...布局最终为阿富汗尼

  • 772

我有一台我安装的机器,设置了德语键盘,但它忽略了我的设置,并且安装了美式键盘。我确定我设置了它,因为如果我不设置它,它会以交互方式询问,但我想要一个无人值守的安装。

这是 Ubuntu 12.04.3

所以现在之后,我想编写一个修复脚本以使其成为德语键盘。

因此,首先我在一台机器上以交互方式设置设置,然后读取设置以查看它们的值,然后在另一台机器上,我设置选择:

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 "

然后我显示选择:

debconf-show keyboard-configuration

这是输出:

* 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:

然后重新配置包以使系统实际使用设置,我运行:

DEBIAN_FRONTEND=noninteractive dpkg-reconfigure keyboard-configuration

这是输出:

update-initramfs: deferring update (trigger activated)

然后检查发生了什么,我再次检查设置:

debconf-show keyboard-configuration

这是输出:

* 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

为什么哦,为什么将其变成阿富汗语布局(在每个问题的字母列表中首先选择)?为什么它不能只使用我的设置,或者至少忽略它们,而不是用虚假值设置它们!

而在过去,我使用了更像这样的东西,但使用了其他东西(如后缀等):

apt-get install --reinstall keyboard-configuration

但在这种情况下,使用键盘配置,它的作用与

DEBIAN_FRONTEND=noninteractive dpkg-reconfigure.

我还将交互式设置机器与重新配置之前使用上述脚本编写的机器进行了比较,整个机器的 debconf 是相同的,除了“grub-pc grub-pc/install_devices ...”有一个 id,显然不是相关的。如果我在交互式安装的机器上运行脚本化方法,它不会重置为阿富汗尼,因此尽管 debconf 相同,但系统的行为会有所不同。

有针对这个的解决方法吗?

我已经看过了:

“dpkg-reconfigure 键盘配置”实际上是做什么的? http://ubuntuforums.org/showthread.php?t=1793250 自动化 dpkg-reconfigure tzdata

ubuntu-12.04
  • 5 5 个回答
  • 8843 Views

5 个回答

  • Voted
  1. Wtower
    2016-02-02T08:03:51+08:002016-02-02T08:03:51+08:00

    我理解你对此感到沮丧。这是我在类似情况下(流浪规定)处理这个问题的方法,所以希望这一天已经到来。

    关键是使用 debconf-utils 来描述配置。第一的:

    sudo apt-get install debconf-utils
    

    您可以通过以下方式查看当前配置:

    debconf-get-selections | grep keyboard-configuration
    

    处理所有这些配置选项可能有点乏味,因此您可能希望dpkg-reconfigure keyboard-configuration在一台机器上执行交互,就像建议的解决方案一样。然后,使用上面的命令将新设置导出到一个新文件,比如file.conf.

    将文件传输到需要配置的机器上,然后:

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

    就是这样。

    奖励:Ansible 任务

    如果你使用 Ansible,这里有一段我​​的剧本:

    - 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
    
    • 4
  2. Best Answer
    Badr Elmers
    2021-01-22T00:28:40+08:002021-01-22T00:28:40+08:00

    最后这是解决方案,它很简单,但我花了两天时间才找到它:(

    解决方案1:

    • 这将用于在您keyboard-configuration第一次安装时配置键盘,或者当您已经安装它并且想要再次重新配置它时。
    • 这也适用于内部chroot:)
    • 你不需要再使用debconf-set-selections了。
    DEBIAN_FRONTEND=noninteractive apt-get install -y console-setup keyboard-configuration
        
    # this is the trick, you have to change the default keyboard config before 
    # running dpkg-reconfigure or you will always end with what it is configured
    #  in /etc/default/keyboard, so for a french keyboard for example:
    echo '
    XKBMODEL="pc105"
    XKBLAYOUT="fr"
    XKBVARIANT=""
    XKBOPTIONS=""
        
    BACKSPACE="guess"
    ' > /etc/default/keyboard
        
    dpkg-reconfigure --frontend noninteractive keyboard-configuration
    

    就这样。请注意,在 chroot 中不会设置键盘,但会为下次重新启动进行配置。

    我用debian 10、debian testing(11)、debian SID、ubuntu 16.04、ubuntu 18.04、ubuntu 20.04测试了上面的方法,都是用debootstrap安装的。

    您可以通过以下方式查看支持的选项列表 ( XKBLAYOUT, XKBVARIANT...):

    less /usr/share/X11/xkb/rules/xorg.lst
    

    dpkg-reconfigure如果 /etc/default/keyboard 中有任何错误,将使用其默认us键盘,因此请确保仅放置受支持的选项(例如ubuntu 16,没有布局的azerty变体fr,因此如果放置 azertydpkg-reconfigure则将恢复为默认值我们的键盘!)

    提示:如果您尝试连接 vnc(例如 qemu vnc),那么您绝对需要使用tigervnc 客户端才能使键盘按需要工作,所有其他 vnc 客户端都已损坏。如何使用 VNC 客户端将键盘布局设置为 KVM (libvirt)

    解决方案2:

    使用 systemd 的操作系统的另一个简单解决方案是:

    localectl set-keymap fr 
    localectl set-x11-keymap fr
    

    注意:这不能在 chroot 中使用,因为它需要一个活动的 dbus 连接。

    解决方案3:

    使用 setupcon

    # let's create  multiple keyboard config
    echo '
    XKBMODEL="pc105"
    XKBLAYOUT="us"
    XKBVARIANT=""
    XKBOPTIONS=""
    
    BACKSPACE="guess"
    ' > /etc/default/keyboard.ENbadr
    
    echo '
    XKBMODEL="pc105"
    XKBLAYOUT="fr"
    XKBVARIANT="azerty"
    XKBOPTIONS=""
    
    BACKSPACE="guess"
    ' > /etc/default/keyboard.FRbadr
    
    #activate the lang you want with
    setupcon FRbadr
    
    

    但这在 chroot 中不起作用。

    • 4
  3. Peter
    2013-09-27T03:32:40+08:002013-09-27T03:32:40+08:00

    所以......希望有一天其他人会有一个正确的答案,但这是我最终做的事情,这与我多年前在没有预置的情况下所做的事情相同:

    一个节点上的交互式键盘设置:

    dpkg-reconfigure keyboard-configuration
    

    然后完成后,复制控制台设置内容

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

    然后将该文件发送到所有节点,或将其放在 http 某处。

    然后使用脚本将其安装在每个节点上,而不是一次交互地安装一个:

    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
    

    只要您不以其他方式重新配置键盘,它可能会保持这种方式(就像以前安装多年一样)。但也许有些事情会再次混乱,例如:

    DEBIAN_FRONTEND=noninteractive dpkg-reconfigure keyboard-configuration
    
    • 3
  4. JonTheNiceGuy
    2018-05-16T07:37:07+08:002018-05-16T07:37:07+08:00

    事实证明,就我而言,我没有为 Ansible 中的 debconf 模块指定正确的类型。如果其他人正在尝试使用 Ansible 执行此操作,那么在您的“模板”机器(您首先用于获取所有正确设置的机器)中安装debconf-utils并运行,debconf-get-selections | grep keyboard-config然后运行debconf-show keyboard-configuration​​. 这为您提供了已更改内容的列表(旁边带有 * 的项目)。请注意,项目中的项目会debconf-get-selections告诉您它们是什么类型。

    为了让我将它们设置为,English (UK)我需要以下 ansible playbook 任务:

    - 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" }

    这是我上面引用的 debconf-* 命令的两个示例行:

    • (debconf-get-selections)keyboard-configuration keyboard-configuration/layout select English (UK)
    • (debconf 显示)* keyboard-configuration/layout: English (UK)
    • 0
  5. Mayra Delgado
    2020-02-05T00:43:25+08:002020-02-05T00:43:25+08:00

    我在这里使用了答案,让它与 saltstack 一起运行:

    我使用 jinja 模板进行配置(我删除了一些条目以使其更短):

    {% 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 %}
    

    现在我的状态是这样的:

    keyboard_conf:
      debconf.set:
      - name: "keyboard-configuration"
      - data: {{ keyboard_data }}
    
    • 0

相关问题

  • 无法安装 fastcgi ubuntu 服务器:软件包 libapache2-mod-fastcgi 不可用

  • UCEProtect Level 3 - 电子邮件进入垃圾邮件

  • 启用 mod ssl 后,apache 停止侦听端口 80

  • 使用 virtmanager 和 GUI 安装和配置 xen

  • Openstack 多节点:单独的 Glance 和 Keystone 机器

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve