]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
90kernel-modules: don't install any block driver if not needed
authorKairui Song <kasong@redhat.com>
Tue, 29 Oct 2019 08:29:14 +0000 (16:29 +0800)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 17 Jan 2020 06:26:24 +0000 (07:26 +0100)
If hostonly mode is in use, and there isn't any block device included
as hostonly device, then the initramfs won't need any block driver.

Eg. for kdump built image, there could be only one nfs mount point,
or the initramfs may only execute some network operation then reboot.

In such case, skip block driver installation to save space and time.

Signed-off-by: Kairui Song <kasong@redhat.com>
modules.d/90kernel-modules/module-setup.sh

index c376fac35027db1b0a1623de86e650a75c686497..7ae881398e52da4222128503dd5f46c1c3b6f150 100755 (executable)
@@ -2,6 +2,8 @@
 
 # called by dracut
 installkernel() {
+    local _blockfuncs='ahci_platform_get_resources|ata_scsi_ioctl|scsi_add_host|blk_cleanup_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device|usb_stor_disconnect|mmc_add_host|sdhci_add_host|scsi_add_host_with_dma'
+
     find_kernel_modules_external () {
         local _OLDIFS
         local external_pattern="^/"
@@ -16,11 +18,25 @@ installkernel() {
         done < "$srcmods/modules.dep"
         IFS=$_OLDIFS
     }
-    local _blockfuncs='ahci_platform_get_resources|ata_scsi_ioctl|scsi_add_host|blk_cleanup_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device|usb_stor_disconnect|mmc_add_host|sdhci_add_host|scsi_add_host_with_dma'
+
+    is_block_dev() {
+        [ -e /sys/dev/block/$1 ] && return 0
+        return 1
+    }
+
+    install_block_modules () {
+        hostonly='' instmods sr_mod sd_mod scsi_dh ata_piix
+        instmods \
+            scsi_dh_rdac scsi_dh_emc scsi_dh_alua \
+            =ide nvme vmd nfit \
+            virtio_blk
+
+        dracut_instmods -o -s "${_blockfuncs}" "=drivers"
+    }
 
     if [[ -z $drivers ]]; then
         hostonly='' instmods \
-            sr_mod sd_mod scsi_dh ata_piix hid_generic unix \
+            hid_generic unix \
             ehci-hcd ehci-pci ehci-platform \
             ohci-hcd ohci-pci \
             uhci-hcd \
@@ -38,10 +54,10 @@ installkernel() {
             ${NULL}
 
         instmods \
-            yenta_socket scsi_dh_rdac scsi_dh_emc scsi_dh_alua \
+            yenta_socket \
             atkbd i8042 usbhid firewire-ohci pcmcia hv-vmbus \
-            virtio virtio_blk virtio_ring virtio_pci virtio_scsi \
-            "=drivers/pcmcia" =ide nvme vmd nfit
+            virtio virtio_ring virtio_pci virtio_scsi \
+            "=drivers/pcmcia"
 
         if [[ "${DRACUT_ARCH:-$(uname -m)}" == arm* || "${DRACUT_ARCH:-$(uname -m)}" == aarch64 ]]; then
             # arm/aarch64 specific modules
@@ -72,10 +88,12 @@ installkernel() {
                 ${NULL}
         fi
 
-        dracut_instmods -o -s "${_blockfuncs}" "=drivers"
-
         find_kernel_modules_external | instmods
 
+        if ! [[ $hostonly ]] || for_each_host_dev_and_slaves is_block_dev; then
+            install_block_modules
+        fi
+
         # if not on hostonly mode, install all known filesystems,
         # if the required list is not set via the filesystems variable
         if ! [[ $hostonly ]]; then