1

My teacher gives me a linux kernel vmlinuz-3.17.2 and a rootfs.ext2 which can be loaded to qemu. And he asks me to build a simplest kernel module which prints a hello world as homework.

  • Firstly, I download the kernel source and run make oldconfig
  • Secondly, I make the config to be PREEMPT and without modversions (according to uname -a of vmlinuz running in qemu) , then make prepare
  • Thirdly, I compile the kernel mod and copy hello.ko in rootfs.ext2
  • Finally, In qemu, I run insmod hello.ko which exit without any prompt and echo $? returns 0.

However, I can't see anything in dmesg or /var/log/messages Is there anything wrong? How can I do with this? There is also nothing to be printed when I run rmmod hello.ko successfully.

My log level is 7 4 1 7

I have make my hello.c as follows:

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

static int __init hello_init(void)
{
    pr_info("Hello World");
    return -1; 
// I changed this to -1 deliberately, Because It seems that the code is not executed.
}

static void __exit hello_exit(void)
{
    printk(KERN_ERR "Goodbye, cruel world\n");
}
MODULE_LICENSE("GPL");

module_init(hello_init);
module_exit(hello_exit);
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
VariantF
  • 41
  • 1
  • 5

1 Answers1

2

Buildroot

Buildroot is the easiest way to do it:

Tested on Ubuntu 16.04.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985