0

Can I use systemd-nspawn to setup a "chroot" install(in that case debian using debootstrap) before booting it? I.e. unattended install and setup.

I need to set the keymap, hostname, maybe timezone and locale. And I'd like to use systemd tools such as hostnamectl, localectl, timedatectl,...

Is it possible and the way to do it or should I use config files? Are they even recognised by systemd? For example if I set a hostname in /etc/hostname is it recognised properly? Can I also set the keymap like that?

1

Is it possible

yes.

I've run Debian in nspawn. It works great with minimal installs.

On the other extreme, if you do this with a desktop install, you should expect to find one or two little issues to work around.

should I use config files? Are they even recogised by systemd? For example if I set a hostname in /etc/hostname is it recignised properly?

/etc/hostname definitely works, it's supported by systemd, it's exactly what hostnamectl would edit. In general, it's hard to see what you're worried about here. Debian Jessie defaults to systemd, so any documentation written for Debian Jessie about how to configure things - e.g. in the debootstrap appendix of the install guide - is supposed to work for systemd. (Although that appendix is more of a sketch, and doesn't show how you would make it run unattended).


From what you've said, you might be also interested in systemd-firstboot. I haven't tried to use it and my understanding is it's limited in some ways, but it could be informative.

In any case I think you would need to use systemd-nspawn --boot, having added a service file similar to the one used by systemd-firstboot. If you don't boot the system, e.g. hostnamectl won't work... Once your script has finished one way or another, it would also need to shut down the system.

One notable issue is if you have any network services installed (including avahi, cups, ...), you probably want to run nspawn with --net-veth or equivalent, to avoid conflicts with the host network services. To get network access at this point (e.g. to install more packages), set up a DHCP client on the interface host0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.