~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
# NOTE: should /host be in fstab
6
#
7
### BEGIN INIT INFO
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
8
# Provides:        mounthost
9
# Required-Start:    mountdevsubfs
63 by ago
Added mounthost (preliminary) to remount the host device at boot
10
# Required-Stop:
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
11
# Default-Start:    S
63 by ago
Added mounthost (preliminary) to remount the host device at boot
12
# Default-Stop:
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
13
# Short-Description:    Remount /host folder read write.
63 by ago
Added mounthost (preliminary) to remount the host device at boot
14
### END INIT INFO
15
16
PATH=/sbin:/bin
17
. /lib/init/vars.sh
18
19
. /lib/lsb/init-functions
20
21
do_start() {
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
22
    [ "$VERBOSE" = no ] || log_action_begin_msg "Mounting host filesystem read-write"
23
63 by ago
Added mounthost (preliminary) to remount the host device at boot
24
    hosttype=none
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
25
    hostopts=defaults
26
    hostmode=rw
27
    hostcheck=no
28
63 by ago
Added mounthost (preliminary) to remount the host device at boot
29
    ES=$?
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
30
    loopfile_fstab_line=$(sed -n '\:^/[^ ]*[ ]*[ ]/[ ][ ]*[^ ]*[ ].*loop.*[ ]:p' /etc/fstab)
31
    host_mountpoint=${loopfile_fstab_line%% *}
32
    while [ -z "$host_device" ] && [ -n "$host_mountpoint" ] && [ ! "$host_mountpoint" = "/" ]; do
33
        host_mountpoint="${host_mountpoint%/*}"
34
        host_device=$(sed -n "\:^/[^ ]*[ ]*[ ]$host_mountpoint :p" /proc/mounts)
35
        host_device=${host_device%% *}
36
    done
73 by ago
Applied new host detection algorithm to postinst and mounthost
37
    if [ -n "$host_device" ]; then
38
        if [ "$hostcheck" = yes ]; then
39
            if \
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
40
                ! mount    -n -o remount,ro              "$host_device" /host             \
41
                && ! mount -n -o remount,ro -t dummytype "$host_device" /host 2>/dev/null \
42
                && ! mount -n -o remount,ro            "$host_device"  /host 2>/dev/null
73 by ago
Applied new host detection algorithm to postinst and mounthost
43
            then
44
                log_failure_msg "Cannot check host file system because it is not mounted read-only."
45
                rootcheck=no
63 by ago
Added mounthost (preliminary) to remount the host device at boot
46
            fi
73 by ago
Applied new host detection algorithm to postinst and mounthost
47
            #TBD add fs checking
48
            #skipping since not supported by ntfs-3g
49
        fi
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
50
        mount -n -o remount,$hostopts,$hostmode "$host_device" /host
73 by ago
Applied new host detection algorithm to postinst and mounthost
51
        ES=$?
52
    fi
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
53
    [ "$VERBOSE" = no ] || log_action_end_msg "$ES"
63 by ago
Added mounthost (preliminary) to remount the host device at boot
54
}
55
56
case "$1" in
57
  start)
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
58
    do_start
59
    ;;
63 by ago
Added mounthost (preliminary) to remount the host device at boot
60
  restart|reload|force-reload)
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
61
    echo "Error: argument '$1' not supported" >&2
62
    exit 3
63
    ;;
63 by ago
Added mounthost (preliminary) to remount the host device at boot
64
  stop)
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
65
    # No-op
66
    ;;
63 by ago
Added mounthost (preliminary) to remount the host device at boot
67
  *)
91 by Agostino Russo
* Do not use awk in mounthost (LP: #198007)
68
    echo "Usage: $0 start|stop" >&2
69
    exit 3
70
    ;;
63 by ago
Added mounthost (preliminary) to remount the host device at boot
71
esac
72
73
: