network: don't use "ifup -m"
[dracut.git] / modules.d / 90mdraid / module-setup.sh
blob621d0fb96cb679a5c79d5622ca8f1b88a5fb3d0c
1 #!/bin/bash
3 # called by dracut
4 check() {
5 local _rootdev
6 # No mdadm? No mdraid support.
7 require_binaries mdadm || return 1
9 [[ $hostonly ]] || [[ $mount_needs ]] && {
10 for dev in "${!host_fs_types[@]}"; do
11 [[ "${host_fs_types[$dev]}" != *_raid_member ]] && continue
13 DEVPATH=$(get_devpath_block "$dev")
15 for holder in "$DEVPATH"/holders/*; do
16 [[ -e "$holder" ]] || continue
17 [[ -e "$holder/md" ]] && return 0
18 break
19 done
21 done
22 return 255
25 return 0
28 # called by dracut
29 depends() {
30 echo rootfs-block
31 return 0
34 # called by dracut
35 installkernel() {
36 instmods =drivers/md
39 # called by dracut
40 cmdline() {
41 local _activated dev line UUID
42 declare -A _activated
44 for dev in "${!host_fs_types[@]}"; do
45 [[ "${host_fs_types[$dev]}" != *_raid_member ]] && continue
47 UUID=$(
48 /sbin/mdadm --examine --export $dev \
49 | while read line || [ -n "$line" ]; do
50 [[ ${line#MD_UUID=} = $line ]] && continue
51 printf "%s" "${line#MD_UUID=} "
52 done
55 [[ -z "$UUID" ]] && continue
57 if ! [[ ${_activated[${UUID}]} ]]; then
58 printf "%s" " rd.md.uuid=${UUID}"
59 _activated["${UUID}"]=1
62 done
65 # called by dracut
66 install() {
67 local rule rule_path
68 inst_multiple cat
69 inst_multiple -o mdmon
70 inst $(command -v partx) /sbin/partx
71 inst $(command -v mdadm) /sbin/mdadm
73 if [[ $hostonly_cmdline == "yes" ]]; then
74 local _raidconf=$(cmdline)
75 [[ $_raidconf ]] && printf "%s\n" "$_raidconf" >> "${initdir}/etc/cmdline.d/90mdraid.conf"
78 # <mdadm-3.3 udev rule
79 inst_rules 64-md-raid.rules
80 # >=mdadm-3.3 udev rules
81 inst_rules 63-md-raid-arrays.rules 64-md-raid-assembly.rules
82 # remove incremental assembly from stock rules, so they don't shadow
83 # 65-md-inc*.rules and its fine-grained controls, or cause other problems
84 # when we explicitly don't want certain components to be incrementally
85 # assembled
86 for rule in 64-md-raid.rules 64-md-raid-assembly.rules; do
87 rule_path="${initdir}${udevdir}/rules.d/${rule}"
88 [ -f "${rule_path}" ] && sed -i -r \
89 -e '/(RUN|IMPORT\{program\})\+?="[[:alpha:]/]*mdadm[[:blank:]]+(--incremental|-I)[[:blank:]]+(--export )?(\$env\{DEVNAME\}|\$tempnode|\$devnode)/d' \
90 "${rule_path}"
91 done
93 inst_rules "$moddir/65-md-incremental-imsm.rules"
95 inst_rules "$moddir/59-persistent-storage-md.rules"
96 prepare_udev_rules 59-persistent-storage-md.rules
98 # guard against pre-3.0 mdadm versions, that can't handle containers
99 if ! mdadm -Q -e imsm /dev/null >/dev/null 2>&1; then
100 inst_hook pre-trigger 30 "$moddir/md-noimsm.sh"
102 if ! mdadm -Q -e ddf /dev/null >/dev/null 2>&1; then
103 inst_hook pre-trigger 30 "$moddir/md-noddf.sh"
106 if [[ $hostonly ]] || [[ $mdadmconf = "yes" ]]; then
107 if [ -f /etc/mdadm.conf ]; then
108 inst -H /etc/mdadm.conf
109 else
110 [ -f /etc/mdadm/mdadm.conf ] && inst -H /etc/mdadm/mdadm.conf /etc/mdadm.conf
112 if [ -d /etc/mdadm.conf.d ]; then
113 local f
114 inst_dir /etc/mdadm.conf.d
115 for f in /etc/mdadm.conf.d/*.conf; do
116 [ -f "$f" ] || continue
117 inst -H "$f"
118 done
122 inst_hook pre-udev 30 "$moddir/mdmon-pre-udev.sh"
123 inst_hook pre-trigger 30 "$moddir/parse-md.sh"
124 inst_hook pre-mount 10 "$moddir/mdraid-waitclean.sh"
125 inst_hook cleanup 99 "$moddir/mdraid-needshutdown.sh"
126 inst_hook shutdown 30 "$moddir/md-shutdown.sh"
127 inst_script "$moddir/mdraid-cleanup.sh" /sbin/mdraid-cleanup
128 inst_script "$moddir/mdraid_start.sh" /sbin/mdraid_start
129 if dracut_module_included "systemd"; then
130 if [ -e $systemdsystemunitdir/mdmon@.service ]; then
131 inst_simple $systemdsystemunitdir/mdmon@.service
134 inst_hook pre-shutdown 30 "$moddir/mdmon-pre-shutdown.sh"