In CentOS you can use the nice Perl-based virt-builder file editing feature to edit the appropriate configuration file:
virt-builder centos-6 \ --edit '/etc/sysconfig/keyboard: s/^KEYTABLE=.*/KEYTABLE="uk"/'
Any line in the file matching
KEYTABLE=... is replaced by
KEYTABLE="uk". This works by running the Perl expression (
s/.../.../ above, but full Perl programs are possible) on the guest file (
/etc/sysconfig/keyboard) and uploading the result.
Debian is also simple:
virt-builder debian-7 \ --edit '/etc/default/keyboard: s/^XKBLAYOUT=.*/XKBLAYOUT="gb"/'
Fedora requires that we run a program,
localectl(1). Unfortunately localectl requires that dbus is running (for good reasons, but in this case it’s unhelpful), so we can’t just use
--run-command to run it while building the guest because libguestfs doesn’t run a dbus daemon. Instead we’ve got to schedule the command to run at first boot, like this:
virt-builder fedora-20 \ --firstboot-command 'localectl set-keymap uk'
Should virt-builder try to hide all this complexity behind a nice, simple
--keyboard option? It’s something to consider.
It would be nice if distros could be more standardized too. I’m suspicious of requiring a program to be run in order to change what ought to be a pure configuration file setting. (If your objection is that other programs must be informed when the configuration changes, then dbus could provide a way to monitor when configuration files change, implemented using inotify.)