diff options
4 files changed, 139 insertions, 0 deletions
diff --git a/meta/recipes-core/volatile-binds/files/COPYING.MIT b/meta/recipes-core/volatile-binds/files/COPYING.MIT new file mode 100644 index 0000000000..7e7d57413d --- /dev/null +++ b/meta/recipes-core/volatile-binds/files/COPYING.MIT | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 2 | of this software and associated documentation files (the "Software"), to deal | ||
| 3 | in the Software without restriction, including without limitation the rights | ||
| 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 5 | copies of the Software, and to permit persons to whom the Software is | ||
| 6 | furnished to do so, subject to the following conditions: | ||
| 7 | |||
| 8 | The above copyright notice and this permission notice shall be included in all | ||
| 9 | copies or substantial portions of the Software. | ||
| 10 | |||
| 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
| 14 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| 15 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| 16 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
| 17 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind new file mode 100755 index 0000000000..2aeaf84ddb --- /dev/null +++ b/meta/recipes-core/volatile-binds/files/mount-copybind | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # Perform a bind mount, copying existing files as we do so to ensure the | ||
| 4 | # overlaid path has the necessary content. | ||
| 5 | |||
| 6 | if [ $# -lt 2 ]; then | ||
| 7 | echo >&2 "Usage: $0 spec mountpoint [OPTIONS]" | ||
| 8 | exit 1 | ||
| 9 | fi | ||
| 10 | |||
| 11 | spec=$1 | ||
| 12 | mountpoint=$2 | ||
| 13 | |||
| 14 | if [ $# -gt 2 ]; then | ||
| 15 | options=$3 | ||
| 16 | else | ||
| 17 | options= | ||
| 18 | fi | ||
| 19 | |||
| 20 | [ -n "$options" ] && options=",$options" | ||
| 21 | |||
| 22 | mkdir -p "${spec%/*}" | ||
| 23 | if [ -d "$mountpoint" ]; then | ||
| 24 | if [ ! -d "$spec" ]; then | ||
| 25 | mkdir "$spec" | ||
| 26 | cp -pPR "$mountpoint"/. "$spec/" | ||
| 27 | fi | ||
| 28 | elif [ -f "$mountpoint" ]; then | ||
| 29 | if [ ! -f "$spec" ]; then | ||
| 30 | cp -pP "$mountpoint" "$spec" | ||
| 31 | fi | ||
| 32 | fi | ||
| 33 | |||
| 34 | mount -o "bind$options" "$spec" "$mountpoint" | ||
diff --git a/meta/recipes-core/volatile-binds/files/volatile-binds.service.in b/meta/recipes-core/volatile-binds/files/volatile-binds.service.in new file mode 100644 index 0000000000..32be5b4425 --- /dev/null +++ b/meta/recipes-core/volatile-binds/files/volatile-binds.service.in | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | [Unit] | ||
| 2 | Description=Bind mount volatile @where@ | ||
| 3 | DefaultDependencies=false | ||
| 4 | Before=local-fs.target | ||
| 5 | RequiresMountsFor=@whatparent@ @whereparent@ | ||
| 6 | ConditionPathIsReadWrite=@whatparent@ | ||
| 7 | ConditionPathExists=@where@ | ||
| 8 | ConditionPathIsReadWrite=!@where@ | ||
| 9 | |||
| 10 | [Service] | ||
| 11 | Type=oneshot | ||
| 12 | RemainAfterExit=Yes | ||
| 13 | StandardOutput=syslog | ||
| 14 | TimeoutSec=0 | ||
| 15 | ExecStart=/sbin/mount-copybind @what@ @where@ | ||
| 16 | ExecStop=/sbin/umount @where@ | ||
| 17 | |||
| 18 | [Install] | ||
| 19 | WantedBy=local-fs.target | ||
diff --git a/meta/recipes-core/volatile-binds/volatile-binds.bb b/meta/recipes-core/volatile-binds/volatile-binds.bb new file mode 100644 index 0000000000..4080ff7ef2 --- /dev/null +++ b/meta/recipes-core/volatile-binds/volatile-binds.bb | |||
| @@ -0,0 +1,69 @@ | |||
| 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 | inherit allarch systemd distro_features_check | ||
| 13 | |||
| 14 | REQUIRED_DISTRO_FEATURES = "systemd" | ||
| 15 | |||
| 16 | VOLATILE_BINDS ?= "\ | ||
| 17 | /var/volatile/lib /var/lib\n\ | ||
| 18 | " | ||
| 19 | VOLATILE_BINDS[type] = "list" | ||
| 20 | VOLATILE_BINDS[separator] = "\n" | ||
| 21 | |||
| 22 | def volatile_systemd_services(d): | ||
| 23 | services = [] | ||
| 24 | for line in oe.data.typed_value("VOLATILE_BINDS", d): | ||
| 25 | if not line: | ||
| 26 | continue | ||
| 27 | what, where = line.split(None, 1) | ||
| 28 | services.append("%s.service" % what[1:].replace("/", "-")) | ||
| 29 | return " ".join(services) | ||
| 30 | |||
| 31 | SYSTEMD_SERVICE_volatile-binds = "${@volatile_systemd_services(d)}" | ||
| 32 | |||
| 33 | FILES_${PN} += "${systemd_unitdir}/system/*.service" | ||
| 34 | |||
| 35 | do_compile () { | ||
| 36 | while read spec mountpoint; do | ||
| 37 | if [ -z "$spec" ]; then | ||
| 38 | continue | ||
| 39 | fi | ||
| 40 | |||
| 41 | servicefile="${spec#/}" | ||
| 42 | servicefile="$(echo "$servicefile" | tr / -).service" | ||
| 43 | sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \ | ||
| 44 | -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \ | ||
| 45 | volatile-binds.service.in >$servicefile | ||
| 46 | done <<END | ||
| 47 | ${@d.getVar('VOLATILE_BINDS', True).replace("\\n", "\n")} | ||
| 48 | END | ||
| 49 | |||
| 50 | if [ -e var-volatile-lib.service ]; then | ||
| 51 | # As the seed is stored under /var/lib, ensure that this service runs | ||
| 52 | # after the volatile /var/lib is mounted. | ||
| 53 | sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \ | ||
| 54 | -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \ | ||
| 55 | var-volatile-lib.service | ||
| 56 | fi | ||
| 57 | } | ||
| 58 | do_compile[dirs] = "${WORKDIR}" | ||
| 59 | |||
| 60 | do_install () { | ||
| 61 | install -d ${D}${base_sbindir} | ||
| 62 | install -m 0755 mount-copybind ${D}${base_sbindir}/ | ||
| 63 | |||
| 64 | install -d ${D}${systemd_unitdir}/system | ||
| 65 | for service in ${SYSTEMD_SERVICE_volatile-binds}; do | ||
| 66 | install -m 0644 $service ${D}${systemd_unitdir}/system/ | ||
| 67 | done | ||
| 68 | } | ||
| 69 | do_install[dirs] = "${WORKDIR}" | ||
