Skip to contentSkip to conversation

initscripts: add read-only-rootfs-hook.sh script

PATCH In review [email protected] 1 participant 2 messages Jan 29, 2013 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 6/6 initscripts: add read-only-rootfs-hook.sh script

From: Chen Qi <[email protected]>

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]

---
 .../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
meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh new file +19 -0
new file mode 100644
index 0000000..3a295ee
@@ -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
meta/recipes-core/initscripts/initscripts_1.0.bb +3 -0
index 69b9bfb..68f8034 100644
@@ -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"
@@ -85,6 +86,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
 
@@ -116,6 +118,7 @@ do_install () {
 	update-rc.d -r ${D} bootmisc.sh start 55 S .
 	update-rc.d -r ${D} sysfs.sh start 02 S .
 	update-rc.d -r ${D} populate-volatile.sh start 37 S .
+	update-rc.d -r ${D} read-only-rootfs-hook.sh start 41 S .
 	update-rc.d -r ${D} devpts.sh start 38 S .
 	if [ "${TARGET_ARCH}" = "arm" ]; then
 	        update-rc.d -r ${D} alignment.sh start 06 S .
Signature · 1 line
1.7.9.5
author
#2 lore raw

V2 is a rebase against the latest master branch, which solves some conflicts in initscripts_1.0.bb file.

Because only this patch [6/6] had conflicts, I only sent out version 2 of this patch.

Cheers,
Chen Qi

Quoted 68 lines · On 01/29/2013 02:17 PM, [email protected] wrote:

From: Chen Qi <[email protected]>

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]

---
  .../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

meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh new file +19 -0
new file mode 100644
index 0000000..3a295ee
@@ -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
meta/recipes-core/initscripts/initscripts_1.0.bb +3 -0
index 69b9bfb..68f8034 100644
@@ -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"
@@ -85,6 +86,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
 
@@ -116,6 +118,7 @@ do_install () {
  	update-rc.d -r ${D} bootmisc.sh start 55 S .
  	update-rc.d -r ${D} sysfs.sh start 02 S .
  	update-rc.d -r ${D} populate-volatile.sh start 37 S .
+	update-rc.d -r ${D} read-only-rootfs-hook.sh start 41 S .
  	update-rc.d -r ${D} devpts.sh start 38 S .
  	if [ "${TARGET_ARCH}" = "arm" ]; then
  	        update-rc.d -r ${D} alignment.sh start 06 S .