0

I can't get why insmod gives Invalid parameters error (can't see anything in dmesg):

$ sudo insmod hello.ko
insmod: ERROR: could not insert module hello.ko: Invalid parameters

$ sudo insmod /hello.ko
insmod: ERROR: could not load module /hello.ko: No such file or directory

I have no parameters in my module. It is just hello world example.

My environment:

$ uname -r
3.16.0-4-amd64

I have installed all possible kernel headers packages:

linux-headers-3.16.0-4-all
linux-headers-3.16.0-4-all-amd64
linux-headers-3.16.0-4-amd64
linux-headers-3.16.0-4-common
linux-headers-amd64 

My code:

#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */

int init_module(void)
{
    printk(KERN_INFO "Hello world 1.\n");
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Goodbye world 1.\n");
}

MODULE_LICENSE("GPL");

I use following Makefile:

obj-m += hello.o

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

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

make output:

$ make

make -C /lib/modules/3.16.0-4-amd64/build M=/home/user/c.driver/driver-1 modules
make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
Makefile:10: *** mixed implicit and normal rules: deprecated syntax
make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'
  CC [M]  /home/user/c.driver/driver-1/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/user/c.driver/driver-1/hello.mod.o
  LD [M]  /home/user/c.driver/driver-1/hello.ko
make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-4-amd64'

Update: same result with 14.04.1-Ubuntu

avasin
  • 9,186
  • 18
  • 80
  • 127
  • 1
    have you tried insmod hello.ko not insmod ./hello.ko ? – Maquefel Jan 25 '16 at 11:28
  • Usually reasons of fails in module loading are explaining in `dmesg` messages. Check it. – Tsyvarev Jan 25 '16 at 12:07
  • @Tsyvarev i know, but there is nothing related to kernel modules. Last one - `Parallels Linux shared folders filesystem driver 1.2.1 loaded`. Can it be caused by Parallels? VM is running under Parallels Desktop. – avasin Jan 25 '16 at 12:09
  • wild guess do you have CONFIG_MODULES=y enabled in kernel ? – Maquefel Jan 25 '16 at 12:21
  • @Maquefel i dont' know, how to look current (stock, working) debian jessie kernel config, but headers file located at `/usr/src/linux-headers-3.16.0-4-amd64/.config` config contains `CONFIG_MODULES=y` – avasin Jan 25 '16 at 12:27
  • 1
    try zcat /proc/config.gz | grep CONFIG_MODULES – Maquefel Jan 25 '16 at 12:28
  • @Maquefel following command worked for me: `cat /boot/config-$(uname -r) | grep CONFIG_MODULES`, it shows `CONFIG_MODULES=y` – avasin Jan 25 '16 at 12:30
  • @Maquefel can this problem be caused by different gcc version used for kernel and module? If so, is it possible to see which gcc was used for kernel compilation? – avasin Jan 25 '16 at 12:33
  • @avasin - nope it is modt likely precompiled kernel problem - what says modinfo hello.ko ? – Maquefel Jan 25 '16 at 12:36
  • @Maquefel seems.. i got it. Problem was that i was using shared folder (editing code on my Mac and compiling it in shared folder on linux). Thanks a lot for you support & help. But.. anyways i can't get why it does not want to deal with shared folders. – avasin Jan 25 '16 at 12:41
  • So the problem has been arised because you **build** the module on shared folders (that is, source files has been located there), or because your module (`hello.ko`) was located on shared folders? What if you copy your module file into linux filesystem after it being built under shared folders? – Tsyvarev Jan 25 '16 at 14:58
  • @Tsyvarev i can compile module in shared folder, copy it to local one and run `insmod`, it works. Problem is with running module from shared folder. – avasin Jan 25 '16 at 16:15
  • @Tsyvarev If i compile module in local folder and then copy it to shared one, i will be unable to run it. – avasin Jan 25 '16 at 16:16

2 Answers2

0

maybe it's because you forget that:

module_init(init_module);                                                           
module_exit(cleanup_module);

and I usually declare init_module() and cleanup_module() as a static function. and fellowing code are my kernel module template:

#include <linux/module.h>
#include <linux/kernel.h>

static int init_module(void)
{
   ... 
   return 0;
}

static void exit_module(void)
{
   ...
}

module_init(init_module);
module_exit(exit_module);
MODULE_LICENSE("GPL");
Refone
  • 1
  • 1
0

For me, the issue was that that module file was in a shared folder (in fact, my Ubuntu box is a VM on Parallels). Copy the module to a local folder and try again.

Thanks to @avasin for this. The answer was in the comments but not quick to find, so adding it here as it may help others. This held me up for a couple of hours.

Dave Kerr
  • 5,117
  • 2
  • 29
  • 31