我有一台 openvz 机器root
,它是一个虚拟机,我ssh
要:
>uname -a
Linux molo 2.6.32-042stab084.25 #1 SMP Wed Feb 12 16:04:42 MSK 2014 x86_64 x86_64 x86_64 GNU/Linux
我正在尝试构建一个 hello world 内核模块:
你好ç:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}
module_init(hello_start);
module_exit(hello_end);
生成文件:
obj-m = hello.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
当我尝试编译时hello.c
:
#make
make -C /lib/modules/2.6.32-042stab084.25/build M=/local/my_modules modules
make: *** /lib/modules/2.6.32-042stab084.25/build: No such file or directory. Stop.
make: *** [all] Error 2
那是内核版本uname -r
报告
#uname -r
2.6.32-042stab084.25
以下内容也无济于事:
$sudo apt-get install "linux-headers-$(uname -r)"
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-2.6.32-042stab084.25
E: Couldn't find any package by regex 'linux-headers-2.6.32-042stab084.25'
这是/lib/modules
目录:
ls /lib/modules/2.6.32-042stab084.25/
modules.alias modules.ccwmap modules.dep.bin modules.ieee1394map modules.isapnpmap modules.pcimap modules.softdep modules.symbols.bin
modules.alias.bin modules.dep modules.devname modules.inputmap modules.ofmap modules.seriomap modules.symbols modules.usbmap