Support 'read-only-rootfs' IMAGE_FEATURES for systemd based systems
v2 cover Support 'read-only-rootfs' IMAGE_FEATURES for systemd based systems
This patchset mainly comes from https://github.com/MentorEmbedded/meta-ro-rootfs with only a little modification.
//Chen Qi
The following changes since commit 3f7fcbc167c13bdaa6c12a81c7851530d72f02e0:
directfb-examples: Fix building with new autoconf (2014-07-27 08:30:13 +0100)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contrib ChenQi/systemd_readonly
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=ChenQi/systemd_readonly
Chen Qi (3):
volatile-binds: add recipe
systemd: add volatile-binds to RDEPENDS
image.bbclass: tweak read_only_rootfs_hook to also support systemd
based systems
meta/classes/image.bbclass | 5 +- meta/recipes-core/systemd/systemd_213.bb | 1 + meta/recipes-core/volatile-binds/files/COPYING.MIT | 17 +++++ .../volatile-binds/files/mount-copybind | 34 ++++++++++ .../volatile-binds/files/volatile-binds.service.in | 19 ++++++ meta/recipes-core/volatile-binds/volatile-binds.bb | 69 ++++++++++++++++++++ 6 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 meta/recipes-core/volatile-binds/files/COPYING.MIT create mode 100755 meta/recipes-core/volatile-binds/files/mount-copybind create mode 100644 meta/recipes-core/volatile-binds/files/volatile-binds.service.in create mode 100644 meta/recipes-core/volatile-binds/volatile-binds.bb
Signature · 1 line
1.7.9.5
PATCH v2 1/3 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.
--- meta/recipes-core/volatile-binds/files/COPYING.MIT | 17 +++++ .../volatile-binds/files/mount-copybind | 34 ++++++++++ .../volatile-binds/files/volatile-binds.service.in | 19 ++++++ meta/recipes-core/volatile-binds/volatile-binds.bb | 69 ++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 meta/recipes-core/volatile-binds/files/COPYING.MIT create mode 100755 meta/recipes-core/volatile-binds/files/mount-copybind create mode 100644 meta/recipes-core/volatile-binds/files/volatile-binds.service.in create mode 100644 meta/recipes-core/volatile-binds/volatile-binds.bb
meta/recipes-core/volatile-binds/files/COPYING.MIT new file +17 -0
@@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR +THE USE OR OTHER DEALINGS IN THE SOFTWARE.
meta/recipes-core/volatile-binds/files/mount-copybind new file +34 -0
@@ -0,0 +1,34 @@ +#!/bin/sh +# +# Perform a bind mount, copying existing files as we do so to ensure the +# overlaid path has the necessary content. + +if [ $# -lt 2 ]; then + echo >&2 "Usage: $0 spec mountpoint [OPTIONS]" + exit 1 +fi + +spec=$1 +mountpoint=$2 + +if [ $# -gt 2 ]; then + options=$3 +else + options= +fi + +[ -n "$options" ] && options=",$options" + +mkdir -p "${spec%/*}" +if [ -d "$mountpoint" ]; then + if [ ! -d "$spec" ]; then + mkdir "$spec" + cp -pPR "$mountpoint"/. "$spec/" + fi +elif [ -f "$mountpoint" ]; then + if [ ! -f "$spec" ]; then + cp -pP "$mountpoint" "$spec" + fi +fi + +mount -o "bind$options" "$spec" "$mountpoint"
meta/recipes-core/volatile-binds/files/volatile-binds.service.in new file +19 -0
@@ -0,0 +1,19 @@ +[Unit] +Description=Bind mount volatile @where@ +DefaultDependencies=false +Before=local-fs.target +RequiresMountsFor=@whatparent@ @whereparent@ +ConditionPathIsReadWrite=@whatparent@ +ConditionPathExists=@where@ +ConditionPathIsReadWrite=!@where@ + +[Service] +Type=oneshot +RemainAfterExit=Yes +StandardOutput=syslog +TimeoutSec=0 +ExecStart=/sbin/mount-copybind @what@ @where@ +ExecStop=/sbin/umount @where@ + +[Install] +WantedBy=local-fs.target
meta/recipes-core/volatile-binds/volatile-binds.bb new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 2/3 systemd: add volatile-binds to RDEPENDS
In reply to Chen QiThis services generated from volatile-binds.bb recipe file only have effect in a read-only filesystem. So if the rootfs is read-write, the related service are not started.
--- meta/recipes-core/systemd/systemd_213.bb | 1 + 1 file changed, 1 insertion(+)
meta/recipes-core/systemd/systemd_213.bb +1 -0
@@ -243,6 +243,7 @@ FILES_${PN}-dbg += "${rootlibdir}/.debug ${systemd_unitdir}/.debug ${systemd_uni FILES_${PN}-dev += "${base_libdir}/security/*.la ${datadir}/dbus-1/interfaces/ ${sysconfdir}/rpm/macros.systemd" RDEPENDS_${PN} += "kmod dbus util-linux-mount udev (= ${EXTENDPKGV})" +RDEPENDS_${PN} += "volatile-binds" RRECOMMENDS_${PN} += "systemd-serialgetty systemd-compat-units udev-hwdb\ util-linux-agetty \
Signature · 1 line
1.7.9.5
PATCH v2 3/3 image.bbclass: tweak read_only_rootfs_hook to also support systemd based systems
In reply to Chen QiModify the read_only_rootfs_hook function to make it also have effect on systemd based systems.
--- meta/classes/image.bbclass | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
meta/classes/image.bbclass +3 -2
@@ -199,9 +199,10 @@ do_rootfs[umask] = "022" # A hook function to support read-only-rootfs IMAGE_FEATURES # Currently, it only supports sysvinit system. read_only_rootfs_hook () { + # Tweak the mount option and fs_passno for rootfs in fstab + sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab + if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then - # Tweak the mount option and fs_passno for rootfs in fstab - sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS
Signature · 1 line
1.7.9.5