centos7编译linux的内核源码

昨天编译了一个linux 内核源码,遇到一些问题, 今天把我遇到的问题和解决方法分享给大家。希望可以帮助到需要的人。

1)检查是否安装了相应的包(我第一次编译的时候只安装的“Development Tools” 包,”Compatibility Libraries“和”Development and Creative Workstation“没有安装)

[[email protected] yum.repos.d]# yum groups list  #查看包组列表
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done

2)下载源码从https://www.kernel.org/网站下载需要编译的内核。

这里直接使用wget命令进行下载

[[email protected] yum.repos.d]# cd /root  #切换到root目录
[[email protected] ~]# wget https://cdn.kernel.org/pub/linux/kernel/v4.x/testing/linux-4.7-rc7.tar.xz  //使用wget下载文件
--2016-07-11 09:59:34--  https://cdn.kernel.org/pub/linux/kernel/v4.x/testing/linux-4.7-rc7.tar.xz
Resolving cdn.kernel.org (cdn.kernel.org)... 151.101.88.69
Connecting to cdn.kernel.org (cdn.kernel.org)|151.101.88.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 90401360 (86M) [application/x-xz]
Saving to: ‘linux-4.7-rc7.tar.xz’

100%[===================================================================================>] 90,401,360   392KB/s   in 6m 35s 

2016-07-11 10:06:10 (223 KB/s) - ‘linux-4.7-rc7.tar.xz’ saved [90401360/90401360]

[[email protected] ~]# ls -l | grep linux    #查看下载的文件
-rw-r--r--. 1 root root 90401360 Jul 10 23:41 linux-4.7-rc7.tar.xz

3)解压文件和创建符号链接文件

tar -xf linux-4.7-rc7.tar.xz  -C /usr/src/  #解压缩到指定目录
[[email protected] ~]# ls
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Music     Public     Videos
Desktop          Downloads  linux-4.7-rc7.tar.xz  Pictures  Templates
[[email protected] ~]# cd /usr/src/  #进入文件目录
[[email protected] src]# ls
debug  kernels  linux-4.7-rc7
[[email protected] src]# ln -sv linux-4.7-rc7/ linux  #创建符号链接
‘linux’ -> ‘linux-4.7-rc7/’
[[email protected] src]# ls      #查看
debug  kernels  linux  linux-4.7-rc7

4)创建.config文件

[[email protected] linux]# ls
arch   COPYING  Documentation  fs       ipc      kernel  MAINTAINERS  net             samples   sound  virt
block  CREDITS  drivers        include  Kbuild   lib     Makefile     README          scripts   tools
certs  crypto   firmware       init     Kconfig  linux   mm           REPORTING-BUGS  security  usr
[[email protected] linux]# make menuconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/mconf.o
In file included from scripts/kconfig/mconf.c:23:0:
scripts/kconfig/lxdialog/dialog.h:38:20: fatal error: curses.h: No such file or directory
 #include CURSES_LOC
                    ^
compilation terminated.
make[1]: *** [scripts/kconfig/mconf.o] Error 1
make: *** [menuconfig] Error 2

这里报错误了。 提示curses.h 这个文件找不到。

[[email protected] linux]# yum search curses    #从yum源查找curses相关的包 , 配置本地yum源看我上篇博客。
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
==================================================== N/S matched: curses ====================================================
ncurses.x86_64 : Ncurses support utilities
ncurses-devel.i686 : Development files for the ncurses library
ncurses-devel.x86_64 : Development files for the ncurses library
ncurses-libs.i686 : Ncurses libraries
ncurses-libs.x86_64 : Ncurses libraries
ncurses-static.i686 : Static libraries for the ncurses library
ncurses-static.x86_64 : Static libraries for the ncurses library
ocaml-curses.x86_64 : OCaml bindings for ncurses
ocaml-curses-devel.x86_64 : Development files for ocaml-curses
NetworkManager-tui.x86_64 : NetworkManager curses-based UI
ncurses-base.noarch : Descriptions of common terminals
ncurses-term.noarch : Terminal descriptions

  Name and summary matches only, use "search all" for everything.
[[email protected] linux]# yum install ncurses    #安装ncurses
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package ncurses-5.9-13.20130511.el7.x86_64 already installed and latest version
Nothing to do
[[email protected] linux]# yum install ncurses-devel  #安装ncurses-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ncurses-devel.x86_64 0:5.9-13.20130511.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                       Arch                   Version                               Repository                  Size
=============================================================================================================================
Installing:
 ncurses-devel                 x86_64                 5.9-13.20130511.el7                   localcdrom                 713 k

Transaction Summary
=============================================================================================================================
Install  1 Package

