Tip: Set the guest language in virt-builder

The latest virt-builder can now set the default timezone of a guest using a simple flag:

virt-builder debian-7 \
  --timezone Europe/London

I wanted to add a flag for setting the default language, but it’s essentially impossible.

The problem is that, unlike timezone, there’s no configuration file where you just set the language and that’s it. Each Linux distro and each language you want to set requires a unique combination of:

  • Installing fonts packages.
  • Installing and selecting an input method.
  • Setting up locales.
  • Configuring perhaps multiple things.

To show you how complex this is, here’s the technique I finally came up with (after hours and hours of trying) to set a Fedora 20 guest to Japanese:

virt-builder fedora-20 \
  --size 20G \
  --update \
  --install @japanese-support \
  --install @xfce \
  --install xorg-x11-server-Xorg,xorg-x11-drivers,rsyslog \
  --link /usr/lib/systemd/system/graphical.target:/etc/systemd/system/default.target \
  --firstboot-command 'localectl set-locale LANG=ja_JP.utf8' \
  --firstboot-command 'localectl set-keymap jp' \
  --firstboot-command 'systemctl isolate graphical.target'

And the same thing, but for Debian 7 (Wheezy):


virt-builder debian-7 \
  --size 20G \
  --install $pkgs \
  --edit '/etc/inittab: s,^#([1-9].*respawn.*/sbin/getty.*),$1,' \
  --edit '/etc/locale.gen: s,^#\s*ja,ja,' \
  --write '/etc/default/locale:LANG="ja_JP.UTF-8"' \
  --run-command "locale-gen"

I would expect that both of these methods would be substantially different for other distros, other languages, or even other versions of Fedora or Debian.

Of course you might say it’s virt-builder’s job to hide all this complexity from the user behind a nice little --language option. And I’m sympathetic — we already do that sort of thing for setting hostnames and installing packages. But this seems like a towering problem that I don’t think we can hope to solve.

Dear distros, please make it easy to install new languages!


1 Comment

Filed under Uncategorized

One response to “Tip: Set the guest language in virt-builder

  1. Pingback: Tip: Set the keyboard layout in virt-builder | Richard WM Jones

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.