~ubuntu-installer/lupin/hardy

63 by ago
Added mounthost (preliminary) to remount the host device at boot
1
#! /bin/sh
2
# /etc/init.d/mounthost: Remount /host folder read write
3
#
4
# Written by Agostino Russo <agostino.russo@gmail.com> based on checkroot.sh
5
#
6
### BEGIN INIT INFO
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
7
# Provides:        mounthost
8
# Required-Start:    mountdevsubfs
63 by ago
Added mounthost (preliminary) to remount the host device at boot
9
# Required-Stop:
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
10
# Default-Start:    S
63 by ago
Added mounthost (preliminary) to remount the host device at boot
11
# Default-Stop:
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
12
# Short-Description:    Remount /host folder read write.
63 by ago
Added mounthost (preliminary) to remount the host device at boot
13
### END INIT INFO
14
15
PATH=/sbin:/bin
16
. /lib/init/vars.sh
17
18
. /lib/lsb/init-functions
19
20
do_start() {
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
21
    [ "$VERBOSE" = no ] || log_action_begin_msg "Mounting host filesystem read-write"
22
63 by ago
Added mounthost (preliminary) to remount the host device at boot
23
    hosttype=none
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
24
    hostopts=defaults
25
    hostmode=rw
26
    hostcheck=no
93 by Agostino Russo
* Do not assume that mounthost has to always remount rw
27
    host_mountpoint=
28
    host_device=
29
    loop_file=
30
    
63 by ago
Added mounthost (preliminary) to remount the host device at boot
31
    ES=$?
93 by Agostino Russo
* Do not assume that mounthost has to always remount rw
32
    
33
    #Find loopmounted root in fstab
34
    while read DEV MTPT FSTYPE OPTS DUMP PASS JUNK;do
94 by Agostino Russo
* Add ISO 9660 to is_supported_fs function (LP: #206989)
35
        [ -z "${DEV%%#*}" ] || [ ! "$MTPT" = "/" ] && continue
93 by Agostino Russo
* Do not assume that mounthost has to always remount rw
36
        [ "${OPTS#*loop}" = "$OPTS" ] && continue
37
        case "$OPTS" in
38
            ro|ro,*|*,ro|*,ro,*) hostmode=ro;;
39
        esac
40
        host_mountpoint="$DEV"
41
        loop_file="$DEV"
42
        break
43
    done < /etc/fstab
44
    [ "$loop_file" ] || exit 0 
45
    
46
    #Find host device
95 by Evan Dandrea
* Replace use of sed in mounthost and lupin-sysctl with a cleaner loop.
47
	host_device=
48
	while [ -n "$host_mountpoint" ]; do
49
		while read DEV MTPT FSTYPE OPTS REST; do
50
			if [ "$MTPT" = "$host_mountpoint" ]; then
51
				host_device=$DEV
52
				break
53
			fi
54
		done < /proc/mounts
55
		host_mountpoint="${host_mountpoint%/*}"
56
		[ -z "$host_device" ] || break
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
57
    done
93 by Agostino Russo
* Do not assume that mounthost has to always remount rw
58
    
59
    #Remount hostdevice
73 by ago
Applied new host detection algorithm to postinst and mounthost
60
    if [ -n "$host_device" ]; then
61
        if [ "$hostcheck" = yes ]; then
62
            if \
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
63
                ! mount    -n -o remount,ro              "$host_device" /host             \
64
                && ! mount -n -o remount,ro -t dummytype "$host_device" /host 2>/dev/null \
65
                && ! mount -n -o remount,ro            "$host_device"  /host 2>/dev/null
73 by ago
Applied new host detection algorithm to postinst and mounthost
66
            then
67
                log_failure_msg "Cannot check host file system because it is not mounted read-only."
68
                rootcheck=no
63 by ago
Added mounthost (preliminary) to remount the host device at boot
69
            fi
73 by ago
Applied new host detection algorithm to postinst and mounthost
70
            #TBD add fs checking
71
            #skipping since not supported by ntfs-3g
72
        fi
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
73
        mount -n -o remount,$hostopts,$hostmode "$host_device" /host
73 by ago
Applied new host detection algorithm to postinst and mounthost
74
        ES=$?
93 by Agostino Russo
* Do not assume that mounthost has to always remount rw
75
        #make sure that the loopdevice is also set rw/ro
76
        if [ -f "$loop_file" ]; then
77
            loop_device=$(losetup -a | grep "($loop_file)")
78
            loop_device=${loop_device%%:*}
79
            if [ -b "$loop_device" ]; then
80
                blockdev --set$hostmode "$loop_device" || true
81
            fi
82
        fi
73 by ago
Applied new host detection algorithm to postinst and mounthost
83
    fi
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
84
    [ "$VERBOSE" = no ] || log_action_end_msg "$ES"
63 by ago
Added mounthost (preliminary) to remount the host device at boot
85
}
86
87
case "$1" in
88
  start)
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
89
    do_start
90
    ;;
63 by ago
Added mounthost (preliminary) to remount the host device at boot
91
  restart|reload|force-reload)
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
92
    echo "Error: argument '$1' not supported" >&2
93
    exit 3
94
    ;;
63 by ago
Added mounthost (preliminary) to remount the host device at boot
95
  stop)
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
96
    # No-op
97
    ;;
63 by ago
Added mounthost (preliminary) to remount the host device at boot
98
  *)
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
99
    echo "Usage: $0 start|stop" >&2
100
    exit 3
101
    ;;
63 by ago
Added mounthost (preliminary) to remount the host device at boot
102
esac
103
95 by Evan Dandrea
* Replace use of sed in mounthost and lupin-sysctl with a cleaner loop.
104
exit 0