Total download size: 713 k
Installed size: 2.1 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ncurses-devel-5.9-13.20130511.el7.x86_64                                                                  1/1
  Verifying  : ncurses-devel-5.9-13.20130511.el7.x86_64                                                                  1/1 

Installed:
  ncurses-devel.x86_64 0:5.9-13.20130511.el7                                                                                 

Complete!

再次make menuconfig这个命令后,会出现如下的字符界面,我们就可以在这个界面上对内核进行配置。我们这里是第二次使用make menuconfig了,需要先运行:make mrproper来清除以前的配置,回到默认配置,然后再运行:make menuconfig生成.config文件 通过这个工具可以设置内核配置参数。

4)执行make 命令

[[email protected] linux]# make
  HOSTCC  scripts/kconfig/conf.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --silentoldconfig Kconfig
  SYSTBL  arch/x86/entry/syscalls/../../include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/entry/syscalls/../../include/generated/asm/syscalls_64.h
  HYPERCALLS arch/x86/entry/syscalls/../../include/generated/asm/xen-hypercalls.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/entry/syscalls/../../include/generated/uapi/asm/unistd_x32.h
  HOSTCC  scripts/basic/bin2c
  HOSTCC  arch/x86/tools/relocs_32.o
  HOSTCC  arch/x86/tools/relocs_64.o
  HOSTCC  arch/x86/tools/relocs_common.o
  HOSTLD  arch/x86/tools/relocs
  CHK     include/config/kernel.release
  UPD     include/config/kernel.release
  WRAP    arch/x86/include/generated/asm/clkdev.h
  WRAP    arch/x86/include/generated/asm/cputime.h
  WRAP    arch/x86/include/generated/asm/dma-contiguous.h
  WRAP    arch/x86/include/generated/asm/early_ioremap.h
  WRAP    arch/x86/include/generated/asm/mcs_spinlock.h
  WRAP    arch/x86/include/generated/asm/mm-arch-hooks.h
  CHK     include/generated/uapi/linux/version.h
  UPD     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  CC      arch/x86/purgatory/purgatory.o
  AS      arch/x86/purgatory/stack.o
  AS      arch/x86/purgatory/setup-x86_64.o
  CC      arch/x86/purgatory/sha256.o
  AS      arch/x86/purgatory/entry64.o
  CC      arch/x86/purgatory/string.o
  LD      arch/x86/purgatory/purgatory.ro
  BIN2C   arch/x86/purgatory/kexec-purgatory.c
  CC      kernel/bounds.s
  CHK     include/generated/bounds.h
  UPD     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  UPD     include/generated/timeconst.h
  CC      arch/x86/kernel/asm-offsets.s
  CHK     include/generated/asm-offsets.h
  UPD     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  HOSTCC  scripts/genksyms/genksyms.o
  SHIPPED scripts/genksyms/parse.tab.c
  HOSTCC  scripts/genksyms/parse.tab.o
  SHIPPED scripts/genksyms/lex.lex.c
  SHIPPED scripts/genksyms/keywords.hash.c
  SHIPPED scripts/genksyms/parse.tab.h
  HOSTCC  scripts/genksyms/lex.lex.o
  HOSTLD  scripts/genksyms/genksyms
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/modpost.o
  CC      scripts/mod/devicetable-offsets.s
  GEN     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/selinux/genheaders/genheaders
  HOSTCC  scripts/selinux/mdp/mdp
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/recordmcount
  HOSTCC  scripts/sortextable
  HOSTCC  scripts/asn1_compiler
  HOSTCC  scripts/sign-file
scripts/sign-file.c:25:30: fatal error: openssl/opensslv.h: No such file or directory
 #include <openssl/opensslv.h>
                              ^

上面的报错了, 才发现原来的编译环境的包没有安装好。

执行下面命令安装包

[[email protected] linux]# yum groups list
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
[[email protected] linux]#yum groups  install  "Development and Creative Workstation" "Compatibility Libraries" -y

5)执行 make clean 和make

[[email protected] linux]# make clean
  CLEAN   .
  CLEAN   arch/x86/purgatory
  CLEAN   arch/x86/tools
  CLEAN   .tmp_versions
[[email protected] linux]# make 

6) 执行 make modules_install

7) 执行make install

[[email protected] linux]# make modules_install
[[email protected] linux]# make install 

8)重新电脑选择新编译好的linux吧。

时间: 2024-11-05 06:05:37

centos7编译linux的内核源码的相关文章

Linux Hugetlbfs内核源码简析-----(一)Hugetlbfs初始化

一.引言 为了实现虚拟内存管理机制,操作系统对内存实行分页管理.自内存“分页机制”提出之始,内存页面的默认大小便被设置为 4096 字节(4KB),虽然原则上内存页面大小是可配置的,但绝大多数的操作系统实现中仍然采用默认的 4KB 页面.当某些应用的需要使用的内存达到几G.甚至几十G的时候,4KB的内存页面将严重制约程序的性能. CPU缓存中有一组缓存专门用于缓存TLB,但其大小是有限的.当采用的默认页面大小为 4KB,其产生的TLB较大,因而将会产生较多 TLB Miss 和缺页中断,从而大大

