]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/90kernel-modules/module-setup.sh
feat(kernel-modules): exclude USB drivers in strict hostonly mode
[thirdparty/dracut.git] / modules.d / 90kernel-modules / module-setup.sh
1 #!/bin/bash
2
3 # called by dracut
4 installkernel() {
5 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|blk_mq_alloc_disk|blk_cleanup_disk'
6 local -A _hostonly_drvs
7
8 record_block_dev_drv() {
9
10 for _mod in $(get_dev_module /dev/block/"$1"); do
11 _hostonly_drvs["$_mod"]="$_mod"
12 done
13
14 for _mod in $(get_blockdev_drv_through_sys "/sys/dev/block/$1"); do
15 _hostonly_drvs["$_mod"]="$_mod"
16 done
17
18 ((${#_hostonly_drvs[@]} > 0)) && return 0
19 return 1
20 }
21
22 install_block_modules_strict() {
23 hostonly='' instmods "${_hostonly_drvs[@]}"
24 }
25
26 install_block_modules() {
27 instmods \
28 scsi_dh_rdac scsi_dh_emc scsi_dh_alua \
29 =drivers/usb/storage \
30 =ide nvme vmd \
31 virtio_blk virtio_scsi
32
33 dracut_instmods -o -s "${_blockfuncs}" "=drivers"
34 }
35
36 if [[ -z $drivers ]]; then
37 hostonly='' instmods \
38 hid_generic unix
39
40 hostonly=$(optional_hostonly) instmods \
41 ehci-hcd ehci-pci ehci-platform \
42 ohci-hcd ohci-pci \
43 uhci-hcd \
44 usbhid \
45 xhci-hcd xhci-pci xhci-plat-hcd \
46 "=drivers/hid" \
47 "=drivers/tty/serial" \
48 "=drivers/input/serio" \
49 "=drivers/input/keyboard" \
50 "=drivers/pci/host" \
51 "=drivers/pci/controller" \
52 "=drivers/pinctrl" \
53 "=drivers/usb/typec" \
54 "=drivers/watchdog"
55
56 instmods \
57 yenta_socket \
58 atkbd i8042 firewire-ohci pcmcia hv-vmbus \
59 virtio virtio_ring virtio_pci pci_hyperv \
60 "=drivers/pcmcia"
61
62 if [[ ${DRACUT_ARCH:-$(uname -m)} == arm* || ${DRACUT_ARCH:-$(uname -m)} == aarch64 || ${DRACUT_ARCH:-$(uname -m)} == riscv* ]]; then
63 # arm/aarch64 specific modules
64 _blockfuncs+='|dw_mc_probe|dw_mci_pltfm_register|nvme_init_ctrl'
65 instmods \
66 "=drivers/clk" \
67 "=drivers/devfreq" \
68 "=drivers/dma" \
69 "=drivers/extcon" \
70 "=drivers/gpio" \
71 "=drivers/hwmon" \
72 "=drivers/hwspinlock" \
73 "=drivers/i2c/busses" \
74 "=drivers/mailbox" \
75 "=drivers/memory" \
76 "=drivers/mfd" \
77 "=drivers/mmc/core" \
78 "=drivers/mmc/host" \
79 "=drivers/nvmem" \
80 "=drivers/phy" \
81 "=drivers/power" \
82 "=drivers/regulator" \
83 "=drivers/reset" \
84 "=drivers/rpmsg" \
85 "=drivers/rtc" \
86 "=drivers/soc" \
87 "=drivers/spi" \
88 "=drivers/usb/chipidea" \
89 "=drivers/usb/dwc2" \
90 "=drivers/usb/dwc3" \
91 "=drivers/usb/host" \
92 "=drivers/usb/isp1760" \
93 "=drivers/usb/misc" \
94 "=drivers/usb/musb" \
95 "=drivers/usb/phy" \
96 "=drivers/scsi/hisi_sas"
97 fi
98
99 awk -F: '/^\// {print $1}' "$srcmods/modules.dep" 2> /dev/null | instmods
100
101 # if not on hostonly mode, or there are hostonly block device
102 # install block drivers
103 if ! [[ $hostonly ]] \
104 || for_each_host_dev_and_slaves_all record_block_dev_drv; then
105 hostonly='' instmods sg sr_mod sd_mod scsi_dh ata_piix
106
107 if [[ $hostonly_mode == "strict" ]]; then
108 install_block_modules_strict
109 else
110 install_block_modules
111 fi
112 fi
113
114 # if not on hostonly mode, install all known filesystems,
115 # if the required list is not set via the filesystems variable
116 if ! [[ $hostonly ]]; then
117 if [[ -z $filesystems ]]; then
118 dracut_instmods -o -P ".*/(kernel/fs/nfs|kernel/fs/nfsd|kernel/fs/lockd)/.*" '=fs'
119 fi
120 elif [[ "${host_fs_types[*]}" ]]; then
121 hostonly='' instmods "${host_fs_types[@]}"
122 fi
123
124 arch=${DRACUT_ARCH:-$(uname -m)}
125
126 # We don't want to play catch up with hash and encryption algorithms.
127 # To be safe, just use the hammer and include all crypto.
128 [[ $arch == x86_64 ]] && arch=x86
129 [[ $arch == s390x ]] && arch=s390
130 [[ $arch == aarch64 ]] && arch=arm64
131 hostonly='' instmods "=crypto"
132 instmods "=arch/$arch/crypto" "=drivers/crypto"
133 fi
134
135 inst_multiple -o "$depmodd/*.conf"
136 if [[ $hostonly ]]; then
137 inst_multiple -H -o "$depmodconfdir/*.conf"
138 fi
139 :
140 }
141
142 # called by dracut
143 install() {
144 [[ -d /lib/modprobe.d ]] && inst_multiple -o "/lib/modprobe.d/*.conf"
145 [[ -d /usr/lib/modprobe.d ]] && inst_multiple -o "/usr/lib/modprobe.d/*.conf"
146 [[ $hostonly ]] && inst_multiple -H -o /etc/modprobe.d/*.conf /etc/modprobe.conf
147 if ! dracut_module_included "systemd"; then
148 inst_hook cmdline 01 "$moddir/parse-kernel.sh"
149 fi
150 inst_simple "$moddir/insmodpost.sh" /sbin/insmodpost.sh
151 inst_multiple -o sysctl
152 }