You are not logged in.

#1 2016-01-01 13:10:04

STaRDoGG
Member
Registered: 2016-01-01
Posts: 6

Executing systemd commands at very first boot

Hi,

I am currently setting up a script which automatically goes through the installation process of Arch Linux. Currently I am at the stage where I want to run some systemd commands, namely:

hostnamectl set-hostname ...
localectl set-locale LANG=...
localectl set-keymap ...
timedatectl set-ntp true
timedatectl set-timezone ...

To run commands inside the bootstrapped container I use arch-chroot. The problem I am experiencing, however, is that these commands only run with a bus connection. This connection is not present at this stage of the installation process (surprisingly, systemctl does not require a bus connection):

[root@archiso ~]# arch-chroot /mnt hostnamectl set-hostname foo
Failed to create bus connection: No such file or directory

I am aware that for each of these commands there is a more low-level alternative that I could resort to, e.g. echo the hostname to /etc/hosts instead of using hostnamectl. However, I would like to use the aforementioned systemd wrappers if possible. I would also like to avoid (re)booting to the container to create a bus connection since that would be awkward to do in a scripting solution (I also checked systemd-nspawn).

Is there any way to execute those commands in the container at the very first boot?

Cheers

Last edited by STaRDoGG (2016-01-01 13:10:28)

Offline

#2 2016-01-01 13:25:49

ayekat
Member
Registered: 2011-01-17
Posts: 1,590

Re: Executing systemd commands at very first boot

Why not place a script in the chroot that executes those commands? Then you could do something like

arch-chroot /mnt /bin/bash -c /my_install_script.sh

Not sure if this works, though. But I guess it would be a lot more elegant than chroot'ing into and out of an environment for each command.


pkgshackscfgblag

Offline

#3 2016-01-01 15:36:15

STaRDoGG
Member
Registered: 2016-01-01
Posts: 6

Re: Executing systemd commands at very first boot

ayekat wrote:

Not sure if this works, though.

Doesn't work.

Offline

#4 2016-01-01 15:49:58

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,565

Re: Executing systemd commands at very first boot

STaRDoGG wrote:

I am aware that for each of these commands there is a more low-level alternative that I could resort to...

Resort to? What do you think those fancy tools end up doing? I don't understand your insistence on needing an extra layer here.

Online

#5 2016-01-02 06:08:35

tom.ty89
Member
Registered: 2012-11-15
Posts: 897

Re: Executing systemd commands at very first boot

Try systemd-nspawn tongue

Offline

#6 2016-01-02 11:01:43

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Executing systemd commands at very first boot

ayekat wrote:

Why not place a script in the chroot that executes those commands? Then you could do something like

arch-chroot /mnt /bin/bash -c /my_install_script.sh

Not sure if this works, though. But I guess it would be a lot more elegant than chroot'ing into and out of an environment for each command.

This could be simplified to:

arch-chroot /mnt /my_install_script
STaRDoGG wrote:

Doesn't work.

Here it does.
Are you sure that your script is located at /mountpoint/scriptname and called as /scriptname?

Offline

#7 2016-01-02 13:50:00

STaRDoGG
Member
Registered: 2016-01-01
Posts: 6

Re: Executing systemd commands at very first boot

respiranto wrote:

Here it does.
Are you sure that your script is located at /mountpoint/scriptname and called as /scriptname?

The script runs of course. The missing bus connection problem remains though.

[root@archiso ~] echo "hostnamectl set-hostname foo" > /mnt/my_install_script
[root@archiso ~] chmod o+x /mnt/my_install_script
[root@archiso ~] arch-chroot /mnt /my_install_script
Failed to create bus connection: No such file or directory

Last edited by STaRDoGG (2016-01-02 13:50:23)

Offline

#8 2016-01-02 14:39:09

Steef435
Member
Registered: 2013-08-29
Posts: 577
Website

Re: Executing systemd commands at very first boot

Like you mentioned yourself, if you had echod the hostname to /etc/hostname you would be done right now. It's even how it's recommended in the installation guide. The same goes for the rest of the commands (I'm not entirely sure about the ntp one but I dare guess that's just enabling a systemd service).

You're not doing anything wrong by doing it that way. I agree with Scimmia. It's easier, takes less time and you can probably boast about it at birthday parties. What more could you possibly wish for?

Offline

#9 2016-01-02 15:15:55

STaRDoGG
Member
Registered: 2016-01-01
Posts: 6

Re: Executing systemd commands at very first boot

Steef435 wrote:

Like you mentioned yourself, if you had echod the hostname to /etc/hostname you would be done right now.

I'm currently doing it that way and it's not a big deal. I was just wondering if it is possible to use the systemd wrappers for t his purpose at the very first boot.

Offline

#10 2016-01-02 15:53:31

Steef435
Member
Registered: 2013-08-29
Posts: 577
Website

Re: Executing systemd commands at very first boot

Doesn't sound impossible. You could try starting a D-Bus daemon. There seems to be a systemd abstraction for that: /usr/lib/systemd/user/dbus.service

But I wouldn't be surprised if they might as well want to use the message bus for something if they require it (checking if systemd-unicornd is free tonight?) so maybe you'll need to launch other things too.

For science, I guess. :-)

Offline

Board footer

Powered by FluxBB