11

I am trying to insert a kernel module using depmod and modprobe utilities in-order to resolve any dependencies. When I build the module it throws "Warning: modules_install: missing 'System.map' file. Skipping depmod."

And later when I try to execute modprobe it throws an error saying "modprobe: FATAL: Module i2c_eeprom_client.ko not found in directory /lib/modules/4.19.58-v7+"

Below is the make file I am using:

obj-m += i2c_eeprom_client.o
KDIR = /lib/modules/$(shell uname -r)/build

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    make -C $(KDIR) M=$(PWD) modules_install

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

And below is the output of build:

make -C /lib/modules/4.19.58-v7+/build M=/home/pi/work/eeprom modules
make[1]: Entering directory '/usr/src/linux-headers-4.19.58-v7+'
  Building modules, stage 2.   
  MODPOST 1 modules
make[1]: Leaving directory '/usr/src/linux-headers-4.19.58-v7+'
make -C /lib/modules/4.19.58-v7+/build M=/home/pi/work/eeprom 
modules_install  
make[1]: Entering directory '/usr/src/linux-headers-4.19.58-v7+'
  INSTALL /home/pi/work/eeprom/i2c_eeprom_client.ko
  DEPMOD  4.19.58-v7+
Warning: modules_install: missing 'System.map' file. Skipping depmod.
make[1]: Leaving directory '/usr/src/linux-headers-4.19.58-v7+'

How can i fix this problem ? Please help

Platform : Raspberry PI 3b+, Raspbian - linux 4.19.58-v7+

user11875340
  • 113
  • 1
  • 1
  • 6
  • As a side note, doing the install step in the same make target as the build step is a bad idea as you typically need root privileges for the install step, but generally don't need them for the build step. – Ian Abbott Aug 16 '19 at 09:02
  • Thanks ! So how can i fix this problem ? I have tried to do it post build and below is the error i have received. make: Entering directory '/usr/src/linux-headers-4.19.58-v7+' cp: cannot stat './modules.order': No such file or directory make: *** [Makefile:1253: _modinst_] Error 1 make: Leaving directory '/usr/src/linux-headers-4.19.58-v7+' – user11875340 Aug 16 '19 at 10:11

1 Answers1

6

You can run depmod after the modules_install step. Also, it is better practice to separate the installation from the building to avoid having to build with root privileges:

obj-m += i2c_eeprom_client.o

# Default to running kernel's build directory if KDIR not set externally
KDIR ?= "/lib/modules/$(shell uname -r)/build"

all:
    $(MAKE) -C "$(KDIR)" M="$(CURDIR)" modules

install:
    $(MAKE) -C "$(KDIR)" M="$(CURDIR)" modules_install
    depmod -A

clean:
    $(MAKE) -C "$(KDIR)" M="$(CURDIR)" clean

Invoke as:

$ make
$ make install
Ian Abbott
  • 15,083
  • 19
  • 33
  • I have no idea what I just did. Can you give me a little more flavor in terms of context of what just happened when I modified my Makefile like so? I created a brand new libvirt VM using Vagrant's generic/ubuntu2204, and modified this make file in the `kmod` project to include `depmod -A` and it worked. https://github.com/orhun/kmon – activedecay Jun 16 '23 at 15:41