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