fix<\/a>. However, I had similar problems with KDE configurations (e.g. kwinrc) that I changed not taking effect immediately when Vagrant first boots the system. You can fix this by looking to see if any new scripts have been added to the Autostart directory in the past few minutes and then restarting the KDE session. If you are modifying .bash_profile or .bashrc at first boot, you may still have a problem with these files running before your changes are made. The fix mentioned above should also fix this issue. Alternatively, if you are only modifying .bashrc, you could just sleep for a bit before starting any interactive shell. You could modify the configuration files in the base box; the only problem is that KDE doesn’t create the directories and files until your first login.<\/p>\n\n\n\nif [ ! -z \"$(find ~\/.kde\/Autostart -mtime -.002)\" ]; then\n kwin --replace >& \/dev\/null &\nfi<\/mark><\/code><\/pre>\n\n\n\nUsing auto-login obviates the problem of the login screen still using the old keyboard layout, but once you are logged in, the keyboard layout is still the old one. You can also set the keyboard layout for only the current X11 session, which takes effect immediately.<\/p>\n\n\n\n
> setxkbmap dvorak\n> setxkbmap -query\nrules: evdev\nmodel: evdev\nlayout: dvorak<\/mark><\/code><\/pre>\n\n\n\nIt probably won’t hurt to run this every time, but there is no need on subsequent logins. First, notice that once set-x11-keymap takes effect, the variant field of a setxkbmap query has been set.<\/p>\n\n\n\n
> more \/etc\/X11\/xorg.conf.d\/00-keyboard.conf\n# Read and parsed by systemd-localed. It's probably wise not to edit this file\n# manually too freely.\nSection \"InputClass\"\n Identifier \"system-keyboard\"\n MatchIsKeyboard \"on\"\n Option \"XkbLayout\" \"us,us\"\n Option \"XkbVariant\" \"dvorak,\"\nEndSection\n\n> setxkbmap -query\nrules: evdev\nmodel: evdev\nlayout: us,us\nvariant: dvorak,<\/mark><\/code><\/pre>\n\n\n\nSo we can add the following to .bash_profile or .bashrc, and it will only run before set-x11-keymap takes effect.<\/p>\n\n\n\n
if [[ ! $(setxkbmap -query) =~ variant:[[:space:]]*dvorak ]]; then\n setxkbmap dvorak\nfi<\/mark><\/code><\/pre>\n\n\n\nThere is still a problem though. If you ssh in, you don’t want to change the keyboard layout because you will already be using the altered keyboard layout of the host. The xhost command will return false if it can’t connect to an X11 display.<\/p>\n\n\n\n
> xhost # from GUI\naccess control enabled, only authorized clients can connect\nSI:localuser:root\nSI:localuser:myuser\n\n> xhost # from ssh\nxhost: unable to open display \"\"<\/mark><\/code><\/pre>\n\n\n\nSo, with this extra condition, we now only run setxkbmap before setx-x11-keymap takes effect and if we are in the GUI.<\/p>\n\n\n\n
if xhost >& \/dev\/null && [[ ! $(setxkbmap -query) =~ variant:[[:space:]]*dvorak<\/mark> ]]; then\n setxkbmap dvorak\nfi<\/mark><\/code><\/pre>\n\n\n\nAnother possibility is to run setxkbmap in the auto-start script only the first time the auto-start script runs.<\/p>\n\n\n\n
Update<\/p>\n\n\n\n
There is an easier way to deal with the problem of setting the keyboard layout and KDE configuration files on first boot. If you have created a base box using Vagrant, simply leave the run level as the default. This is multi-user.target on CentOS with Systemd. Upon booting with X11, make any changes to the KDE configuration files, change to auto-login if you haven’t already, set the locale, and then change the run-level to graphical.target.<\/p>\n\n\n\n
systemctl isolate graphical.target\nsystemctl set-default graphical.target<\/code><\/pre>\n\n\n\nThe first line changes to the graphical run-level immediately. The second makes it permanent.<\/p>\n\n\n\n
There’s no longer any need to also change the keyboard layout using setxkbmap on the first login. And if you do it this way, you won’t run into any race conditions between updating configuration files and KDE loading those same configuration files.<\/p>\n","protected":false},"excerpt":{"rendered":"
Setting the keyboard layout on Linux\/X11 has always been a bit of a mystery to me. To make matters worse, I’m using Vagrant to frequently spin up a new VM; the extra step of system restart or log out so that changes can take effect is very unwelcome. When troubleshooting initialization and configuration issues, it’s …<\/p>\n
Linux Keyboard Layout Customization<\/span> Read More »<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/posts\/257"}],"collection":[{"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":24,"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":289,"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/posts\/257\/revisions\/289"}],"wp:attachment":[{"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.signalsguru.net\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}