[systemd-devel] Implementing resume from hibernation as a systemd unit file

Lennart Poettering lennart at poettering.net
Fri Aug 15 03:19:50 PDT 2014


On Fri, 15.08.14 14:07, Ivan Shapovalov (intelfx100 at gmail.com) wrote:

> On Friday 15 August 2014 at 12:00:41, Lennart Poettering wrote:	
> > [...] 
> > > > > 
> > > > > So is "Before=local-fs-pre.target" a sufficient ordering for such resume unit?
> > > > > 
> > > > > Again, the resume unit must be started before any filesystems are (re)mounted
> > > > > read-write, either from initrd or not.
> > > > 
> > > > Yes. That should be enough.
> > > > 
> > > > > Seems like there's at least systemd-remount-fs.service that also needs to be
> > > > > taken into account...
> > > > 
> > > > That only runs after the transition into the host OS.
> > > 
> > > I'd like to make this work both with initramfs and without one (provided that
> > > the rootfs has been mounted read-only by using 'ro' kernel cmdline parameter).
> > > 
> > > In this case, what are the needed orderings?
> > 
> > Actually systemd-remount-fs.service uses After=local-fs-pre.target
> > anyway, so ordering before l-f-p.t should be nough.
> 
> Hm. In git (v215-651-g41488fe), it is
> 
> Before=local-fs-pre.target local-fs.target shutdown.target
> Wants=local-fs-pre.target

Ah, right. This is actually correct here. We want to make sure that the
root fs is remounted before we mount the other units, since this might
required creating additional directories to mount things on...

There are two more complications: 

a) if you want to make use of local-fs-pre.target you actually have to
   pull it in, it's a "passive" unit. See systemd.special(5).

b) You want to run your stuff before fsck is run on the devices, so that
   you don't end up interrupting an fsck that is half in progress.

To put this together, in your unit file you need:

    Before=local-fs-pre.target systemd-remount-fs.service systemd-fsck-root.service
    Wants=local-fs-pre.target

That should be enough. (You don't need to individually order the
systemd-fsck at .service instances for the other devices after your
service, since they are already ordered after systemd-fsck-root.service,
and you order yourself before that, so all is good).

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list