Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | SUMMARY = "Volatile bind mount setup and configuration for read-only-rootfs" |
| 2 | DESCRIPTION = "${SUMMARY}" |
| 3 | LICENSE = "MIT" |
| 4 | LIC_FILES_CHKSUM = "file://COPYING.MIT;md5=5750f3aa4ea2b00c2bf21b2b2a7b714d" |
| 5 | |
| 6 | SRC_URI = "\ |
| 7 | file://mount-copybind \ |
| 8 | file://COPYING.MIT \ |
| 9 | file://volatile-binds.service.in \ |
| 10 | " |
| 11 | |
| 12 | S = "${WORKDIR}" |
| 13 | |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 14 | inherit allarch systemd features_check |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | |
| 16 | REQUIRED_DISTRO_FEATURES = "systemd" |
| 17 | |
| 18 | VOLATILE_BINDS ?= "\ |
| 19 | /var/volatile/lib /var/lib\n\ |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 20 | /var/volatile/cache /var/cache\n\ |
| 21 | /var/volatile/spool /var/spool\n\ |
| 22 | /var/volatile/srv /srv\n\ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | " |
| 24 | VOLATILE_BINDS[type] = "list" |
| 25 | VOLATILE_BINDS[separator] = "\n" |
| 26 | |
| 27 | def 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 Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 36 | SYSTEMD_SERVICE:${PN} = "${@volatile_systemd_services(d)}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 38 | FILES:${PN} += "${systemd_system_unitdir}/*.service ${servicedir}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 40 | # Set to 1 to forcibly skip OverlayFS, and default to copy+bind |
| 41 | AVOID_OVERLAYFS = "0" |
| 42 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | do_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 Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 53 | -e "s#@avoid_overlayfs@#${@d.getVar('AVOID_OVERLAYFS')}#g" \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | volatile-binds.service.in >$servicefile |
| 55 | done <<END |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | ${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | END |
| 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 | } |
| 67 | do_compile[dirs] = "${WORKDIR}" |
| 68 | |
| 69 | do_install () { |
| 70 | install -d ${D}${base_sbindir} |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 71 | install -d ${D}${servicedir} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | install -m 0755 mount-copybind ${D}${base_sbindir}/ |
| 73 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 74 | install -d ${D}${systemd_system_unitdir} |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 75 | for service in ${SYSTEMD_SERVICE:${PN}}; do |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 76 | install -m 0644 $service ${D}${systemd_system_unitdir}/ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | done |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 78 | |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | } |
| 85 | do_install[dirs] = "${WORKDIR}" |