Ubuntu-12.04

為鍵盤配置設置 debconf 選擇失敗…佈局最終為阿富汗尼

  • January 22, 2021

我有一台我安裝的機器,設置了德語鍵盤,但它忽略了我的設置,並且安裝了美式鍵盤。我確定我設置了它,因為如果我不設置它,它會以互動方式詢問,但我想要一個無人值守的安裝。

這是 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

最後這是解決方案,它很簡單,但我花了兩天時間才找到它:(

解決方案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 中不起作用。

引用自:https://serverfault.com/questions/539911