Skip to content

Commit

Permalink
90kernel-modules: don't install any block driver if not needed
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ryncsn authored and haraldh committed Jan 17, 2020
1 parent cb86c56 commit f4ad2e5
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions modules.d/90kernel-modules/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="^/"
Expand All @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f4ad2e5

Please sign in to comment.