Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the keyboard layout from the Vagrantfile

I'm using the DevBox of JHipster, which is a XUbuntu Vagrant box.

I want to change the keyboard layout during the provisionning of the box, and make it effective even on the login page, without the need of a reboot, so the user can just use it directly after the first start of the VM.

I tried several commands to change the keyboard layout:

  • setxkbmap fr (won't work since shell provisionning is done with root and setxkbmap can't be used with root)
  • loadkeys fr (no errors but no result)
  • sed -ie '/^XKBLAYOUT=/s/".*"/"fr"/' /etc/default/keyboard (apparently works but have to be "sourced")

and several commands to apply the changes:

  • udevadm trigger --subsystem-match=input --action=change
  • dpkg-reconfigure -f noninteractive keyboard-configuration (noninteactive because it is a shell script)
  • setupcon --force (force because without it it complains that it's not a Linux terminal)

None of them worked (or more precisely, the combination of sed and udevadm seemed to work, but when I tried it with a newly installed VM, it did not).

Any idea on how to make it work ?

EDIT:

Ok it was a serious case of PEBKAC...

For the record, the correct combination for me was: sed -ie '/^XKBLAYOUT=/s/".*"/"fr"/' /etc/default/keyboard && udevadm trigger --subsystem-match=input --action=change

I just badly refactored the variable containing the language (fr here), so it printed nothing...

EDIT:

Well it wasn't just a PEBKAC, it works fine on the login page but not once I'm logged in (even if it worked before I reinstalled everything).

like image 687
CidTori Avatar asked Sep 13 '25 15:09

CidTori


1 Answers

Ok it was a serious case of PEBKAC...

For the record, the correct combination for me was: sed -ie '/^XKBLAYOUT=/s/".*"/"fr"/' /etc/default/keyboard && udevadm trigger --subsystem-match=input --action=change

I just badly refactored the variable containing the language (fr here), so it printed nothing...


EDIT: Well it wasn't just a PEBKAC, it works fine on the login page but not once I'm logged in (even if it worked before I reinstalled everything).

like image 199
CidTori Avatar answered Sep 17 '25 06:09

CidTori