* [Buildroot] [PATCH] package/skeleton-systemd: systemd-ify /var on a read-only rootfs
@ 2022-07-04 12:24 yann.morin
2022-10-15 21:27 ` Yann E. MORIN
0 siblings, 1 reply; 2+ messages in thread
From: yann.morin @ 2022-07-04 12:24 UTC (permalink / raw)
To: buildroot
Cc: Norbert Lange, Yann E. MORIN, Jérémy Rosen, Romain Naour
From: "Yann E. MORIN" <yann.morin@orange.com>
When the rootfs is not remounted read-write (thus assuming a read-only
rootfs like squashfs), we create a tmpfiles.d factory for /var.
However, we register those in /etc/tmpfiles.d/, but /etc could also be
a tmpfs (for full state-less systems, or easy factory-reset, see [0]).
So, we move our var factory to /usr/lib/tmpfiles.d/, which is also the
lcoation where systemd itself places its own tmpfiles, and where we
already put all our other tmpfiles (see audit, avahi, cryptsetup, dhcp,
lighttpd, nfs-utils, quagga, samba4, swupdate) and our handling of
systemd's catalog files too. We also rename the file to a better name,
so that it is obvious it is generated by us (systemd already installs a
var.conf of its own, so we want to avoid name clashing).
Additionally, since /etc may be empty, we might not have an fstab
available to actually mount /var as a tmpfs. So, we register /var as aa
systemd mount, so that we can also have the /var factory populated and
functional even when /etc is empty. The var.mount unit is heavily
modelled after systemd's own tmp.mount one, so we carry the same license
for that file (in case that may apply). We add an explicit reverse
dependency to systemd-tmpfiles-setup.service, to ensure /var is mounted
before we try to populate it.
Even though we could have split the two changes in two patches, one for
moving the tmpfiles unit away from /etc, and one for adding a systemd
mount unit, the two really make sense together as part of having an
empty /etc, so we made that a single change.
[0] http://0pointer.de/blog/projects/stateless.html
Signed-off-by: Yann E. MORIN <yann.morin@orange.com>
Cc: Norbert Lange <nolange79@gmail.com>
Cc: Romain Naour <romain.naour@smile.fr>
Cc: Jérémy Rosen <jeremy.rosen@smile.fr>
---
.../skeleton-init-systemd.mk | 7 ++++---
package/skeleton-init-systemd/var.mount | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
create mode 100644 package/skeleton-init-systemd/var.mount
diff --git a/package/skeleton-init-systemd/skeleton-init-systemd.mk b/package/skeleton-init-systemd/skeleton-init-systemd.mk
index 795a171809..970951d553 100644
--- a/package/skeleton-init-systemd/skeleton-init-systemd.mk
+++ b/package/skeleton-init-systemd/skeleton-init-systemd.mk
@@ -29,15 +29,14 @@ else
# a real (but empty) directory, and the "factory files" will be copied
# back there by the tmpfiles.d mechanism.
define SKELETON_INIT_SYSTEMD_ROOT_RO_OR_RW
- mkdir -p $(TARGET_DIR)/etc/systemd/tmpfiles.d
echo "/dev/root / auto ro 0 1" >$(TARGET_DIR)/etc/fstab
- echo "tmpfs /var tmpfs mode=1777 0 0" >>$(TARGET_DIR)/etc/fstab
endef
define SKELETON_INIT_SYSTEMD_PRE_ROOTFS_VAR
rm -rf $(TARGET_DIR)/usr/share/factory/var
mv $(TARGET_DIR)/var $(TARGET_DIR)/usr/share/factory/var
mkdir -p $(TARGET_DIR)/var
+ mkdir -p $(TARGET_DIR)/usr/lib/tmpfiles.d
for i in $(TARGET_DIR)/usr/share/factory/var/* \
$(TARGET_DIR)/usr/share/factory/var/lib/* \
$(TARGET_DIR)/usr/share/factory/var/lib/systemd/*; do \
@@ -51,7 +50,9 @@ define SKELETON_INIT_SYSTEMD_PRE_ROOTFS_VAR
printf "C! %s - - - -\n" "$${j}" \
|| exit 1; \
fi; \
- done >$(TARGET_DIR)/etc/tmpfiles.d/var-factory.conf
+ done >$(TARGET_DIR)/usr/lib/tmpfiles.d/buildroot-factory.conf
+ $(INSTALL) -D -m 0644 $(SKELETON_INIT_SYSTEMD_PKGDIR)/var.mount \
+ $(TARGET_DIR)/usr/lib/systemd/system/var.mount
endef
SKELETON_INIT_SYSTEMD_ROOTFS_PRE_CMD_HOOKS += SKELETON_INIT_SYSTEMD_PRE_ROOTFS_VAR
diff --git a/package/skeleton-init-systemd/var.mount b/package/skeleton-init-systemd/var.mount
new file mode 100644
index 0000000000..6b165dff6d
--- /dev/null
+++ b/package/skeleton-init-systemd/var.mount
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Modelled after systemd's tmp.mount
+
+[Unit]
+Description=Buildroot /var tmpfs
+DefaultDependencies=no
+Conflicts=umount.target
+Before=basic.target local-fs.target umount.target systemd-tmpfiles-setup.service
+After=swap.target
+
+[Mount]
+What=tmpfs
+Where=/var
+Type=tmpfs
+Options=mode=1777,strictatime,nosuid,nodev,size=50%%,nr_inodes=1m
+
+[Install]
+WantedBy=basic.target
--
2.25.1
_________________________________________________________________________________________________________________________
Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.
This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Buildroot] [PATCH] package/skeleton-systemd: systemd-ify /var on a read-only rootfs
2022-07-04 12:24 [Buildroot] [PATCH] package/skeleton-systemd: systemd-ify /var on a read-only rootfs yann.morin
@ 2022-10-15 21:27 ` Yann E. MORIN
0 siblings, 0 replies; 2+ messages in thread
From: Yann E. MORIN @ 2022-10-15 21:27 UTC (permalink / raw)
To: yann.morin
Cc: Norbert Lange, Jérémy Rosen, Romain Naour, buildroot
Yann, All,
On 2022-07-04 14:24 +0200, yann.morin@orange.com spake thusly:
> From: "Yann E. MORIN" <yann.morin@orange.com>
[--SNIP--]
> Even though we could have split the two changes in two patches, one for
> moving the tmpfiles unit away from /etc, and one for adding a systemd
> mount unit, the two really make sense together as part of having an
> empty /etc, so we made that a single change.
Yet, you should have known it would been a bit more easier to review the
two as separate changes, so this is eaxactly what I did in that series:
https://lore.kernel.org/buildroot/cover.1665868987.git.yann.morin.1998@free.fr/T/#mea2407e6384ddf35d618c720ed9c6bf8462fcfd2
Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| 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. |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-15 21:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-04 12:24 [Buildroot] [PATCH] package/skeleton-systemd: systemd-ify /var on a read-only rootfs yann.morin
2022-10-15 21:27 ` Yann E. MORIN
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.