2011-11-26 43 views
4

我正在编译Hello World模块。我在我的系统中有一个新的Ubuntu,它没有任何编译好的内核。如何根据新的源编译内核模块

我的内核是:

2.6.32-34-通用

我给下面的Makefile并得到了错误:

obj-m += hello-1.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 

# make 
make -C /lib/modules/2.6.32-34-generic/build M=/home/james/Desktop/hello modules 
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-34-generic' 
make[2]: *** No rule to make target `/home/james/Desktop/hello/hello-1.c', needed by `/home/james/Desktop/hello/hello-1.o'. Stop. 
make[1]: *** [_module_/home/james/Desktop/hello] Error 2 
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-34-generic' 
make: *** [all] Error 2 

我/lib/modules/2.6的内容.32-34-generic是

total 3864 
lrwxrwxrwx 1 root root  40 2011-11-05 15:55 build -> /usr/src/linux-headers-2.6.32-34-generic 
drwxr-xr-x 2 root root 4096 2011-11-05 15:49 initrd 
drwxr-xr-x 10 root root 4096 2011-11-05 15:49 kernel 
....................................................... 
....................................................... 

存在文件夹/usr/src/linux-headers-2.6.32-34-generic

由于没有工作,我下载了linux-headers-2.6.32-34-generic source from Ubuntu,并编译和改变了我的Makefile文件:

obj-m += hello-1.o 
all: 
    make -C /usr/src/linux-2.6.32/ M=$(PWD) modules 

clean: 
    make -C /usr/src/linux-2.6.32/ M=$(PWD) clean 

#make 
make -C /usr/src/linux-2.6.32/ M=/home/james/Desktop/hello modules 
make[1]: Entering directory `/usr/src/linux-2.6.32' 

    ERROR: Kernel configuration is invalid. 
     include/linux/autoconf.h or include/config/auto.conf are missing. 
     Run 'make oldconfig && make prepare' on kernel src to fix it. 


    WARNING: Symbol version dump /usr/src/linux-2.6.32/Module.symvers 
      is missing; modules will have no dependencies and modversions. 

make[2]: *** No rule to make target `/home/james/Desktop/hello/hello-1.c', needed by `/home/james/Desktop/hello/hello-1.o'. Stop. 
make[1]: *** [_module_/home/james/Desktop/hello] Error 2 
make[1]: Leaving directory `/usr/src/linux-2.6.32' 
make: *** [all] Error 2 

有人能帮助我解决this.http://packages.ubuntu.com/lucid-updates/devel /linux-headers-2.6.32-34-generic

我有一些一般的问题要问。

全新安装后编译内核的最佳方式是什么?在我编译内核并构建了一个模块之后,它的工作完美无缺。但是我不可能知道在这种情况下该怎么做这个

回答

2

make[2]: * No rule to make target /home/james/Desktop/hello/hello-1.c', needed by /home/james/Desktop/hello/hello-1.o'. Stop

你都面临这个错误在第一次编译,因为HELLO-1.C文件在/家庭/詹姆斯/桌面/你好/失踪目录。

1

你需要在Fedora上安装一些类似'kernel-devel'的软件包(对不起,我不是Ubuntu用户),它提供了头文件和.config文件来编译你的内核模块。

0
  1. 检查/ home/james/Desktop/hello /目录中是否存在hello-1.c。
  2. 你需要在你的内核中有modules_enabled。你需要编译一个新的内核来做到这一点。 以下文章解释了如何很好地构建内核。在内核构建的配置中启用模块。

    http://kernelnewbies.org/FAQ/KernelCompilation

0

错误:

ERROR: Kernel configuration is invalid. 
     include/linux/autoconf.h or include/config/auto.conf are missing. 
     Run 'make oldconfig && make prepare' on kernel src to fix it. 


    WARNING: Symbol version dump /usr/src/linux-2.6.32/Module.symvers 
      is missing; modules will have no dependencies and modversions. 

仅仅是因为你的内核源代码是最新下载和之前未编译。

这是你应该如何编译任何内核模块。

下载内核源代码后,您必须准备添加任何模块。

将旧内核的“config-xxxx”文件从/ boot /目录复制到新的内核源目录中,并将其重命名为“.config”。

然后执行“make oldconfig”,该命令会将.config的备份记录到.config.old文件中,并基于新的内核源文件重新生成一个新的.config文件。只需为所有默认设置(大量)输入“ENTER”即可。

接下来是做一个“make”(并等待一段时间) - 它将生成一个新的内核文件“vmlinux”,以及其他许多由模块编译过程读取的文件。

现在你可以去你所在的目录内核模块的源代码的位置,并在下面的Makefile基于:

obj-m += hello-1.o 

default: modules 

modules: 

    make -C /kernel_source/ M=$(PWD) modules 

clean: 
    make -C /kernel_source/ M=$(PWD) clean 

与Makefile文件一起是你的头文件和源文件,这就是hello-1。 c位于一起。

只是“make”,你的内核模块应该成功生成。