dracut-systemd/dracut-initqueue: only start service if really needed
[dracut.git] / modules.d / 90lvm / module-setup.sh
blob42dda5750020ef6aed43c7f78bdb89e71dcd9202
1 #!/bin/bash
3 # called by dracut
4 check() {
5 # No point trying to support lvm if the binaries are missing
6 require_binaries lvm || return 1
8 [[ $hostonly ]] || [[ $mount_needs ]] && {
9 for fs in "${host_fs_types[@]}"; do
10 [[ $fs = LVM*_member ]] && return 0
11 done
12 return 255
15 return 0
18 # called by dracut
19 depends() {
20 # We depend on dm_mod being loaded
21 echo rootfs-block dm
22 return 0
25 # called by dracut
26 cmdline() {
27 local _activated
28 declare -A _activated
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
42 done
45 installkernel() {
46 instmods dm-snapshot
49 # called by dracut
50 install() {
51 local _i
53 inst lvm
55 if [[ $hostonly_cmdline == "yes" ]]; then
56 local _lvmconf=$(cmdline)
57 [[ $_lvmconf ]] && printf "%s\n" "$_lvmconf" >> "${initdir}/etc/cmdline.d/90lvm.conf"
60 inst_rules "$moddir/64-lvm.rules"
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
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
76 eval $(lvm dumpconfig global/system_id_source)
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
83 unset LVM_SUPPRESS_FD_WARNINGS
86 if ! [[ -e ${initdir}/etc/lvm/lvm.conf ]]; then
87 mkdir -p "${initdir}/etc/lvm"
89 echo 'global {'
90 echo 'locking_type = 4'
91 echo 'use_lvmetad = 0'
92 echo '}'
93 } > "${initdir}/etc/lvm/lvm.conf"
96 inst_rules 11-dm-lvm.rules 69-dm-lvm-metad.rules
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
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
117 inst_script "$moddir/lvm_scan.sh" /sbin/lvm_scan
118 inst_hook cmdline 30 "$moddir/parse-lvm.sh"
120 inst_libdir_file "libdevmapper-event-lvm*.so"
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
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
144 dracut_need_initqueue