Ubuntu下直接编译内核的方法

配置系统环境

apt-get install build-essential linux-headers-`uname -r`

编写hellowrold模块

#include 
#include 
#include 

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andrew Klotz");
MODULE_DESCRIPTION("A Simple Hello World Module");

static int hello_init(void)
{
	printk(KERN_ALERT "Hello world\n");
	return 0;
}

static void hello_exit(void)
{
	printk(KERN_ALERT "Goodbye world\n");
}

module_init(hello_init);
module_exit(hello_exit);

编写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

.PHONY: setup
setup:
	apt-get install build-essential linux-headers-`uname -r`

装载后的输出

在这里插入图片描述

你可能感兴趣的:(#,Linux源码学习,ubuntu,linux,kernel,helloworld)