Skip to content
Advertisement

Problem running “Hello World” linux module

I’m trying to compile and run a “Hello World” module from the book “Linux Device Drivers” the program ~/ldd3/hello.c I’m trying to compile is:

/*                                                     
 * $Id: hello.c,v 1.5 2004/10/26 03:32:21 corbet Exp $ 
 */                                                    
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "Hello, worldn");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel worldn");
}

module_init(hello_init);
module_exit(hello_exit);

And the Makefile is:

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

When I run make, the compilation seems ok:

root@deb:/home/deb/ldd3# make
make -C /lib/modules/4.14.86/build M=/home/deb/ldd3 modules
make[1]: Entering directory '/home/deb/src/linux-4.14.86'
  Building modules, stage 2.
  MODPOST 1 modules
make[1]: Leaving directory '/home/deb/src/linux-4.14.86'

But when I run :

root@deb:/home/deb/ldd3# insmod ./hello.ko
root@deb:/home/deb/ldd3#

the “Hello World” message doesnt get printed. Nor do I get a message printed when I run

rmmod hello

Can you tell me why? Thanks

Advertisement

Answer

In order to see kernel messages, you can use dmesg. Alternatively, you can see the syslog tail var/log/syslog.

Advertisement