[Buildroot] [PATCH 5/6] systemd: add hook to fix /run, /var

Eric Le Bihan eric.le.bihan.dev at free.fr
Tue Jul 8 13:05:47 UTC 2014


Hi!
On Mon, Jul 07, 2014 at 06:43:52PM +0200, Arnout Vandecappelle wrote:
> On 03/07/14 18:57, Eric Le Bihan wrote:
> > Add a post installation hook to fix target runtime data directories
> > /var/{lock,run,tmp} and /run. Theses directories will be populated by
> > systemd according to the configuration files from /usr/lib/tmpfiles.d.
>
>  I don't understand why this is needed, or how this can work...
>
>  Currently, /run, /var/run, /var/lock, and /var/tmp are all symlinks to /tmp
> where a tmpfs is mounted. I would expect that this is OK for systemd.
>
>  With this change, /run no longer links to /tmp, but it becomes a directory on
> the rootfs. So unless systemd mounts a tmpfs on /run, this won't work at all.
> And on my Debian sid system which uses systemd, I see that /run is mounted in
> /init in the initramfs, so before systemd is started. We don't do that in
> buildroot, so how can this work?

When started, systemd will mount /run as tmpfs. Search for mount_table in
src/core/mount-setup.c in the source tree to see all the mount operations
performed.

Once running, systemd will start the service systemd-tmpfiles [1], which is in
charge of populating the volatile and temporary files and directories,
according to configuration files [2] located in /usr/lib/tmpfiles.d/.

The link from /run to /var/run is mentioned in var.conf:

  L /var/run - - - - ../run

/var/tmp is handled from tmp.conf:

  d /tmp 1777 root root 10d
  d /var/tmp 1777 root root 30d

/var/lock is handled from legacy.conf

  L /var/lock - - - - ../run/lock

And I've just noticed etc.conf will handle the creation of the symlink for
/etc/resolv.conf, so I can simplify my post installation hook :-)

  L /etc/resolv.conf - - - - ../run/systemd/resolve/resolv.conf

We can see that for /var/run and /var/tmp, the types 'd' and 'L' are used,
which means that if the directories/symlinks exist (created by the target
skeleton), systemd-tmpfiles will not touch them. /var/run not being a symlink
to /run made systemd-networkd not work properly on my system.

Best regards,
ELB

[1] http://www.freedesktop.org/software/systemd/man/systemd-tmpfiles.html
[2] http://www.freedesktop.org/software/systemd/man/tmpfiles.d.html



More information about the buildroot mailing list