Patchwork [2/2] read-only-rootfs-hook.sh: check before bind mounting /var/lib

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date Aug. 26, 2013, 6:43 a.m.
Message ID <a2ff16e4b0c0ed3d04f1c6bc50d1b2a498e8020d.1377499381.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/56605/
State Accepted
Commit 86ac10995fd08226f82d87e23fda5d4898c3190f
Headers show

Comments

Qi.Chen@windriver.com - Aug. 26, 2013, 6:43 a.m.
From: Chen Qi <Qi.Chen@windriver.com>

It's possible that /var/lib is on a separate writable partition. In such
situation, we should not bind mount /var/lib with tmpfs, becasue it's
already writable.

This patch fixes this problem by checking whether /var/lib is already
on a writable partition.

[YOCTO #4888]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 .../initscripts-1.0/read-only-rootfs-hook.sh       |   33 +++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)

Patch

diff --git a/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh b/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh
index 9cf0921..1a0328d 100644
--- a/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh
+++ b/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh
@@ -4,10 +4,35 @@ 
 
 [ "$ROOTFS_READ_ONLY" = "no" ] && exit 0
 
+is_on_read_only_partition () {
+	DIRECTORY=$1
+	dir=`readlink -f $DIRECTORY`
+	while true; do
+		if [ ! -d "$dir" ]; then
+			echo "ERROR: $dir is not a directory"
+			exit 1
+		else
+			for flag in `awk -v dir=$dir '{ if ($2 == dir) { print "FOUND"; split($4,FLAGS,",") } }; \
+				END { for (f in FLAGS) print FLAGS[f] }' < /proc/mounts`; do
+				[ "$flag" = "FOUND" ] && partition="read-write"
+				[ "$flag" = "ro" ] && { partition="read-only"; break; }
+			done
+			if [ "$dir" = "/" -o -n "$partition" ]; then
+				break
+			else
+				dir=`dirname $dir`
+			fi
+		fi
+	done
+	[ "$partition" = "read-only" ] && echo "yes" || echo "no"
+}
+
 if [ "$1" = "start" ] ; then
-	grep -q "tmpfs /var/volatile" /proc/mounts || mount /var/volatile
-	mkdir -p /var/volatile/lib
-	cp -a /var/lib/* /var/volatile/lib
-	mount --bind /var/volatile/lib /var/lib
+	if [ `is_on_read_only_partition /var/lib` = "yes" ]; then
+		grep -q "tmpfs /var/volatile" /proc/mounts || mount /var/volatile
+		mkdir -p /var/volatile/lib
+		cp -a /var/lib/* /var/volatile/lib
+		mount --bind /var/volatile/lib /var/lib
+	fi
 fi