[systemd-devel] How to run *ctl command using systemd-nspawn

Lennart Poettering lennart at poettering.net
Wed Apr 17 08:13:23 PDT 2013


On Tue, 16.04.13 20:59, Koen Kooi (koen at dominion.thruhere.net) wrote:

> 
> Op 16 apr. 2013, om 20:14 heeft Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl> het volgende geschreven:
> 
> > On Tue, Apr 16, 2013 at 09:11:51AM +0200, Koen Kooi wrote:
> >> Hi,
> >> 
> >> To help with flashing the onboard eMMC of a 100000 boards I'm using systemd-nspawn to run package postinstall scripts that generate UUIDs and some other things and it's working great for that! Every board now has a unique value in /etc/machine-id instead it being empty and systemd randomizing it on startup.
> >> 
> >> What doesn't work however is something like this:
> >> 
> >> 	systemd-nspawn -D ${PART2MOUNT} /usr/bin/timedatectl set-timezone Europe/Paris
> >> 
> >> or this:
> >> 
> >> 	systemd-nspawn -D ${PART2MOUNT} /usr/bin/hostnamectl set-hostname BeagleBoneBlack
> >> 
> >> I know I can run the lowlevel 'ln -sf <zoneinfo> /etc/timezone' or echo the name into /etc/hostname, but I'd like to use the *ctl commands because they work and have error handling built-in. 
> >> it looks like I would need -b to get the *ctl commands to work, but -b doesn't support running single commands and exiting.
> >> 
> >> My goal is to be able to drop in a rootfs tarball and change timezone and hostname settings in a config file for the flasher script and avoid generating N different tarballs. For use in the office lab I use something like [1] to generate the hostnames based on board revision and serial number.
> >> 
> >> So, is there a way to *ctl command using systemd-nspawn in a rootfs that wasn't specially prepared (e.g. helper units/targets) for that?
> > 
> > With very recent systemd just run:
> > 
> > PID=$(head -n1 /sys/fs/cgroup/systemd/machine/$NAME/system/tasks)
> > nsenter -m -u -i -n -p -t $PID /usr/bin/timedatectl set-timezone Europe/Paris
> > ...
> > nsenter -m -u -i -n -p -t $PID systemctl halt
> > 
> > where NAME is either speicified with -M or the name of the tree root.
> 
> I'll update my util-linux to get nsenter and give that a try, thanks!

Well, you wouldn't known when the right time is to enter the
machine... After all you#d have to do that after the dbus socket is
established, otherwise your timedatectl will still fail...

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list