diff options
Diffstat (limited to 'meta/recipes-core/volatile-binds')
3 files changed, 56 insertions, 23 deletions
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind index e32e675308..5885880534 100755 --- a/meta/recipes-core/volatile-binds/files/mount-copybind +++ b/meta/recipes-core/volatile-binds/files/mount-copybind | |||
@@ -2,6 +2,9 @@ | |||
2 | # | 2 | # |
3 | # Perform a bind mount, copying existing files as we do so to ensure the | 3 | # Perform a bind mount, copying existing files as we do so to ensure the |
4 | # overlaid path has the necessary content. | 4 | # overlaid path has the necessary content. |
5 | # If the target is a directory and overlayfs is available (and the environment | ||
6 | # variable MOUNT_COPYBIND_AVOID_OVERLAYFS=1 is not set), then an overlay mount | ||
7 | # will be attempted first. | ||
5 | 8 | ||
6 | if [ $# -lt 2 ]; then | 9 | if [ $# -lt 2 ]; then |
7 | echo >&2 "Usage: $0 spec mountpoint [OPTIONS]" | 10 | echo >&2 "Usage: $0 spec mountpoint [OPTIONS]" |
@@ -31,21 +34,42 @@ if [ -d "$mountpoint" ]; then | |||
31 | else | 34 | else |
32 | specdir_existed=no | 35 | specdir_existed=no |
33 | mkdir "$spec" | 36 | mkdir "$spec" |
37 | # If the $spec directory is created we need to take care that | ||
38 | # the selinux context is correct | ||
39 | if command -v selinuxenabled > /dev/null 2>&1; then | ||
40 | if selinuxenabled; then | ||
41 | restorecon "$spec" | ||
42 | fi | ||
43 | fi | ||
34 | fi | 44 | fi |
35 | 45 | ||
36 | # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work | 46 | # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work |
37 | overlay_workdir="${spec%/*}/.${spec##*/}-work" | 47 | overlay_workdir="${spec%/*}/.${spec##*/}-work" |
38 | mkdir "${overlay_workdir}" | 48 | if [ "$MOUNT_COPYBIND_AVOID_OVERLAYFS" != 1 ]; then |
49 | mkdir "${overlay_workdir}" | ||
50 | fi | ||
39 | 51 | ||
40 | # Try to mount using overlay, which is must faster than copying files. | 52 | # Try to mount using overlay, which is much faster than copying files. |
41 | # If that fails, fall back to slower copy. | 53 | # If that fails, fall back to slower copy. |
42 | if ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir" "$mountpoint" > /dev/null 2>&1; then | 54 | if command -v selinuxenabled > /dev/null 2>&1; then |
55 | if selinuxenabled; then | ||
56 | mountcontext=",rootcontext=$(matchpathcon -n "$mountpoint")" | ||
57 | fi | ||
58 | fi | ||
59 | if [ "$MOUNT_COPYBIND_AVOID_OVERLAYFS" = 1 ] || ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir""$mountcontext" "$mountpoint" > /dev/null 2>&1; then | ||
60 | rm -rf "$overlay_workdir" | ||
43 | 61 | ||
44 | if [ "$specdir_existed" != "yes" ]; then | 62 | if [ "$specdir_existed" != "yes" ]; then |
45 | cp -aPR "$mountpoint"/. "$spec/" | 63 | cp -aPR "$mountpoint"/. "$spec/" |
46 | fi | 64 | fi |
47 | 65 | ||
48 | mount -o "bind$options" "$spec" "$mountpoint" | 66 | mount -o "bind$options" "$spec" "$mountpoint" |
67 | # restore the selinux context. | ||
68 | if command -v selinuxenabled > /dev/null 2>&1; then | ||
69 | if selinuxenabled; then | ||
70 | restorecon -R "$mountpoint" | ||
71 | fi | ||
72 | fi | ||
49 | fi | 73 | fi |
50 | elif [ -f "$mountpoint" ]; then | 74 | elif [ -f "$mountpoint" ]; then |
51 | if [ ! -f "$spec" ]; then | 75 | if [ ! -f "$spec" ]; then |
@@ -53,4 +77,10 @@ elif [ -f "$mountpoint" ]; then | |||
53 | fi | 77 | fi |
54 | 78 | ||
55 | mount -o "bind$options" "$spec" "$mountpoint" | 79 | mount -o "bind$options" "$spec" "$mountpoint" |
80 | # restore the selinux context. | ||
81 | if command -v selinuxenabled > /dev/null 2>&1; then | ||
82 | if selinuxenabled; then | ||
83 | restorecon -R "$mountpoint" | ||
84 | fi | ||
85 | fi | ||
56 | fi | 86 | fi |
diff --git a/meta/recipes-core/volatile-binds/files/volatile-binds.service.in b/meta/recipes-core/volatile-binds/files/volatile-binds.service.in index e2ad39f258..5a0055bec3 100644 --- a/meta/recipes-core/volatile-binds/files/volatile-binds.service.in +++ b/meta/recipes-core/volatile-binds/files/volatile-binds.service.in | |||
@@ -1,16 +1,17 @@ | |||
1 | [Unit] | 1 | [Unit] |
2 | Description=Bind mount volatile @where@ | 2 | Description=Bind mount volatile @where@ |
3 | DefaultDependencies=false | 3 | DefaultDependencies=no |
4 | Before=local-fs.target | 4 | Before=local-fs.target |
5 | RequiresMountsFor=@whatparent@ @whereparent@ | 5 | RequiresMountsFor=@whatparent@ @whereparent@ |
6 | ConditionPathIsReadWrite=@whatparent@ | 6 | ConditionPathIsReadWrite=|@whatparent@ |
7 | ConditionPathExists=|!@whatparent@ | ||
7 | ConditionPathExists=@where@ | 8 | ConditionPathExists=@where@ |
8 | ConditionPathIsReadWrite=!@where@ | 9 | ConditionPathIsReadWrite=!@where@ |
9 | 10 | ||
10 | [Service] | 11 | [Service] |
11 | Type=oneshot | 12 | Type=oneshot |
12 | RemainAfterExit=Yes | 13 | RemainAfterExit=Yes |
13 | TimeoutSec=0 | 14 | Environment=MOUNT_COPYBIND_AVOID_OVERLAYFS=@avoid_overlayfs@ |
14 | ExecStart=/sbin/mount-copybind @what@ @where@ | 15 | ExecStart=/sbin/mount-copybind @what@ @where@ |
15 | ExecStop=/bin/umount @where@ | 16 | ExecStop=/bin/umount @where@ |
16 | 17 | ||
diff --git a/meta/recipes-core/volatile-binds/volatile-binds.bb b/meta/recipes-core/volatile-binds/volatile-binds.bb index 3c8b18291e..857bcc93ff 100644 --- a/meta/recipes-core/volatile-binds/volatile-binds.bb +++ b/meta/recipes-core/volatile-binds/volatile-binds.bb | |||
@@ -9,17 +9,17 @@ SRC_URI = "\ | |||
9 | file://volatile-binds.service.in \ | 9 | file://volatile-binds.service.in \ |
10 | " | 10 | " |
11 | 11 | ||
12 | S = "${WORKDIR}" | 12 | S = "${UNPACKDIR}" |
13 | 13 | ||
14 | inherit allarch systemd features_check | 14 | inherit allarch systemd features_check |
15 | 15 | ||
16 | REQUIRED_DISTRO_FEATURES = "systemd" | 16 | REQUIRED_DISTRO_FEATURES = "systemd" |
17 | 17 | ||
18 | VOLATILE_BINDS ?= "\ | 18 | VOLATILE_BINDS ?= "\ |
19 | /var/volatile/lib /var/lib\n\ | 19 | ${localstatedir}/volatile/lib ${localstatedir}/lib\n\ |
20 | /var/volatile/cache /var/cache\n\ | 20 | ${localstatedir}/volatile/cache ${localstatedir}/cache\n\ |
21 | /var/volatile/spool /var/spool\n\ | 21 | ${localstatedir}/volatile/spool ${localstatedir}/spool\n\ |
22 | /var/volatile/srv /srv\n\ | 22 | ${localstatedir}/volatile/srv /srv\n\ |
23 | " | 23 | " |
24 | VOLATILE_BINDS[type] = "list" | 24 | VOLATILE_BINDS[type] = "list" |
25 | VOLATILE_BINDS[separator] = "\n" | 25 | VOLATILE_BINDS[separator] = "\n" |
@@ -33,9 +33,12 @@ def volatile_systemd_services(d): | |||
33 | services.append("%s.service" % what[1:].replace("/", "-")) | 33 | services.append("%s.service" % what[1:].replace("/", "-")) |
34 | return " ".join(services) | 34 | return " ".join(services) |
35 | 35 | ||
36 | SYSTEMD_SERVICE_${PN} = "${@volatile_systemd_services(d)}" | 36 | SYSTEMD_SERVICE:${PN} = "${@volatile_systemd_services(d)}" |
37 | 37 | ||
38 | FILES_${PN} += "${systemd_unitdir}/system/*.service ${servicedir}" | 38 | FILES:${PN} += "${systemd_system_unitdir}/*.service ${servicedir}" |
39 | |||
40 | # Set to 1 to forcibly skip OverlayFS, and default to copy+bind | ||
41 | AVOID_OVERLAYFS = "0" | ||
39 | 42 | ||
40 | do_compile () { | 43 | do_compile () { |
41 | while read spec mountpoint; do | 44 | while read spec mountpoint; do |
@@ -43,39 +46,38 @@ do_compile () { | |||
43 | continue | 46 | continue |
44 | fi | 47 | fi |
45 | 48 | ||
46 | servicefile="${spec#/}" | 49 | servicefile="$(echo "${spec#/}" | tr / -).service" |
47 | servicefile="$(echo "$servicefile" | tr / -).service" | 50 | [ "$mountpoint" != ${localstatedir}/lib ] || var_lib_servicefile=$servicefile |
48 | sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \ | 51 | sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \ |
49 | -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \ | 52 | -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \ |
53 | -e "s#@avoid_overlayfs@#${@d.getVar('AVOID_OVERLAYFS')}#g" \ | ||
50 | volatile-binds.service.in >$servicefile | 54 | volatile-binds.service.in >$servicefile |
51 | done <<END | 55 | done <<END |
52 | ${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")} | 56 | ${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")} |
53 | END | 57 | END |
54 | 58 | ||
55 | if [ -e var-volatile-lib.service ]; then | 59 | if [ -e "$var_lib_servicefile" ]; then |
56 | # As the seed is stored under /var/lib, ensure that this service runs | 60 | # As the seed is stored under /var/lib, ensure that this service runs |
57 | # after the volatile /var/lib is mounted. | 61 | # after the volatile /var/lib is mounted. |
58 | sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \ | 62 | sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \ |
59 | -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \ | 63 | -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \ |
60 | var-volatile-lib.service | 64 | "$var_lib_servicefile" |
61 | fi | 65 | fi |
62 | } | 66 | } |
63 | do_compile[dirs] = "${WORKDIR}" | ||
64 | 67 | ||
65 | do_install () { | 68 | do_install () { |
66 | install -d ${D}${base_sbindir} | 69 | install -d ${D}${base_sbindir} |
67 | install -d ${D}${servicedir} | 70 | install -d ${D}${servicedir} |
68 | install -m 0755 mount-copybind ${D}${base_sbindir}/ | 71 | install -m 0755 mount-copybind ${D}${base_sbindir}/ |
69 | 72 | ||
70 | install -d ${D}${systemd_unitdir}/system | 73 | install -d ${D}${systemd_system_unitdir} |
71 | for service in ${SYSTEMD_SERVICE_${PN}}; do | 74 | for service in ${SYSTEMD_SERVICE:${PN}}; do |
72 | install -m 0644 $service ${D}${systemd_unitdir}/system/ | 75 | install -m 0644 $service ${D}${systemd_system_unitdir}/ |
73 | done | 76 | done |
74 | 77 | ||
75 | # Suppress attempts to process some tmpfiles that are not temporary. | 78 | # Suppress attempts to process some tmpfiles that are not temporary. |
76 | # | 79 | # |
77 | install -d ${D}${sysconfdir}/tmpfiles.d ${D}/var/cache | 80 | install -d ${D}${sysconfdir}/tmpfiles.d ${D}${localstatedir}/cache |
78 | ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf | 81 | ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf |
79 | ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf | 82 | ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf |
80 | } | 83 | } |
81 | do_install[dirs] = "${WORKDIR}" | ||