]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/90lvm/module-setup.sh
dracut-install: Add support for compressed kernel modules
[thirdparty/dracut.git] / modules.d / 90lvm / module-setup.sh
1 #!/bin/bash
2
3 # called by dracut
4 check() {
5 # No point trying to support lvm if the binaries are missing
6 require_binaries lvm || return 1
7
8 [[ $hostonly ]] || [[ $mount_needs ]] && {
9 for fs in "${host_fs_types[@]}"; do
10 [[ $fs = LVM*_member ]] && return 0
11 done
12 return 255
13 }
14
15 return 0
16 }
17
18 # called by dracut
19 depends() {
20 # We depend on dm_mod being loaded
21 echo rootfs-block dm
22 return 0
23 }
24
25 # called by dracut
26 cmdline() {
27 local _activated
28 declare -A _activated
29
30 for dev in "${!host_fs_types[@]}"; do
31 [ -e /sys/block/${dev#/dev/}/dm/name ] || continue
32 [ -e /sys/block/${dev#/dev/}/dm/uuid ] || continue
33 uuid=$(</sys/block/${dev#/dev/}/dm/uuid)
34 [[ "${uuid#LVM-}" == "$uuid" ]] && continue
35 dev=$(</sys/block/${dev#/dev/}/dm/name)
36 eval $(dmsetup splitname --nameprefixes --noheadings --rows "$dev" 2>/dev/null)
37 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 1
38 if ! [[ ${_activated[${DM_VG_NAME}/${DM_LV_NAME}]} ]]; then
39 printf " rd.lvm.lv=%s\n" "${DM_VG_NAME}/${DM_LV_NAME} "
40 _activated["${DM_VG_NAME}/${DM_LV_NAME}"]=1
41 fi
42 done
43 }
44
45 installkernel() {
46 hostonly='' instmods dm-snapshot
47 }
48
49 # called by dracut
50 install() {
51 local _i
52
53 inst lvm
54
55 if [[ $hostonly_cmdline == "yes" ]]; then
56 local _lvmconf=$(cmdline)
57 [[ $_lvmconf ]] && printf "%s\n" "$_lvmconf" >> "${initdir}/etc/cmdline.d/90lvm.conf"
58 fi
59
60 inst_rules "$moddir/64-lvm.rules"
61
62 if [[ $hostonly ]] || [[ $lvmconf = "yes" ]]; then
63 if [ -f /etc/lvm/lvm.conf ]; then
64 inst_simple -H /etc/lvm/lvm.conf
65 # FIXME: near-term hack to establish read-only locking;
66 # use command-line lvm.conf editor once it is available
67 sed -i -e 's/\(^[[:space:]]*\)locking_type[[:space:]]*=[[:space:]]*[[:digit:]]/\1locking_type = 4/' ${initdir}/etc/lvm/lvm.conf
68 sed -i -e 's/\(^[[:space:]]*\)use_lvmetad[[:space:]]*=[[:space:]]*[[:digit:]]/\1use_lvmetad = 0/' ${initdir}/etc/lvm/lvm.conf
69 fi
70
71 export LVM_SUPPRESS_FD_WARNINGS=1
72 # Also install any files needed for LVM system id support.
73 if [ -f /etc/lvm/lvmlocal.conf ]; then
74 inst_simple -H /etc/lvm/lvmlocal.conf
75 fi
76 eval $(lvm dumpconfig global/system_id_source &>/dev/null)
77 if [ "$system_id_source" == "file" ]; then
78 eval $(lvm dumpconfig global/system_id_file)
79 if [ -f "$system_id_file" ]; then
80 inst_simple -H $system_id_file
81 fi
82 fi
83 unset LVM_SUPPRESS_FD_WARNINGS
84 fi
85
86 if ! [[ -e ${initdir}/etc/lvm/lvm.conf ]]; then
87 mkdir -p "${initdir}/etc/lvm"
88 {
89 echo 'global {'
90 echo 'locking_type = 4'
91 echo 'use_lvmetad = 0'
92 echo '}'
93 } > "${initdir}/etc/lvm/lvm.conf"
94 fi
95
96 inst_rules 11-dm-lvm.rules 69-dm-lvm-metad.rules
97
98 # Do not run lvmetad update via pvscan in udev rule - lvmetad is not running yet in dracut!
99 if [[ -f ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules ]]; then
100 if grep -q SYSTEMD_WANTS ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules; then
101 sed -i -e 's/^ENV{SYSTEMD_ALIAS}=.*/# No LVM pvscan in dracut - lvmetad is not running yet/' \
102 ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules
103 sed -i -e 's/^ENV{ID_MODEL}=.*//' ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules
104 sed -i -e 's/^ENV{SYSTEMD_WANTS}=.*//' ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules
105 else
106 sed -i -e 's/.*lvm pvscan.*/# No LVM pvscan for in dracut - lvmetad is not running yet/' \
107 ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules
108 fi
109 fi
110
111 # Gentoo ebuild for LVM2 prior to 2.02.63-r1 doesn't install above rules
112 # files, but provides the one below:
113 inst_rules 64-device-mapper.rules
114 # debian udev rules
115 inst_rules 56-lvm.rules 60-persistent-storage-lvm.rules
116
117 inst_script "$moddir/lvm_scan.sh" /sbin/lvm_scan
118 inst_hook cmdline 30 "$moddir/parse-lvm.sh"
119
120 inst_libdir_file "libdevmapper-event-lvm*.so"
121
122 if [[ $hostonly ]] && type -P lvs &>/dev/null; then
123 for dev in "${!host_fs_types[@]}"; do
124 [ -e /sys/block/${dev#/dev/}/dm/name ] || continue
125 dev=$(</sys/block/${dev#/dev/}/dm/name)
126 eval $(dmsetup splitname --nameprefixes --noheadings --rows "$dev" 2>/dev/null)
127 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || continue
128 case "$(lvs --noheadings -o segtype ${DM_VG_NAME} 2>/dev/null)" in
129 *thin*|*cache*|*era*)
130 inst_multiple -o thin_dump thin_restore thin_check thin_repair \
131 cache_dump cache_restore cache_check cache_repair \
132 era_check era_dump era_invalidate era_restore
133 break;;
134 esac
135 done
136 fi
137
138 if ! [[ $hostonly ]]; then
139 inst_multiple -o thin_dump thin_restore thin_check thin_repair \
140 cache_dump cache_restore cache_check cache_repair \
141 era_check era_dump era_invalidate era_restore
142 fi
143
144 dracut_need_initqueue
145 }