Hello Jean-Michel,

> On 15 Jan 2016, at 09:13, Jean-Michel Barbet 
> <jean-michel.bar...@subatech.in2p3.fr> wrote:
> 
> I am fighting with SL72 systemd. I am trying to build kind of an
> appliance based on a LiveCD (created with livecd-creator).
> 
> The idea is to read an USB key, early enough in the startup process, and
> overwrite somes files in /etc with the content of the USB key.
> In particular, there are /etc/sysconfig/network-script/ifcfg-xxx files
> for configuring the network, ssh keys and a /etc/rsyslogd/file.conf
> 
> I did it using a rc-local.service but it is not run early enough and
> the network configuration is not right.

yes, the boot process SL7 inherits from Fedora is aggressively optimized for 
bringing up a login prompt as early as possible, by starting everything in 
parallel that can be. While this is fine for a Laptop or Workstation managed by 
the user, it makes it really hard to run startup tasks before certain other 
services are started :-(

> => Did someone on this list try sth similar ? Ideas on how to have
>   the USB read early ?

The only reliable way I found is to create an extra target as a synchronization 
point, boot into that instead of default.target, and have the last service for 
that target "isolate" default.target.

Let's call your task "localconfig". You'll create a localconfig.service doing 
the work:

---8<---
[Unit]
Description=localconfig: apply some config early
After=basic.target

[Service]
ExecStart=/my/script
Type=oneshot

[Install]
WantedBy=localconfig.target default.target
--->8---

and a localconfig_done.service to run after localconfig is complete:

---8<---
[Unit]
Description=localconfig_done: commence bootup after localconfig
After=basic.target localconfig.service

[Service]
ExecStart=/usr/bin/systemctl isolate default.target
Type=simple
RemainAfterExit=yes

[Install]
WantedBy=localconfig.target default.target
--->8---

and a localconfig.target requiring it:

---8<---
[Unit]
Description=localconfig: synchronization point for early config
Requires=basic.target
After=basic.target
Conflicts=rescue.service rescue.target

Wants=localconfig.service localconfig_done.service
 
[Install]
WantedBy=default.target
--->8---

Now add systemd.unit=localconfig.target to the kernel command line, cross 
fingers and reboot.

> Moreover, I am doubtful on the use of NetworkManager service in this
> situation.

That would make it easier to run your script before the network is configured. 
But it wouldn't use your ifcg-xxxx files.

The above may not be perfect or even wrong (I didn't test it), or there may be 
a more elegant solution. If so, rant away ;-)

Still hope it helps,
        Stephan

-- 
Stephan Wiesand
DESY - DV -
Platanenallee 6
15738 Zeuthen, Germany

Reply via email to