summaryrefslogtreecommitdiff
path: root/debian/initramfs/hook
blob: eefe1076e92efd08ca6e8490bb765d06c30ec41f (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
#!/bin/sh -eu
#
# Copyright © 2006 Martin F. Krafft <madduck@debian.org>
# based on the scripts in the initramfs-tools package.
# released under the terms of the Artistic Licence.
#

PREREQ=""

prereqs()
{
	echo "$PREREQ"
}

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

if [ -e /usr/share/initramfs-tools/hooks/md ]; then
  echo "I: mdadm: initramfs md hook still present, I thus won't pop the trunk." >&2
  echo "I: Please see /usr/share/doc/mdadm/README.experimental ." >&2
  exit 0
fi

if [ -e /etc/initramfs-tools/hooks/md ]; then
  echo "W: mdadm: I found /etc/initramfs-tools/hooks/md, which may conflict" >&2
  echo "with this version of mdadm. Please see /usr/share/doc/mdadm/README.mdrun" >&2
  echo "and /usr/share/initramfs-tools/hooks/mdadm for reference and update" >&2
  echo "(or remove) the file." >&2
  exit 0
fi

MDADM=$(command -v mdadm)
[ -x $MDADM ] || exit 0

[ -r /usr/share/initramfs-tools/hook-functions ] || exit 0
. /usr/share/initramfs-tools/hook-functions

INITRDSTART=all
[ -s /etc/default/mdadm ] && . /etc/default/mdadm

DEVS=''; LEVELS=''
if [ "$INITRDSTART" != none ]; then
  eval $(mdadm --examine --scan --config=partitions \
    | while read a dev level num uuid; do

      if [ "$INITRDSTART" = all ] || expr "$INITRDSTART" : ".*${dev}.*" >/dev/null; then
          DEVS="$DEVS ${dev}:${uuid#UUID=}"
          LEVELS="$LEVELS ${level#level=}"
      fi

      echo "DEVS='$DEVS'"
      echo "LEVELS='$LEVELS'"
    done)

  [ "$INITRDSTART" = all ] && DEVS=all
fi

uniquify()
{
  for i in $@; do echo "$i"; done | sort -u
}

if [ -n "$DEVS" ]; then

  touch $DESTDIR/conf/mdadm.conf
  echo "RAID_DEVS='${DEVS## }'" >> $DESTDIR/conf/mdadm.conf

  # 1:1 mapping between level names and modules
  MODULES="$(uniquify $LEVELS | tr '\n' ' ')"
  echo "RAID_MODULES='$MODULES'" >> $DESTDIR/conf/mdadm.conf

  copy_exec $MDADM /sbin

  # copy all modules into the initramfs, just for safety
  MODULES="linear multipath raid0 raid1 raid5 raid6 raid10"
  for mod in $MODULES; do manual_add_modules $mod; done

  # prevent problems with old md script. Since this hook is only called if
  # either this file does not exist or the user chose to try the new stuff,
  # this is safe.
  rm -f $DESTDIR/scripts/local-top/md

  if [ "$DEVS" = all ]; then
    DEVNAMES="all RAID arrays"
  else
    DEVNAMES="$(for i in $DEVS; do echo -n "${i%%:*},"; done)"
    DEVNAMES="${DEVNAMES%,}"
  fi

  echo "I: mdadm: RAID support installed to mount $DEVNAMES during boot." >&2

else
  echo "I: mdadm: no RAID devices selected for initrd initialisation." >&2
  echo "I: mdadm: not including RAID stuff." >&2
fi

echo 'I: mdadm: use `dpkg-reconfigure -plow mdadm` if this is not correct.' >&2

exit 0