我是一个能够翻译文本的助手。
我刚开始学习模块化编程。
以上是我的两个文件:
hello.c
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk(KERN_ALERT "TEST: Hello world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "TEST: Good Bye");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile
obj-m += hello.o
KDIR = /usr/src/linux-headers-3.13.0-46-generic
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
这是我的终端输出,显示insmod命令中出现错误,请帮忙。
anubhav@anubhav-Inspiron-3421:~/Desktop/os$ make
make -C /usr/src/linux-headers-3.13.0-46-generic SUBDIRS=/home/anubhav/Desktop/os modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-46-generic'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-46-generic'
anubhav@anubhav-Inspiron-3421:~/Desktop/os$ insmod hello.ko
insmod: ERROR: could not insert module hello.ko: Operation not permitted
root
用户拥有插入/移除内核模块的权限。要么使用su
切换到root
用户,要么使用sudo
(如果适用)以 root 用户身份运行命令。 - lsowensu
中需要使用的密码是root
密码,而不是您的用户密码。 - lsowenprintk(KERN_ALERT "TEST: Good Bye");
是因为你还没有执行rmmod hello
,对吧? - Milind Dumbare