linux、内核源码、内核编译与配置、内核模块开发、内核启动流程(转)

linux是如何组成的?答:linux是由用户空间和内核空间组成的为什么要划分用户空间和内核空间?答:有关CPU体系结构,各处理器可以有多种模式,而LInux这样的划分是考虑到系统的安全性,比如X86可以有4种模式RING0~RING3  RING0特权模式给LINUX内核空间RING3给用户空间linux内核是如何组成的?答:linux内核由SCI(System Call Interface)系统调用接口.PM(Process Management)进程管理.MM(Memory Managem

【转】如何下载并编译Android4.0内核源码goldfish(图文)

原文网址:http://blog.csdn.net/flydream0/article/details/7070392 关于如何下载Android4.0源码,请查看我的博客内另一篇文章(同样是图文教程): http://blog.csdn.net/flydream0/article/details/7036156 如何编译Android4.0源码请看: http://blog.csdn.net/flydream0/article/details/7046612 下面进入正题: 第一步:下载gol

Linux Hugetlbfs内核源码简析-----(二)Hugetlbfs挂载

本文只讨论执行"mount none /mnt/huge -t hugetlbfs"命令后,mount系统调用的执行过程(基于Linux-3.4.51),不涉及进程相关的细节. mount系统调用的内核实现: 1 SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, 2 char __user *, type, unsigned long, flags, void __user *, data)

linux内核源码注解

轻松学习Linux操作系统内核源码的方法 针对好多Linux 爱好者对内核很有兴趣却无从下口,本文旨在介绍一种解读linux内核源码的入门方法,而不是解说linux复杂的内核机制:一.核心源程序的文件组织:1.Linux核心源程序通常都安装在/usr/src/linux下,而且它有一个非常简单的编号约定:任何偶数的核心(例如2.0.30)都是一个稳定地发行的核心,而任何奇数的核心(例如2.1.42)都是一个开发中的核心. 本文基于稳定的2.2.5源代码,第二部分的实现平台为 RedHat Lin

轻松学习linux内核源码的方法

轻松学习Linux操作系统内核源码的方法 针对好多Linux 爱好者对内核很有兴趣却无从下口,本文旨在介绍一种解读linux内核源码的入门方法,而不是解说linux复杂的内核机制:一.核心源程序的文件组织:1.Linux核心源程序通常都安装在/usr/src/linux下,而且它有一个非常简单的编号约定:任何偶数的核心(例如2.0.30)都是一个稳定地发行的核心,而任何奇数的核心(例如2.1.42)都是一个开发中的核心. 本文基于稳定的2.2.5源代码,第二部分的实现平台为 RedHat Lin

【转】Linux CentOS内核编译:下载CentOS源码、编译2.6.32-220的错误(apic.c:819 error &#39;numi_watchdog&#39; undeclared)

一.下载CentOS源码 1.1 查看CentOS版本 cat /etc/issue 1.2 查看Linux内核版本 uname -r 1.3 下载 文件名:kernel-2.6.32-220.el6.src.rpm 下载地址:http://vault.centos.org/6.2/os/Source/SPackages/ 官网:http://vault.centos.org/ 1.4 从kernel-2.6.32-220.el6.src.rpm获取源码 1. rpm -i kernel-2.6

Linux内核分析(一)---linux体系简介|内核源码简介|内核配置编译安装

原文:Linux内核分析(一)---linux体系简介|内核源码简介|内核配置编译安装 Linux内核分析(一) 从本篇博文开始我将对linux内核进行学习和分析,整个过程必将十分艰辛,但我会坚持到底,同时在博文中如果那些地方有问题还请各位大神为我讲解. 今天我们会分析到以下内容: 1.      Linux体系结构简介 2.      Linux内核源码简介 3.      Linux内核配置.编译.安装 l  Linux体系结构简介 1.       Linux体系结构(linux系统构成)

Linux内核源码分析--内核启动之(5)Image内核启动(rest_init函数)(Linux-3.0 ARMv7)【转】

原文地址:Linux内核源码分析--内核启动之(5)Image内核启动(rest_init函数)(Linux-3.0 ARMv7) 作者:tekkamanninja 转自:http://blog.chinaunix.net/uid-25909619-id-4938395.html 前面粗略分析start_kernel函数,此函数中基本上是对内存管理和各子系统的数据结构初始化.在内核初始化函数start_kernel执行到最后,就是调用rest_init函数,这个函数的主要使命就是创建并启动内核线