summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/volatile-binds
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2014-07-23 09:40:12 (GMT)
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-08-02 08:26:14 (GMT)
commitdb15e2d01c48786326ee13dd09b7f2dd45f53116 (patch)
tree85aaa9c06c70204977ffd5c8624e9a93f6c98849 /meta/recipes-core/volatile-binds
parent3b19f90bdfca520a6e00057cacb103f8a55feac6 (diff)
downloadpoky-db15e2d01c48786326ee13dd09b7f2dd45f53116.tar.gz
volatile-binds: add recipe
This recipe is designed to play a key role in a read-only rootfs of systemd based systems. It generates service files from a template, volatile-binds.service.in and the VOLATILE_BINDS variable. By default, VOLATILE_BINDS takes the value of "/var/volatile/lib /var/lib\n", which leads to the generation of volatile-var-lib.service file. This file doesn't have any effect in a read-write system, as it has "ConditionPathIsReadWrite = !/var/lib" in the [Unit] section. In other words, this file only has effect in a read-only rootfs. (From OE-Core rev: ed7d30dc0cdb6d6c56c50ac7a3440c4ed0ee70d3) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/volatile-binds')
-rw-r--r--meta/recipes-core/volatile-binds/files/COPYING.MIT17
-rwxr-xr-xmeta/recipes-core/volatile-binds/files/mount-copybind34
-rw-r--r--meta/recipes-core/volatile-binds/files/volatile-binds.service.in19
-rw-r--r--meta/recipes-core/volatile-binds/volatile-binds.bb69
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 0000000..7e7d574
--- /dev/null
+++ b/meta/recipes-core/volatile-binds/files/COPYING.MIT
@@ -0,0 +1,17 @@
1Permission is hereby granted, free of charge, to any person obtaining a copy
2of this software and associated documentation files (the "Software"), to deal
3in the Software without restriction, including without limitation the rights
4to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5copies of the Software, and to permit persons to whom the Software is
6furnished to do so, subject to the following conditions:
7
8The above copyright notice and this permission notice shall be included in all
9copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
14SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
17THE 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 0000000..2aeaf84
--- /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
6if [ $# -lt 2 ]; then
7 echo >&2 "Usage: $0 spec mountpoint [OPTIONS]"
8 exit 1
9fi
10
11spec=$1
12mountpoint=$2
13
14if [ $# -gt 2 ]; then
15 options=$3
16else
17 options=
18fi
19
20[ -n "$options" ] && options=",$options"
21
22mkdir -p "${spec%/*}"
23if [ -d "$mountpoint" ]; then
24 if [ ! -d "$spec" ]; then
25 mkdir "$spec"
26 cp -pPR "$mountpoint"/. "$spec/"
27 fi
28elif [ -f "$mountpoint" ]; then
29 if [ ! -f "$spec" ]; then
30 cp -pP "$mountpoint" "$spec"
31 fi
32fi
33
34mount -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 0000000..32be5b4
--- /dev/null
+++ b/meta/recipes-core/volatile-binds/files/volatile-binds.service.in
@@ -0,0 +1,19 @@
1[Unit]
2Description=Bind mount volatile @where@
3DefaultDependencies=false
4Before=local-fs.target
5RequiresMountsFor=@whatparent@ @whereparent@
6ConditionPathIsReadWrite=@whatparent@
7ConditionPathExists=@where@
8ConditionPathIsReadWrite=!@where@
9
10[Service]
11Type=oneshot
12RemainAfterExit=Yes
13StandardOutput=syslog
14TimeoutSec=0
15ExecStart=/sbin/mount-copybind @what@ @where@
16ExecStop=/sbin/umount @where@
17
18[Install]
19WantedBy=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 0000000..4080ff7
--- /dev/null
+++ b/meta/recipes-core/volatile-binds/volatile-binds.bb
@@ -0,0 +1,69 @@
1SUMMARY = "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
12inherit allarch systemd distro_features_check
13
14REQUIRED_DISTRO_FEATURES = "systemd"
15
16VOLATILE_BINDS ?= "\
17 /var/volatile/lib /var/lib\n\
18"
19VOLATILE_BINDS[type] = "list"
20VOLATILE_BINDS[separator] = "\n"
21
22def 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
31SYSTEMD_SERVICE_volatile-binds = "${@volatile_systemd_services(d)}"
32
33FILES_${PN} += "${systemd_unitdir}/system/*.service"
34
35do_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")}
48END
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}
58do_compile[dirs] = "${WORKDIR}"
59
60do_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}
69do_install[dirs] = "${WORKDIR}"