Patchwork [6/6] initscripts: add read-only-rootfs-hook.sh script

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date Jan. 28, 2013, 9:05 a.m.
Message ID <700967f8822cb1e9810db4625938ade265677863.1359362547.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/43501/
State New
Headers show

Comments

Qi.Chen@windriver.com - Jan. 28, 2013, 9:05 a.m.
From: Chen Qi <Qi.Chen@windriver.com>

Add read-only-rootfs-hook.sh script to support a read-only rootfs.
This script makes a union mount of /var/lib and /var/volatile/lib,
making /var/lib directory writable.

[YOCTO #3406]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 .../initscripts-1.0/read-only-rootfs-hook.sh       |   19 +++++++++++++++++++
 meta/recipes-core/initscripts/initscripts_1.0.bb   |    3 +++
 2 files changed, 22 insertions(+)
 create mode 100644 meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh

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
new file mode 100644
index 0000000..3a295ee
--- /dev/null
+++ b/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh
@@ -0,0 +1,19 @@ 
+#!/bin/sh
+
+. /etc/default/rcS
+
+[ "$ROOTFS_READ_ONLY" = "no" ] && exit 0
+
+# Make sure unionfs is in /proc/filesystems
+if ! grep -q unionfs /proc/filesystems; then
+    echo "ERROR: unionfs not supported by kernel!"
+    exit 1
+fi
+
+mkdir -p /var/volatile/lib
+mount -t unionfs -o dirs=/var/volatile/lib:/var/lib=ro none /var/lib
+
+if [ $? != 0 ]; then
+    echo "ERROR: Union mount failed!"
+    exit 1
+fi
diff --git a/meta/recipes-core/initscripts/initscripts_1.0.bb b/meta/recipes-core/initscripts/initscripts_1.0.bb
index 6e15f88..a8b093b 100644
--- a/meta/recipes-core/initscripts/initscripts_1.0.bb
+++ b/meta/recipes-core/initscripts/initscripts_1.0.bb
@@ -28,6 +28,7 @@  SRC_URI = "file://functions \
            file://sysfs.sh \
            file://device_table.txt \
            file://populate-volatile.sh \
+           file://read-only-rootfs-hook.sh \
            file://volatiles \
            file://save-rtc.sh \
            file://GPLv2.patch"
@@ -82,6 +83,7 @@  do_install () {
 	install -m 0755    ${WORKDIR}/devpts		${D}${sysconfdir}/default
 	install -m 0755    ${WORKDIR}/sysfs.sh		${D}${sysconfdir}/init.d
 	install -m 0755    ${WORKDIR}/populate-volatile.sh ${D}${sysconfdir}/init.d
+	install -m 0755    ${WORKDIR}/read-only-rootfs-hook.sh ${D}${sysconfdir}/init.d
 	install -m 0755    ${WORKDIR}/save-rtc.sh	${D}${sysconfdir}/init.d
 	install -m 0644    ${WORKDIR}/volatiles		${D}${sysconfdir}/default/volatiles/00_core
 	if [ "${TARGET_ARCH}" = "arm" ]; then
@@ -124,6 +126,7 @@  do_install () {
 	ln -sf		../init.d/sysfs.sh	${D}${sysconfdir}/rcS.d/S02sysfs.sh
 	# udev will run at S03 if installed
 	ln -sf		../init.d/populate-volatile.sh	${D}${sysconfdir}/rcS.d/S37populate-volatile.sh
+	ln -sf		../init.d/read-only-rootfs-hook.sh  ${D}${sysconfdir}/rcS.d/S41read-only-rootfs-hook.sh
 	ln -sf		../init.d/devpts.sh	${D}${sysconfdir}/rcS.d/S38devpts.sh
 	if [ "${TARGET_ARCH}" = "arm" ]; then
 		ln -sf	../init.d/alignment.sh	${D}${sysconfdir}/rcS.d/S06alignment.sh