summaryrefslogtreecommitdiff
path: root/debian/initramfs/script.local-top
blob: e44cecf608d545a469d260bf11e177e070cd8226 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
#
# Copyright © 2006-2007 Martin F. Krafft <madduck@debian.org>
# based on the scripts in the initramfs-tools package.
# released under the terms of the Artistic Licence.
#
set -eu

PREREQ="udev_helper"

prereqs()
{
  echo "$PREREQ"
}

case ${1:-} in
  prereqs)
    prereqs
    exit 0
    ;;
esac

. /scripts/functions

maybe_break pre-mdadm

if [ -e /scripts/local-top/md ]; then
  log_warning_msg "old md initialisation script found, getting out of its way..."
  exit 1
fi

MDADM=/sbin/mdadm
[ -x "$MDADM" ] || exit 0

verbose()
{
  case "$quiet" in y*|Y*|1|t*|T*)
    return 1;;
  *)
    return 0;;
  esac
}

MD_DEVS=all
MD_MODULES='linear multipath raid0 raid1 raid456 raid5 raid6 raid10'
[ -s /conf/conf.d/md ] && . /conf/conf.d/md

verbose && log_begin_msg Loading MD modules
for module in ${MD_MODULES:-}; do
  if modprobe --syslog "$module"; then
    verbose && log_success_msg "loaded module ${module}."
  else
    log_failure_msg "failed to load module ${module}."
  fi
done
log_end_msg

if [ ! -f /proc/mdstat ]; then
  verbose && panic "cannot initialise MD subsystem (/proc/mdstat missing)"
  exit 1
fi

# handle /dev/md/X nodes
mkdir -p /dev/md

CONFIG=/etc/mdadm/mdadm.conf
# in case the hook failed to install a configuration file, this is our last
# attempt... the "emergency procedure"... <drumroll>
if [ ! -e $CONFIG ]; then
  log_warning_msg "missing mdadm.conf file, trying to create one..."
  mkdir -p ${CONFIG%/*}
  echo DEVICE partitions > $CONFIG
  $MDADM --examine --scan >> $CONFIG
  if [ -s $CONFIG ]; then
    verbose && log_success_msg "mdadm.conf created."
  else
    verbose && log_failure_msg "could not create mdadm.conf, the boot will likely fail."
  fi
  MD_DEVS=all
fi

# prevent writes/syncs so that resuming works (#415441).
echo 1 > /sys/module/md_mod/parameters/start_ro

if [ "$MD_DEVS" = all ]; then

  verbose && log_begin_msg "Assembling all MD arrays"
  extra_args=''
  [ -n "$MD_HOMEHOST" ] && \
    extra_args="--homehost='$MD_HOMEHOST' --auto-update-homehost"
  if $MDADM --assemble --scan --run --auto=yes $extra_args; then
    verbose && log_success_msg "assembled all arrays."
  else
    log_failure_msg "failed to assemble all arrays."
  fi
  verbose && log_end_msg

elif [ "$MD_DEVS" != none ]; then
  for dev in $MD_DEVS; do

    verbose && log_begin_msg "Assembling MD array $dev"
    if $MDADM --assemble --scan --run --auto=yes $dev; then
      verbose && log_success_msg "started $dev"
    else
      log_failure_msg "failed to start $dev"
    fi
    verbose && log_end_msg

  done
fi

maybe_break post-mdadm

case "$ROOT" in
  /dev/disk/by-id/md-*)
    MAXWAIT=10
    if [ ! -L "$ROOT" ]; then
      verbose && log_begin_msg "Waiting for udev array link to $ROOT "
      while [ ! -L "$ROOT" ] && [ $MAXWAIT -gt 0 ]; do
        verbose && echo -n . >&2
        sleep 1
        MAXWAIT=$((MAXWAIT - 1))
      done

      if [ ! -L "$ROOT" ]; then
        verbose && log_failure_msg "timed out after $MAXWAIT seconds."
        exit 1
      else
        verbose && log_success_msg "udev array link to $ROOT appeared."
      fi
    fi
    ;;
esac

exit 0