blob: 3fefa9abde904dcfb35fc3d54fc258bf6e39c004 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SUMMARY = "Volatile bind mount setup and configuration for read-only-rootfs"
2DESCRIPTION = "${SUMMARY}"
3LICENSE = "MIT"
4LIC_FILES_CHKSUM = "file://COPYING.MIT;md5=5750f3aa4ea2b00c2bf21b2b2a7b714d"
5
6SRC_URI = "\
7 file://mount-copybind \
8 file://COPYING.MIT \
9 file://volatile-binds.service.in \
10"
11
12S = "${WORKDIR}"
13
Brad Bishop6dbb3162019-11-25 09:41:34 -050014inherit allarch systemd features_check
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015
16REQUIRED_DISTRO_FEATURES = "systemd"
17
18VOLATILE_BINDS ?= "\
19 /var/volatile/lib /var/lib\n\
Brad Bishop37a0e4d2017-12-04 01:01:44 -050020 /var/volatile/cache /var/cache\n\
21 /var/volatile/spool /var/spool\n\
22 /var/volatile/srv /srv\n\
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023"
24VOLATILE_BINDS[type] = "list"
25VOLATILE_BINDS[separator] = "\n"
26
27def volatile_systemd_services(d):
28 services = []
29 for line in oe.data.typed_value("VOLATILE_BINDS", d):
30 if not line:
31 continue
32 what, where = line.split(None, 1)
33 services.append("%s.service" % what[1:].replace("/", "-"))
34 return " ".join(services)
35
Patrick Williams213cb262021-08-07 19:21:33 -050036SYSTEMD_SERVICE:${PN} = "${@volatile_systemd_services(d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
Andrew Geissler5199d832021-09-24 16:47:35 -050038FILES:${PN} += "${systemd_system_unitdir}/*.service ${servicedir}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
Andrew Geissler9aee5002022-03-30 16:27:02 +000040# Set to 1 to forcibly skip OverlayFS, and default to copy+bind
41AVOID_OVERLAYFS = "0"
42
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043do_compile () {
44 while read spec mountpoint; do
45 if [ -z "$spec" ]; then
46 continue
47 fi
48
49 servicefile="${spec#/}"
50 servicefile="$(echo "$servicefile" | tr / -).service"
51 sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \
52 -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \
Andrew Geissler9aee5002022-03-30 16:27:02 +000053 -e "s#@avoid_overlayfs@#${@d.getVar('AVOID_OVERLAYFS')}#g" \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 volatile-binds.service.in >$servicefile
55 done <<END
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057END
58
59 if [ -e var-volatile-lib.service ]; then
60 # As the seed is stored under /var/lib, ensure that this service runs
61 # after the volatile /var/lib is mounted.
62 sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \
63 -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \
64 var-volatile-lib.service
65 fi
66}
67do_compile[dirs] = "${WORKDIR}"
68
69do_install () {
70 install -d ${D}${base_sbindir}
Andrew Geissler6ce62a22020-11-30 19:58:47 -060071 install -d ${D}${servicedir}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072 install -m 0755 mount-copybind ${D}${base_sbindir}/
73
Andrew Geissler5199d832021-09-24 16:47:35 -050074 install -d ${D}${systemd_system_unitdir}
Patrick Williams213cb262021-08-07 19:21:33 -050075 for service in ${SYSTEMD_SERVICE:${PN}}; do
Andrew Geissler5199d832021-09-24 16:47:35 -050076 install -m 0644 $service ${D}${systemd_system_unitdir}/
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 done
Brad Bishop37a0e4d2017-12-04 01:01:44 -050078
79 # Suppress attempts to process some tmpfiles that are not temporary.
80 #
81 install -d ${D}${sysconfdir}/tmpfiles.d ${D}/var/cache
82 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf
83 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084}
85do_install[dirs] = "${WORKDIR}"