1From 1fa4d0eb9631771bd751f04ce898433580996e5e Mon Sep 17 00:00:00 2001 2From: Chen Qi <Qi.Chen@windriver.com> 3Date: Thu, 27 Mar 2014 02:34:41 +0000 4Subject: [PATCH] init.d: add support for read-only rootfs 5 6Upstream-Status: Inappropriate [oe specific] 7 8Signed-off-by: Chen Qi <Qi.Chen@windriver.com> 9--- 10 init.d | 40 ++++++++++++++++++++++++++++++++++++++++ 11 1 file changed, 40 insertions(+) 12 13diff --git a/init.d b/init.d 14index 2ef2277..95e8909 100644 15--- a/init.d 16+++ b/init.d 17@@ -6,8 +6,48 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin 18 # Don't modify this line, change or create /etc/default/bind9. 19 OPTIONS="" 20 21+test -f /etc/default/rcS && . /etc/default/rcS 22 test -f /etc/default/bind9 && . /etc/default/bind9 23 24+# This function is here because it's possible that /var and / are on different partitions. 25+is_on_read_only_partition () { 26+ DIRECTORY=$1 27+ dir=`readlink -f $DIRECTORY` 28+ while true; do 29+ if [ ! -d "$dir" ]; then 30+ echo "ERROR: $dir is not a directory" 31+ exit 1 32+ else 33+ for flag in `awk -v dir=$dir '{ if ($2 == dir) { print "FOUND"; split($4,FLAGS,",") } }; \ 34+ END { for (f in FLAGS) print FLAGS[f] }' < /proc/mounts`; do 35+ [ "$flag" = "FOUND" ] && partition="read-write" 36+ [ "$flag" = "ro" ] && { partition="read-only"; break; } 37+ done 38+ if [ "$dir" = "/" -o -n "$partition" ]; then 39+ break 40+ else 41+ dir=`dirname $dir` 42+ fi 43+ fi 44+ done 45+ [ "$partition" = "read-only" ] && echo "yes" || echo "no" 46+} 47+ 48+bind_mount () { 49+ olddir=$1 50+ newdir=$2 51+ mkdir -p $olddir 52+ cp -a $newdir/* $olddir 53+ mount --bind $olddir $newdir 54+} 55+ 56+# Deal with read-only rootfs 57+if [ "$ROOTFS_READ_ONLY" = "yes" ]; then 58+ [ "$VERBOSE" != "no" ] && echo "WARN: start bind service in read-only rootfs" 59+ [ `is_on_read_only_partition /etc/bind` = "yes" ] && bind_mount /var/volatile/bind/etc /etc/bind 60+ [ `is_on_read_only_partition /var/named` = "yes" ] && bind_mount /var/volatile/bind/named /var/named 61+fi 62+ 63 test -x /usr/sbin/rndc || exit 0 64 65 case "$1" in 66