14

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
# 
1
  • 4
    For future reference, lsinitramfs included in initramfs-tools does about the same as the zcat /initrd.img .. command illustrated here.
    – timss
    Apr 21, 2016 at 19:47

2 Answers 2

16

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 .

3
  • How do you define module names ? Now I need to add ahci.ko module? So what should be included in that file? Sep 4, 2016 at 5:05
  • @sandundhammika ahci
    – Ken Sharp
    Jul 26, 2018 at 19:38
  • How come my /etc/initramfs-tools/modules file is empty (just comment lines)? I'm using ubuntu 16.04. Hope someone could explain to me what's happened in the past.
    – Chan Kim
    Feb 23, 2021 at 4:58
3

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.

1
  • 1
    But isn't there a simpler way of just appending the module name to /conf/modules? Where should I put it in order for update-initramfs -u to use it? Nov 23, 2015 at 9:38

You must log in to answer this question.

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