]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(multipath): include module with "find_multipaths strict"
authorMartin Wilck <mwilck@suse.com>
Tue, 16 Jul 2024 14:55:03 +0000 (16:55 +0200)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Wed, 17 Jul 2024 19:37:51 +0000 (15:37 -0400)
The previous commits 377d52c and 4957ffa excluded the multipath module in
non-hostonly mode, with the purpose of avoiding to start multipath in the
initramfs on systems that don't use multipath. This is against the idea of
non-hostonly, which is to build an initramfs with all kernel modules and tools
that may be necessary to bring up the system.

This patch takes a different approach. In non-hostonly mode, if there are no
multipath devices and no multipath.conf, include the multipath module, but
require "find_multipaths strict" policy. This will ensure that users that don't
use dm-multipath won't be surprised by finding their root device under
multipath control. But the multipath tools will still be included in the
initramfs, allowing users to set up multipathing e.g. on the emergency shell if
necessary. Also, if /etc/multipath/wwids exists, it will be included in the
initramfs and will cause the WWIDs listed in that file to be multipathed.

Note that in multipath-tools upstream and many Linux distributions,
"find_multipaths strict" is the default anyway. Users of distributions with
different defaults (e.g. openSUSE) would just need to create
/etc/multipath.conf (possibly with empty contents) to override this behavior if
they intend to activate multipath in the initramfs.

Fixes: 377d52c ("fix(multipath): omit module if included with no multipath devices")
Fixes: 4957ffa ("fix(multipath): omit module if included with no multipath devices")
modules.d/90multipath/module-setup.sh

index 0a1fd55806579f7193536d0e43b4ed315ee8d2cc..5fdbb9a77e59c4abad368191c801515561d85203 100755 (executable)
@@ -21,23 +21,14 @@ majmin_to_mpath_dev() {
 
 # called by dracut
 check() {
-    local _any_mpath_dev
-
     # if there's no multipath binary, no go.
     require_binaries multipath || return 1
     require_binaries kpartx || return 1
 
-    for_each_host_dev_and_slaves is_mpath
-    _any_mpath_dev=$?
-
     [[ $hostonly ]] || [[ $mount_needs ]] && {
-        [[ $_any_mpath_dev == 0 ]] || return 255
+        for_each_host_dev_and_slaves is_mpath || return 255
     }
 
-    if [[ $_any_mpath_dev != 0 ]] && [[ ! -f /etc/multipath.conf ]]; then
-        return 255
-    fi
-
     return 0
 }
 
@@ -131,6 +122,19 @@ install() {
         fi
     }
 
+    [[ $hostonly ]] || {
+        for_each_host_dev_and_slaves is_mpath \
+            || [[ -f /etc/multipath.conf ]] || {
+            cat > "${initdir}"/etc/multipath.conf << EOF
+# Minimal multipath.conf generated by dracut
+# Avoid any devices being multipathed by default
+defaults {
+         find_multipaths strict
+}
+EOF
+        }
+    }
+
     inst "$(command -v partx)" /sbin/partx
 
     inst_libdir_file "libmultipath*" "multipath/*"