[systemd-devel] Simple oneshot service before switching root leads to no /var mount

Lennart Poettering lennart at poettering.net
Wed Oct 14 09:08:52 PDT 2015

On Mon, 28.09.15 15:40, Aaron_Wright at selinc.com (Aaron_Wright at selinc.com) wrote:

> I'm rolling my own initrd, and I'm trying to run a oneshot service in 
> initrd just before the switch root happens. I added this unit to the 
> initrd and enabled it.
> [Unit]
> Description=Test Unit
> Requires=initrd-fs.target
> After=initrd-fs.target
> [Service]
> Type=oneshot
> ExecStart=/bin/sh -c "echo hello"
> [Install]
> RequiredBy=initrd-switch-root.target
> The service does run, and I get "hello" in the journal, but then my /var 
> mount doesn't mount. I'm having a hard time correlating the two seeming 
> different things. The var.mount unit complains about a failed dependency. 
> It's dependency is dev-disk-by\x2dpartlabel-varfs.device, which has no 
> logs, is loaded, but inactive (dead). There is also a fsck dependency that 
> is loaded, but inactive (dead).

Well, the var.mount backing device never appeared then.

> Without this simple oneshot service in initrd, everything works fine, fsck 
> checks varfs and /var is mounted. Thoughts?

Well, that service does not set DefaultDependencies=no, hence will be
ordered after local-fs.target, and hence after var.mount... but you
also use it in earliest boot and effectively order it before
initrd-switch-root.target. Which means you have a cyclic dep, as you
have a service that wants to be in late boot, but is ordered into
early boot...

systemd should log about cyclic deps like this.

Anyway, long story short: you must set DefaultDependency=no for all
initrd and early-bird services, as otherwise your service will be
placed into late boot, via the implicit default deps, and that makes
no sense for the initrd.


Lennart Poettering, Red Hat

More information about the systemd-devel mailing list