更新Linux内核头文件(linux headers)

一般来说,如果不是自己编译kernel,那么更新头文件是比较容易的事情,在Ubuntu/Fedora等操作系统上,可以直接安装相应的linux-headers软件包,下面就演示了在Ubuntu上安装内核头文件的过程。

master@jay-intel:~/workspace/c-study$ uname -r
3.2.0-33-generic
master@jay-intel:~/workspace/c-study$ apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-headers-3.2.0-33-generic is already the newest version.
linux-headers-3.2.0-33-generic set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 331 not upgraded.

然而,如果自己编译Linux kernel并用它启动了系统,然后为了让本地程序基于当前kernel的headers来编译,就需要自己手动更新内核的头文件了。手动更新linux headers的步骤如下:
1. 在Linux kernel目录中,执行“make headers_install”命令,将headers安装到当前目录的usr/include/下面。
2. 将以前的headers备份:包括/usr/include/目录下的asm,asm-generic,linux等目录。
3. 将刚才生成的当前编译内核目录下的usr/include/中的asm,asm-generic,linux等目录复制到/usr/include/目录下即可。
(当然如果还需要更新其他的目录的头文件,也都可以一起复制过去。)

操作演示如下:

[root@jay-linux kvm.git]# make headers_install
  CHK     include/generated/uapi/linux/version.h
  WRAP    arch/x86/include/generated/asm/clkdev.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_x32.h
  SYSTBL  arch/x86/syscalls/../include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/syscalls/../include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/syscalls/../include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/syscalls/../include/generated/asm/syscalls_64.h
  HOSTCC  arch/x86/tools/relocs
  HOSTCC  scripts/unifdef
  INSTALL include/asm-generic (35 files)
  INSTALL include/drm (15 files)
  INSTALL include/linux/byteorder (2 files)
  INSTALL include/linux/caif (2 files)
  INSTALL include/linux/can (5 files)
  INSTALL include/linux/dvb (8 files)
  INSTALL include/linux/hdlc (1 file)
  INSTALL include/linux/hsi (1 file)
  INSTALL include/linux/isdn (1 file)
  <省略部分信息...>
  INSTALL include/asm (64 files)
 
[root@jay-linux include]# pwd
/usr/include
[root@jay-linux include]# mv asm asm_orig
[root@jay-linux include]# mv linux linux_orig
[root@jay-linux include]# mv asm-generic asm-generic_orig
 
[root@jay-linux kvm.git]# pwd
/root/kvm_demo/kvm.git
[root@jay-linux kvm.git]# cp -r usr/include/asm /usr/include/
[root@jay-linux kvm.git]# cp -r usr/include/asm-generic/ /usr/include/
[root@jay-linux kvm.git]# cp -r usr/include/linux /usr/include/

Original article: 更新Linux内核头文件(linux headers)

©2013 笑遍世界. All Rights Reserved.

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页