~ubuntu-branches/ubuntu/hardy/mdadm/hardy-updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh

# init-premount script for mdadm.

PREREQS="udev"

prereqs()
{
	echo $PREREQS
}

mountroot_fail()
{
	if ! mdadm --misc --scan --detail >/dev/null 2>&1; then
		cat <<EOF
** WARNING: There appears to be one or more degraded RAID devices **

The system may have suffered a hardware fault, such as a disk drive
failure.  The root device may depend on the RAID devices being online. One
or more of the following RAID devices are degraded:
EOF
		cat /proc/mdstat

		BOOT_DEGRADED="false"
		# Read BOOT_DEGRADED from file
		if [ -r "/conf/conf.d/mdadm" ]; then
			. /conf/conf.d/mdadm
		fi
		# But allow for overides on the kernel command line
		for x in $(cat /proc/cmdline); do
			case $x in
				bootdegraded)
					BOOT_DEGRADED="true"
				;;
				bootdegraded=*)
					BOOT_DEGRADED=${x#bootdegraded=}
				;;
			esac
		done
		# Allow for a couple of permutations, {true|1|yes|on}
		case "$BOOT_DEGRADED" in
			1)    BOOT_DEGRADED="true";;
			yes)  BOOT_DEGRADED="true";;
			on)   BOOT_DEGRADED="true";;
		esac
		# Finally, prompt interactively if the user has not specified
		# to boot degraded either in a configuration file or as a
		# kernel boot parameter
		if [ "$BOOT_DEGRADED" != "true" ]; then
			cat <<EOF
You may attempt to start the system anyway, or stop now and attempt
manual recovery operations.  To do this automatically in the future,
add "bootdegraded=true" to the kernel boot options.

If you choose to start the degraded RAID, the system may boot normally,
but performance may be degraded, and a further hardware fault could
result in permanent data loss.

If you abort now, you will be provided with a recovery shell.

EOF
			# Set a 15-second timeout for this question
			ANSWER="unanswered"
			read -t 15 -p "Do you wish to start the degraded RAID? [y/N]: " -r ANSWER
			case "$ANSWER" in
				unanswered) echo "Timed out" ;;
				y*|Y*)  BOOT_DEGRADED="true" ;;
				*)      BOOT_DEGRADED="false";;
			esac
		fi
		if [ "$BOOT_DEGRADED" = "true" ]; then
			echo "Attempting to start the RAID in degraded mode..."
			if mdadm --assemble --scan --run; then
				echo "Started the RAID in degraded mode."
				exit 0
			else
				echo "Could not start the RAID in degraded mode."
			fi
		fi
	fi
	exit 1
}

case $1 in
# get pre-requisites
prereqs)
	prereqs
	exit 0
	;;
mountfail)
	mountroot_fail
	exit 0
	;;
esac

. /scripts/functions

add_mountroot_fail_hook_d "10-mdadm"

exit 0