clux/provision

systemd-firstboot + localectl

clux opened this issue · 4 comments

clux commented

Not sure how these are meant to work.

I thought the main point was that you were outside the chroot to run systemd-firstboot with --root /mnt to set the locales, but you need to be inside the chroot to run locale-gen so that your choice of default locale has any impact at all.

Maybe I need to do:

chroot /mnt
echo "en_GB.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
systemd-firstboot --locale=en_GB.UTF-8 --locale-messages=en_GB.UTF-8
clux commented

Because different things expect different outputs, we need to run all of these it seems.
systemd-firstboot seems to work best inside the chroot.

Definitely need to create the two locales via locale-gen if we need something that's not en_US (as firstboot only supports one, and steam + other things expects en_US to exist).

localectl will not work inside the chroot, only after boot.

locale-gen is a script that comes with glibc systems. Note that the semantics of /etc/locale.gen are slightly different on Gentoo than on other distros. It needs to be run inside the chroot after you have fiddled with /etc/locale.gen. Portage will also run the tool as a post_install step for sys-libs/glibc, if /etc/locale.gen is blank or all commented out (the default) it may take a while as it generates a few hundred locales in serial. A safe, but slow operation.

Since you typically don need all of the locales on a personal system, setting /etc/locale.gen speeds this up by a lot.

systemd-firstboot should call localectl when it runs. Note the localectl and firstboot don't operate on the filesystem directly, instead they use dbus APIs to get their jobs done. This can have the unfortunate effect of not actually doing what you think they should be doing, regardless if you are in a chroot or not (blame IPC).

It's probably best to run systemd-firstboot, the first time that you actually boot, e.g. a good time is when you generate system ssh host keys, or the /etc/machine-id file.
For things like localectl and timedatectl, you could also setup those symlinks on the filesystem by hand, or by config management.

It's tricky setting up a modern system and just relying on chroot. You may need to use a few more layers of the container stack. I've been using systemd-nspawn -D $directory as a drop-in replacement for chroot in the meantime.

clux commented

Hm, didn't know systemd-firstboot was calling localectl, since the former is meant to work even outside the chroot (and it does report it wrote to files inside /etc).

But I can possibly move my firstboot call to after I actually boot. The root option seems weird to have if it's not working properly outside it though.

Currently I have made a solution to pass over a few idempotent scripts that manages localectl and timedatectl (see scripts folder) so got a solution for it at least.

clux commented

Tried doing systemd-firstboot after booting properly. Means I have to do an extra boot to get the hostname to stick (needed in ansible step) so that wasn't worth it. Also need to call localectl manually anyway (for colemak) so gonna stick with calling it inside the chroot only.