Patchwork [6/9] initscripts: use a uniform way to handle directories in read-only rootfs

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date July 26, 2013, 7:39 a.m.
Message ID <32e18c31ae6edea8ff2fe6ccea04add5006b5978.1374642547.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/54555/
State New
Headers show

Comments

Qi.Chen@windriver.com - July 26, 2013, 7:39 a.m.
From: Chen Qi <Qi.Chen@windriver.com>

Packages in our system may need to write to some directories to function
correctly. In read-only rootfs, these directories should be made writable.

This patch uses a convenient and uniform way to handle such situations.
The read-only-rootfs-hook.sh script searches the /etc/default/readonly
diretory for config files and then apply them one by one.

The config files simply have the following format.
<original diretory> <corresponding directory in volatile story>

For example, /etc/default/readonly/initscripts have the following content.
/var/lib /var/volatile/lib

This patch only has effect for systems with read-only rootfs.

[YOCTO #4103]
[YOCTO #4888]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 .../initscripts-1.0/read-only-rootfs-hook.sh       |   17 ++++++++++++++---
 meta/recipes-core/initscripts/initscripts_1.0.bb   |    5 +++++
 2 files changed, 19 insertions(+), 3 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 d523924..b61f420 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
@@ -1,15 +1,26 @@ 
 #!/bin/sh
 
 . /etc/init.d/functions
+READONLY_CFGDIR="/etc/default/readonly"
 
 ROOTFS_READ_ONLY=`is_rootfs_readonly`
 
 [ "$ROOTFS_READ_ONLY" = "no" ] && exit 0
 
+apply_conf () {
+	cfgfile=$1
+	cat $cfgfile | while read line; do
+		eval `echo "$line" | sed -n "s/\(.*\)\ \(.*\)/DIR_READONLY=\1; DIR_VOLATILE=\2;/p"`
+		mkdir -p $DIR_VOLATILE
+		cp -a $DIR_READONLY/* $DIR_VOLATILE
+		mount --bind $DIR_VOLATILE $DIR_READONLY
+	done
+}
+
 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
+	for file in `ls -1 "$READONLY_CFGDIR"`; do
+		apply_conf "$READONLY_CFGDIR/$file"
+	done
 fi
 
diff --git a/meta/recipes-core/initscripts/initscripts_1.0.bb b/meta/recipes-core/initscripts/initscripts_1.0.bb
index 52e1c9c..46c4c99 100644
--- a/meta/recipes-core/initscripts/initscripts_1.0.bb
+++ b/meta/recipes-core/initscripts/initscripts_1.0.bb
@@ -105,6 +105,11 @@  do_install () {
 	install -m 0755 ${WORKDIR}/umountfs	${D}${sysconfdir}/init.d/umountfs
 	install -m 0755		${WORKDIR}/device_table.txt		${D}${sysconfdir}/device_table
 #
+# Create config files for read-only rootfs
+#
+	install -d ${D}${sysconfdir}/default/readonly
+	echo "/var/lib /var/volatile/lib" > ${D}${sysconfdir}/default/readonly/initscripts
+#
 # Create runlevel links
 #
 	update-rc.d -r ${D} rmnologin.sh start 99 2 3 4 5 .