I want to explicitly load a module (say, netconsole) during the initrd stage, similarly to /etc/modules in the main system startup procedure.

First, I checked that the initrd in my system already contains the wanted module (see Appendix).

I have looked into /initrd.img (which is a compressed cpio archive, so to have a quick look into it, I have done zcat /initrd.img > initrd.cpio and gone inside it with mc). I have looked for any invocations of modprobe among the scripts, and have figured out that the modules listed in /conf/modules (/ is initrd's root here) get automatically loaded by the load_modules() function from /scripts/functions (called by /init).

But what would be the standard tool in the Ubuntu system to update /conf/modules of the initrd?

(BTW, during my study of the code of the Ubuntu's initrd, I noticed that there is some special support for netconsole in the /init script, which I might make work for my needs, but anyway ,my question is more general, concerning any other custom module.)

Appendix

As I said above: first, I checked that the initrd in my system already contains the wanted module (namely, netconsole). This is how:

# zcat /initrd.img | cpio --extract --verbose --list  | fgrep netconsole
-rw-r--r--   1 root     root        25372 Aug 31 20:59 lib/modules/3.19.0-28-generic/kernel/drivers/net/netconsole.ko
109504 blocks
# 

And also I checked that it already contains the needed network driver:

# ls -ld /sys/class/net/eth0/device/driver
lrwxrwxrwx 1 root root 0 Sep 21 15:34 /sys/class/net/eth0/device/driver -> ../../../../bus/pci/drivers/sky2
# zcat /initrd.img | cpio --extract --verbose --list  | fgrep sky2
-rw-r--r--   1 root     root        92948 Aug 31 20:49 lib/modules/3.19.0-28-generic/kernel/drivers/net/ethernet/marvell/sky2.ko
109504 blocks
# 

I discovered how to add modules to the initrd in Ubuntu 14.04 I added the names of the modules to /etc/initramfs-tools/modules . This added the modules to the initrd file. Do not forget to update the initrd file ( update-initramfs -u ) after you have made changes to /etc/initramfs-tools/modules .


Ubuntu uses initramfs-tools (see man initramfs-tools for an introduction) to handle the creation of initrd.

To add a module netconsole in initrd and force loading it create a file in /etc/initramfs-tools/hooks (i.e. /etc/initramfs-tools/hooks/netconsole) with the contents:

#!/bin/sh
PREREQ=""
prereqs()
{
   echo "$PREREQ"
}

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

. /usr/share/initramfs-tools/hook-functions

force_load netconsole

and make it executable. Then run:

update-initramfs -u

to update the initrd of the newest kernel.