]> git.ipfire.org Git - thirdparty/dracut.git/blobdiff - modules.d/90btrfs/module-setup.sh
fix(btrfs): do not require module via cmdline when --no-kernel
[thirdparty/dracut.git] / modules.d / 90btrfs / module-setup.sh
index 526d9dd43189d579a755e54594633046095e12de..5d881332053daa19b388565333a4b778653607ff 100755 (executable)
@@ -1,39 +1,60 @@
 #!/bin/bash
-# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
-# ex: ts=8 sw=4 sts=4 et filetype=sh
 
+# called by dracut
 check() {
-    local _rootdev
     # if we don't have btrfs installed on the host system,
     # no point in trying to support it in the initramfs.
-    type -P btrfs >/dev/null || return 1
+    require_binaries btrfs || return 1
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
-        local _found
-        for fs in ${host_fs_types[@]}; do
-            strstr "$fs" "\|btrfs" && _found="1"
+        for fs in "${host_fs_types[@]}"; do
+            [[ $fs == "btrfs" ]] && return 0
         done
-        [[ $_found ]] || return 1
-        unset _found
+        return 255
     }
 
     return 0
 }
 
+# called by dracut
 depends() {
     echo udev-rules
     return 0
 }
 
+# called by dracut
+cmdline() {
+    # Hack for slow machines
+    # see https://github.com/dracutdevs/dracut/issues/658
+    printf " rd.driver.pre=btrfs"
+}
+
+# called by dracut
 installkernel() {
     instmods btrfs
+    printf "%s\n" "$(cmdline)" > "${initdir}/etc/cmdline.d/00-btrfs.conf"
 }
 
+# called by dracut
 install() {
-    inst_rules "$moddir/80-btrfs.rules"
-    inst_script "$moddir/btrfs_finished.sh" /sbin/btrfs_finished
-    inst_script "$moddir/btrfs_timeout.sh" /sbin/btrfs_timeout
-    dracut_install btrfsck
-    inst $(command -v btrfs) /sbin/btrfs
-}
+    if ! inst_rules 64-btrfs.rules; then
+        inst_rules "$moddir/80-btrfs.rules"
+        case "$(btrfs --help)" in
+            *device\ ready*)
+                inst_script "$moddir/btrfs_device_ready.sh" /sbin/btrfs_finished
+                ;;
+            *)
+                inst_script "$moddir/btrfs_finished.sh" /sbin/btrfs_finished
+                ;;
+        esac
+    else
+        inst_rules 64-btrfs-dm.rules
+    fi
 
+    if ! dracut_module_included "systemd"; then
+        inst_hook initqueue/timeout 10 "$moddir/btrfs_timeout.sh"
+    fi
+
+    inst_multiple -o btrfsck btrfs-zero-log
+    inst "$(command -v btrfs)" /sbin/btrfs
+}