package/systemd: pre-create directories for services
PATCH 1/1 package/systemd: pre-create directories for services
this adds a new hook and a corresponding variable to add addirectories and files after installation.
various services need directories in /var when they are started, and create them if necessary. Creating those before, allows those services to start even if /var is read-only.
--- package/systemd/systemd.mk | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
package/systemd/systemd.mk +19 -5
@@ -317,6 +317,7 @@ endif ifeq ($(BR2_PACKAGE_SYSTEMD_LOGIND),y) SYSTEMD_CONF_OPTS += -Dlogind=true +SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/linger/ else SYSTEMD_CONF_OPTS += -Dlogind=false endif
@@ -336,6 +337,7 @@ endif ifeq ($(BR2_PACKAGE_SYSTEMD_HOMED),y) SYSTEMD_CONF_OPTS += -Dhomed=true SYSTEMD_DEPENDENCIES += cryptsetup openssl +SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/home/ else SYSTEMD_CONF_OPTS += -Dhomed=false endif
@@ -380,12 +382,14 @@ endif ifeq ($(BR2_PACKAGE_SYSTEMD_COREDUMP),y) SYSTEMD_CONF_OPTS += -Dcoredump=true SYSTEMD_COREDUMP_USER = systemd-coredump -1 systemd-coredump -1 * - - - systemd core dump processing +SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/coredump/ else SYSTEMD_CONF_OPTS += -Dcoredump=false endif ifeq ($(BR2_PACKAGE_SYSTEMD_PSTORE),y) SYSTEMD_CONF_OPTS += -Dpstore=true +SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/pstore/ else SYSTEMD_CONF_OPTS += -Dpstore=false endif
@@ -436,6 +440,7 @@ endif ifeq ($(BR2_PACKAGE_SYSTEMD_TIMESYNCD),y) SYSTEMD_CONF_OPTS += -Dtimesyncd=true SYSTEMD_TIMESYNCD_USER = systemd-timesync -1 systemd-timesync -1 * - - - systemd Time Synchronization +SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/timesync/ else SYSTEMD_CONF_OPTS += -Dtimesyncd=false endif
@@ -485,18 +490,23 @@ ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) SYSTEMD_CONF_OPTS += -Dfallback-hostname=$(SYSTEMD_FALLBACK_HOSTNAME) endif +define SYSTEMD_INSTALL_ENTRY_HOOK + mkdir -p -m700 $(TARGET_DIR)/var/lib/private $(TARGET_DIR)/var/log/private \ + $(TARGET_DIR)/var/cache/private + mkdir -p -m1777 $(TARGET_DIR)/var/tmp + $(if $(BR2_PACKAGE_SYSTEMD_MACHINED),mkdir -p -m700 $(TARGET_DIR)/var/lib/machines) + mkdir -p $(addprefix $(TARGET_DIR)/,var/lib $(filter %/,$(SYSTEMD_POST_INSTALL_ENTRIES))) + touch $(addprefix $(TARGET_DIR)/,etc/machine-id $(filter-out %/,$(SYSTEMD_POST_INSTALL_ENTRIES))) +endef + define SYSTEMD_INSTALL_INIT_HOOK ln -fs multi-user.target \ $(TARGET_DIR)/usr/lib/systemd/system/default.target endef -define SYSTEMD_INSTALL_MACHINEID_HOOK - touch $(TARGET_DIR)/etc/machine-id -endef - SYSTEMD_POST_INSTALL_TARGET_HOOKS += \ + SYSTEMD_INSTALL_ENTRY_HOOK \ SYSTEMD_INSTALL_INIT_HOOK \ - SYSTEMD_INSTALL_MACHINEID_HOOK \ SYSTEMD_INSTALL_RESOLVCONF_HOOK define SYSTEMD_INSTALL_IMAGES_CMDS
@@ -532,6 +542,10 @@ endef SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_INSTALL_NSSCONFIG_HOOK +define SYSTEMD_PERMISSIONS + $(if $(SYSTEMD_TIMESYNCD_USER),/var/lib/systemd/timesync d 755 systemd-timesync systemd-timesync - - - - -) +endef + ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),) # systemd provides multiple units to autospawn getty as neede # * getty at .service to start a getty on normal TTY
Signature · 1 line
2.27.0
PATCH 1/1 package/systemd: pre-create directories for services
Norbert, All,
On 2020-07-18 01:42 +0200, Norbert Lange spake thusly:
Quoted 17 lines
this adds a new hook and a corresponding variable to add addirectories and files after installation.
various services need directories in /var when they are started, and create them if necessary. Creating those before, allows those services to start even if /var is read-only.
Signed-off-by Norbert Lange <[email protected]>--- package/systemd/systemd.mk | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)package/systemd/systemd.mk +0
-0
package/systemd/systemd.mk endif · line 320
Quoted 4 lines
package/systemd/systemd.mk +1
-0@@ -317,6 +317,7 @@ endif ifeq ($(BR2_PACKAGE_SYSTEMD_LOGIND),y) SYSTEMD_CONF_OPTS += -Dlogind=true +SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/linger/
The naming is not nice. Also, paths should be absolute:
SYSTEMD_CREATE_DIRS += /var/lib/systemd/linger/
However, I am not fond of mixing the directories creation with two
infras: post-isntall hooks and _PERMISSIONS tables.
So, in fact:
SYSTEMD_LOGIND_PERMISIONS = /var/lib/systemd/linger d 755 0 0 - - - - -
Ditto for the others conditional directories. And of course, we should also treat the non-conditional ones similarly.
[--SNIP--]
package/systemd/systemd.mk endif · line 443
Quoted 5 lines
package/systemd/systemd.mk +1
-0@@ -436,6 +440,7 @@ endif ifeq ($(BR2_PACKAGE_SYSTEMD_TIMESYNCD),y) SYSTEMD_CONF_OPTS += -Dtimesyncd=true SYSTEMD_TIMESYNCD_USER = systemd-timesync -1 systemd-timesync -1 * - - - systemd Time Synchronization +SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/timesync/
SYSTEMD_TIMESYNCD_PERMISIONS = /var/lib/systemd/timesync d 755 systemd-timesync systemd-timesync - - - - -
[--SNIP--]
package/systemd/systemd.mk ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) · line 500
Quoted 12 lines
package/systemd/systemd.mk +8
-0@@ -485,18 +490,23 @@ ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) SYSTEMD_CONF_OPTS += -Dfallback-hostname=$(SYSTEMD_FALLBACK_HOSTNAME) endif +define SYSTEMD_INSTALL_ENTRY_HOOK + mkdir -p -m700 $(TARGET_DIR)/var/lib/private $(TARGET_DIR)/var/log/private \ + $(TARGET_DIR)/var/cache/private + mkdir -p -m1777 $(TARGET_DIR)/var/tmp + $(if $(BR2_PACKAGE_SYSTEMD_MACHINED),mkdir -p -m700 $(TARGET_DIR)/var/lib/machines) + mkdir -p $(addprefix $(TARGET_DIR)/,var/lib $(filter %/,$(SYSTEMD_POST_INSTALL_ENTRIES))) + touch $(addprefix $(TARGET_DIR)/,etc/machine-id $(filter-out %/,$(SYSTEMD_POST_INSTALL_ENTRIES))) +endef
This would thus no longer be needed.
package/systemd/systemd.mk ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) · line 495
Quoted 8 lines
package/systemd/systemd.mk +0
-3define SYSTEMD_INSTALL_INIT_HOOK ln -fs multi-user.target \ $(TARGET_DIR)/usr/lib/systemd/system/default.target endef -define SYSTEMD_INSTALL_MACHINEID_HOOK - touch $(TARGET_DIR)/etc/machine-id -endef
This could also probably be replaced with a non-conditional entry in the permissions table, see below...
Quoted 8 lines
package/systemd/systemd.mk +1
-1SYSTEMD_POST_INSTALL_TARGET_HOOKS += \ + SYSTEMD_INSTALL_ENTRY_HOOK \ SYSTEMD_INSTALL_INIT_HOOK \ - SYSTEMD_INSTALL_MACHINEID_HOOK \ SYSTEMD_INSTALL_RESOLVCONF_HOOK define SYSTEMD_INSTALL_IMAGES_CMDS
package/systemd/systemd.mk endef · line 547
Quoted 6 lines
package/systemd/systemd.mk +3
-0@@ -532,6 +542,10 @@ endef SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_INSTALL_NSSCONFIG_HOOK +define SYSTEMD_PERMISSIONS + $(if $(SYSTEMD_TIMESYNCD_USER),/var/lib/systemd/timesync d 755 systemd-timesync systemd-timesync - - - - -) +endef
We usually do not use conditional in the permissions tables, but define conditional variables that we then re-use (see above):
define SYSTEMD_PERMISSIONS
/etc/machine-id f 644 0 0 - - - - -
$(SYSTEMD_LOGIND_PERMISIONS)
$(SYSTEMD_TIMESYNCD_PERMISIONS)
...
endefRegards,
Yann E. MORIN.
Quoted 7 lines
package/systemd/systemd.mk +1
-0+ ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),) # systemd provides multiple units to autospawn getty as neede # * getty at .service to start a getty on normal TTYSignature · 1 line
2.27.0
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 1/1 package/systemd: pre-create directories for services
I am kinda philosophically torn on this one...
According to man:file-hierarchy, /var MUST be writable (it MAY be a tmpfs if the system has no persistent, writable storage)
This means that daemons can assume that /var will be writable, and we might be starting a wild goose hunt to get them
working in all cases.
The clean way to have a file go in /var (at least with systemd) is to put it in /usr/share/factory/var/ and systemd will copy it to
/var on first boot (or every boot if it's a tmpfs)
this has the added advantage that /var can be empty at install time, can be easily reset by reformatting/emptying
without breaking the system.
I have no idea how factory is handled in sysV.
If buildroot wants to support read-only /var, it's supporting a "buggy setup" according to various standards including FHS.
And yeah... it's a buggy setup, but it's also a common setup :(
So, I guess it's important to point that out but I don't really know what the correct answer is for buildroot..
Jeremy
Le sam. 18 juil. 2020 ? 23:16, Yann E. MORIN <[email protected]> a ?crit :
Quoted 133 lines
Norbert, All,
On 2020-07-18 01:42 +0200, Norbert Lange spake thusly:
Quoted 17 lines
this adds a new hook and a corresponding variable to add addirectories and files after installation.
various services need directories in /var when they are started, and create them if necessary. Creating those before, allows those services to start even if /var is read-only.
Signed-off-by Norbert Lange <[email protected]>--- package/systemd/systemd.mk | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)package/systemd/systemd.mk +0
-0package/systemd/systemd.mk endif · line 320
Quoted 4 lines
package/systemd/systemd.mk +1
-0@@ -317,6 +317,7 @@ endif ifeq ($(BR2_PACKAGE_SYSTEMD_LOGIND),y) SYSTEMD_CONF_OPTS += -Dlogind=true +SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/linger/The naming is not nice. Also, paths should be absolute:
SYSTEMD_CREATE_DIRS += /var/lib/systemd/linger/However, I am not fond of mixing the directories creation with two
infras: post-isntall hooks and_PERMISSIONStables.So, in fact:
SYSTEMD_LOGIND_PERMISIONS=/var/lib/systemd/lingerd 755 0 0 - - - - -Ditto for the others conditional directories. And of course, we should also treat the non-conditional ones similarly.
[--SNIP--]
package/systemd/systemd.mk endif · line 442
Quoted 4 lines
package/systemd/systemd.mk +0
-0@@ -436,6 +440,7 @@ endif ifeq ($(BR2_PACKAGE_SYSTEMD_TIMESYNCD),y) SYSTEMD_CONF_OPTS += -Dtimesyncd=true SYSTEMD_TIMESYNCD_USER = systemd-timesync -1 systemd-timesync -1 * - -- systemd Time Synchronization
package/systemd/systemd.mk endif · line 443
Quoted 1 line
package/systemd/systemd.mk +1
-0+SYSTEMD_POST_INSTALL_ENTRIES += var/lib/systemd/timesync/
SYSTEMD_TIMESYNCD_PERMISIONS=/var/lib/systemd/timesyncd 755
systemd-timesync systemd-timesync - - - - -[--SNIP--]
package/systemd/systemd.mk ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) · line 494
Quoted 6 lines
package/systemd/systemd.mk +2
-0@@ -485,18 +490,23 @@ ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) SYSTEMD_CONF_OPTS += -Dfallback-hostname=$(SYSTEMD_FALLBACK_HOSTNAME) endif +define SYSTEMD_INSTALL_ENTRY_HOOK + mkdir -p -m700 $(TARGET_DIR)/var/lib/private$(TARGET_DIR)/var/log/private \
package/systemd/systemd.mk ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),)
Quoted 3 lines
package/systemd/systemd.mk +3
-0+ $(TARGET_DIR)/var/cache/private + mkdir -p -m1777 $(TARGET_DIR)/var/tmp + $(if $(BR2_PACKAGE_SYSTEMD_MACHINED),mkdir -p -m700$(TARGET_DIR)/var/lib/machines)
package/systemd/systemd.mk ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) · line 498
Quoted 1 line
package/systemd/systemd.mk +1
-0+ mkdir -p $(addprefix $(TARGET_DIR)/,var/lib $(filter%/,$(SYSTEMD_POST_INSTALL_ENTRIES)))
package/systemd/systemd.mk ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) · line 499
Quoted 1 line
package/systemd/systemd.mk +1
-0+ touch $(addprefix $(TARGET_DIR)/,etc/machine-id $(filter-out%/,$(SYSTEMD_POST_INSTALL_ENTRIES)))
package/systemd/systemd.mk ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) · line 500
Quoted 1 line
package/systemd/systemd.mk +1
-0+endefThis would thus no longer be needed.
package/systemd/systemd.mk ifneq ($(SYSTEMD_FALLBACK_HOSTNAME),) · line 495
Quoted 8 lines
package/systemd/systemd.mk +0
-3define SYSTEMD_INSTALL_INIT_HOOK ln -fs multi-user.target \ $(TARGET_DIR)/usr/lib/systemd/system/default.target endef -define SYSTEMD_INSTALL_MACHINEID_HOOK - touch $(TARGET_DIR)/etc/machine-id -endefThis could also probably be replaced with a non-conditional entry in the permissions table, see below...
package/systemd/systemd.mk endef · line 546
Quoted 13 lines
package/systemd/systemd.mk +3
-1SYSTEMD_POST_INSTALL_TARGET_HOOKS += \ + SYSTEMD_INSTALL_ENTRY_HOOK \ SYSTEMD_INSTALL_INIT_HOOK \ - SYSTEMD_INSTALL_MACHINEID_HOOK \ SYSTEMD_INSTALL_RESOLVCONF_HOOK define SYSTEMD_INSTALL_IMAGES_CMDS@@ -532,6 +542,10 @@ endef SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_INSTALL_NSSCONFIG_HOOK +define SYSTEMD_PERMISSIONS + $(if $(SYSTEMD_TIMESYNCD_USER),/var/lib/systemd/timesync d 755systemd-timesync systemd-timesync - - - - -)
package/systemd/systemd.mk endef · line 547
Quoted 1 line
package/systemd/systemd.mk +1
-0+endefWe usually do not use conditional in the permissions tables, but define conditional variables that we then re-use (see above):
define SYSTEMD_PERMISSIONS /etc/machine-id f 644 0 0 - - - - - $(SYSTEMD_LOGIND_PERMISIONS) $(SYSTEMD_TIMESYNCD_PERMISIONS) ... endefRegards,
Yann E. MORIN.Quoted 7 lines
package/systemd/systemd.mk +1
-1+ ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),) # systemd provides multiple units to autospawn getty as neede # * getty at .service to start a getty on normal TTY --2.27.0
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |'------------------------------^-------^------------------^--------------------'
Signature · 21 lines
[image: SMILE] <http://www.smile.eu/> 20 rue des Jardins 92600 Asni?res-sur-Seine *J?r?my ROSEN* Architecte technique [image: email] jeremy.rosen at smile.fr [image: phone] +33 6 88 25 87 42 [image: url] http://www.smile.eu [image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook] <https://www.facebook.com/smileopensource> [image: LinkedIn] <https://www.linkedin.com/company/smile> [image: Github] <https://github.com/Smile-SA> [image: D?couvrez l?univers Smile, rendez-vous sur smile.eu] <https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200720/bfed6b85/attachment.html>
PATCH 1/1 package/systemd: pre-create directories for services
Am Mo., 20. Juli 2020 um 10:42 Uhr schrieb J?r?my ROSEN < [email protected]>:
Quoted 6 lines
I am kinda philosophically torn on this one...
According to man:file-hierarchy, /var MUST be writable (it MAY be a tmpfs if the system has no persistent, writable storage)
I'd not confuse the "distribution image" (the thing that buildroot creates) with the running system.
To me, buildroot should do *everything that's possible* up-front.
Quoted 4 lines
This means that daemons can assume that /var will be writable, and we might be starting a wild goose hunt to get them
working in all cases.
Nope, definitely not the aim for buildroot. Personally I would aim at some sort of base system still being accessible, even if /var is read-only (might happen if the block-device has errors).
systemd actively tries to do this, v246 will have some fallbacks do services can start if /var/tmp is read-only (albeit in obviously reduced fashion).
The clean way to have a file go in /var (at least with systemd) is to put
Quoted 3 lines
it in
/usr/share/factory/var/and systemd will copy it to /var on first boot (or every boot if it's a tmpfs)
No, no, no. the factory approach is one of the most fragile I have ever seen., See [1] for a short list of issues,
[2] for a patch with conflicting use.
That's something requiring a "wild goose hunt" to get in shape.
A clean approach is to mount a overlayfs, ideally already in the initramfs, or to separate /usr into a RO image. Both approaches are hindered with the intransparent
logic hidden behind the innocent REMOUNT_ROOTFS_RW option.
The best in-image option would be to either:
- hook /sbin/init
- create a systemd-unit that is run after /var is mounted and before tmpfilesd-create is run.
At one of these points, do either an overlayfs or copying over the contents to a new tmpfs, then bindmounting it to /var.
I'd still do this as a separate option to REMOUNT_ROOTFS_RW, perhaps even as its own package.
this has the added advantage that /var can be empty at install time, can be
Quoted 3 lines
easily reset by reformatting/emptying
without breaking the system.
Thats what tmpfilesd is for, ideally it doesn't require copying over the old contents. Then it works with an empty /var whether you use the rw or ro option in buildroot,
you just might need to add a tmpfs mount there.
I have no idea how factory is handled in sysV.
Quoted 5 lines
If buildroot wants to support read-only /var, it's supporting a "buggy setup" according to various standards including FHS.
And yeah... it's a buggy setup, but it's also a common setup :(
I'd call it a robust setup, if things still work in a reduced fashion. But again I use buildroot as a "distribution image" generator, I do mount an overlayfs over the whole fs in the initramfs,
something that seems official support as you cant mount a .tar file.
Quoted 4 lines
So, I guess it's important to point that out but I don't really know what the correct answer is for buildroot..
For this patch, its just a question if the work (as in maintainance cost) is acceptable to pre-create the directories,
I don't see any downsides, philosophically or pragmatically.
How RO-systems should be supported is another question, but in my opionion a bind-mount script that works
on all init-systems (just maybe hooked-in differently) and doesnt causes a host of side-effects would be alot better than the status quo.
I'll append a small example, how such a bind-mount script (with overlay) would look like.
[1] - http://lists.busybox.net/pipermail/buildroot/2020-July/287016.html
[2] - http://lists.busybox.net/pipermail/buildroot/2020-July/287200.html
ROOTFSDIR=/tmp/rootfs
OVLDIR=/run/ovl
# create a separate filesystem for testing mkdir $ROOTFSDIR mount -t tmpfs tmpfs_root_to $ROOTFSDIR mkdir $ROOTFSDIR/var touch $ROOTFSDIR/var/upperfile mount -o remount,ro $ROOTFSDIR
# real overlay script
mkdir $OVLDIR
mount -t tmpfs tmpfs_root_ovl $OVLDIR
mkdir $OVLDIR/lower $OVLDIR/upper $OVLDIR/work
mount --bind $ROOTFSDIR/var $OVLDIR/lower
mount -t overlay -o lowerdir=$OVLDIR/lower,upperdir=$OVLDIR/upper,workdir=$OVLDIR/workoverlay_var $ROOTFSDIR/var
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200720/0ccdc4e3/attachment.html>