0

I want to prevent some drivers get put into ramdisk during mkinitramfs. In fedora or arch there is configuration file that I can put something like omit_drivers+=driver-a driver-b to avoid some modules. Then I do not need to rebuild the ramdisk after kernel/driver update.

How can I achieve this in ubuntu? I only find options to add extra modules via initramfs.conf or /etc/initramfs-tools/modules. But how can I blacklist some modules?

To avoid confusion: I do not want to black list the driver, I actually need to load the driver after boot. I just do not want the modules got put in ramdisk.

1 Answer 1

1

There does not appear to be an equivalent setting for this dracut option in initramfs-tools. One approach could be to remove kernel modules using a custom hook script.

Here is a rather simple example where I remove the e1000.ko and e1000e.ko kernel modules from the initramfs.

  1. confirm the modules are present in the initramfs initially.
root@ubuntu:~# lsinitramfs /boot/initrd.img-$(uname -r) | grep e1000
usr/lib/modules/5.15.0-48-generic/kernel/drivers/net/ethernet/intel/e1000
usr/lib/modules/5.15.0-48-generic/kernel/drivers/net/ethernet/intel/e1000/e1000.ko
usr/lib/modules/5.15.0-48-generic/kernel/drivers/net/ethernet/intel/e1000e
usr/lib/modules/5.15.0-48-generic/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko
  1. create a hook script to remove the modules and rebuild the initramfs.
install -m 0755 /dev/null /etc/initramfs-tools/hooks/omit
cat <<'EOF' > /etc/initramfs-tools/hooks/omit
#!/bin/sh
PREREQ=""
prereqs()
{
   echo "$PREREQ"
}

case $1 in
prereqs)
   prereqs
   exit 0
   ;;
esac

. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line

OMIT_DRIVERS="e1000.ko e1000e.ko"
for i in ${OMIT_DRIVERS}; do
   find ${DESTDIR} -name ${i} -delete
done
EOF
update-initramfs -c -k $(uname -r)
  1. confirm the modules are not contained in the rebuilt initramfs.
root@ubuntu:~# lsinitramfs /boot/initrd.img-$(uname -r) | grep e1000
usr/lib/modules/5.15.0-48-generic/kernel/drivers/net/ethernet/intel/e1000
usr/lib/modules/5.15.0-48-generic/kernel/drivers/net/ethernet/intel/e1000e

The hook script could be much more flexible. The contents of my sample are largely based on the examples in man -7 initramfs-tools.

There is a MODULES option in initramfs.conf that could also be useful.

1
  • thanks a lot. In the mean time I found we actually can use dracut in ubuntu.
    – Wang
    Oct 26, 2022 at 19:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .