linux —— 编译linux内核
目录: 0、测试环境
1、获得最新内核源代码
2、编译源代码
3、运行新的内核
0、测试环境:
我的系统 : ubuntu 16.04 LTS (内核版本:4.4.0-36-generic )
下载源代码内核版本 : Linux 4.8-rc6
测试时间 : 2016/9/16
1、获得最新内核源代码
获取方法可以有以下两种:
1.1 在linux 内核官方主页:http://www.kernel.org,你永远可以获得 当前最新的linux内核源完整的tarball(一种用tar命令生成的 归档/压缩 文件)以及不断发布的 补丁(patch) .
1.2 直接从git上面获取: https://github.com/torvalds/linux。具体是:Terminal 进入自己想要同步下来的目录后。clone下来:
cd /同步下来/的/目录
git clone https://github.com/torvalds/linux.git #这个应该有2G多
1.3 编译准备
连同源代码和编译后的产生的文件,请准备好20G的硬盘空间!(从git上clone下来的源代码 2.6 G; 经过make后另外生成的编译文件 13.5G 这加起来有17G的空间)
/ 根目录(具体来说是 /lib,没挂载/lib的话就默认是使用/目录) 要有至少4G的空余空间
/ boot 要有至少 400M 的空余空间
所以请在编译前查看自己是否有对应充足的空间。(我就是不知道这一点重装了两次系统:一次是 /home 不足,一次是/boot不足)
2、编译源代码
编译内核:(根据github README 的说明)
2.0、在编译前仔细看README,有一些细节得注意例如说:
DOCUMENTATION:
这个说明项里面提到,可以参考的文档网站:帮助文档项目 还有git项目的目录里document里有部分项目文档的说明等。
SOFTWARE REQUIREMENTS
而这个提到要去看一下 项目目录里的 “Documentation/Changes” 的软件要求最低要求(不然后面遇到版本问题会很头大),我使用的时ubuntu 16.04,里面提到的软件版本都符合要求,就是有一些没软件我没有,因为刚接触还不确定需不需要所以没有的我都自己下载了。
还有,在开始编译前:要 Make sure you have no stale .o files and dependencies lying around:
cd linux #进入git clone 下来的linux 目录(最顶目录)
make mrproper 具体还是自己刻苦啃一下 README 比较好。
2.1、执行 make menuconfig
我决定自定义编译的路径:( 根据 “BUILD directory for the kernel”)
执行:
make O=/home/bensonlaur/build/kernel menuconfig
结果报错:
/home/bensonlaur/gproject/linux/scripts/kconfig/lxdialog/dialog.h::: fatal error: curses.h: 没有那个文件或目录
解决:
#因为缺少包,安装之,然后重新 make menuconfig
sudo apt-get install libncurses5-dev
2.2、开始按上面的配置结果来 执行: make
执行:(由于github 项目里的README说,一旦自定义了build路径,选择了O选项,所有的make都得制定这个路径)
make O=/home/bensonlaur/build/kernel
(注意:刚才执行 make O=/home/bensonlaur/build/kernel menuconfig 成功时,会显示图形界面给你配置,save 配置为 .config 。
我试过别的名字,这样的话在make这一步会提示:
***
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
,我也不知道改了配置名字后,去哪里制定我的别的名字的配置文件,就重新使用make O=/home/bensonlaur/build/kernel menuconfig生成 名为.config的配置文件,于是就没报这个错了 )
继续make 时继续报错:
/home/bensonlaur/gproject/linux/scripts/sign-file.c::: fatal error: openssl/opensslv.h: 没有那个文件或目录
解决:
#还是因为缺少包,安装之,然后重新 执行make
sudo apt-get install libssl-dev
解决缺少的文件问题后,接着就是漫长的编译等待了
(时间需要很长,也消耗空间,第一次都没底,可怜我12G的/home空间本来已经剩下9G,没想到还爆满,也不知道还会生成多少,为了分20G给/home,还重装了一遍系统,还好这次够用)。
此过程有很多warning,不知道是什么情况,我先记录在这里:
......
/home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c: In function ‘save_mc_for_early’:
/home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c::: warning: the frame size of bytes is larger than bytes [-Wframe-larger-than=]
}
^
/home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c: In function ‘load_microcode.isra..constprop’:
/home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c::: warning: the frame size of bytes is larger than bytes [-Wframe-larger-than=]
}
^
/home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c: In function ‘get_matching_model_microcode.isra..constprop’:
/home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c::: warning: the frame size of bytes is larger than bytes [-Wframe-larger-than=]
}
^
/home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c: In function ‘save_microcode_in_initrd_intel’:
/home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c::: warning: the frame size of bytes is larger than bytes [-Wframe-larger-than=]
}
^
......
这个不是warning,也记录下吧,(反正现在还在等着)
CC [M] kernel/torture.o
CC certs/system_keyring.o
EXTRACT_CERTS
Generating X. key generation config
###
### Now generating an X. key pair to be used for signing modules.
###
### If this takes a long time, you might wish to run rngd in the
### background to keep the supply of entropy topped up. It
### needs to be run as root, and uses a hardware random
### number generator if one is available.
###
Generating a bit RSA private key
..........................................................................................++
.................++
unable to write 'random state'
writing new private key to 'certs/signing_key.pem'
-----
###
### Key pair generated.
###
EXTRACT_CERTS certs/signing_key.pem
AS certs/system_certificates.o
LD certs/built-in.o
CC mm/filemap.o
CC mm/mempool.o ......
CC [M] fs/jffs2/xattr.o
/home/bensonlaur/gproject/linux/fs/jffs2/xattr.c: In function ‘jffs2_build_xattr_subsystem’:
/home/bensonlaur/gproject/linux/fs/jffs2/xattr.c::: warning: the frame size of bytes is larger than bytes [-Wframe-larger-than=]
}
^
CC [M] fs/jffs2/xattr_trusted.o
...... (呀,等了那么久,不小心复制 ctrl+shift+c 按错成 取消的ctrl+c,还好重新make好像可以从上次继续,吓死我了,以为又要等那么久,算了不贴了,warning应该都是类似的那个warning: the frame size of bytes is larger than bytes [-Wframe-larger-than=])
......
......
make 过程中的 warning
2.3、执行 :sudo make modules_install install
我前面指定了O选项,这里同样指定执行:
sudo make O=/home/bensonlaur/build/kernel modules_install install
此过程会在 /lib 生成接近4G的所编译内核的文件,在/boot生成400M的文件(包括initrd.img-4.8.0-rc6,/boot/grub/menu.lst 等)。
2.4 配置kernel
CONFIGURING the kernel: 在README 的“CONFIGURING the kernel”里面提到,配置是必要的,如果想要以最小的工作量把已有的自己系统的配置搬过来 ,执行make oldconfig:
sudo make O=/home/bensonlaur/build/kernel oldconfig
关于make oldconfig: 不必要的驱动会使内核变得臃肿,不同于386的处理器类型的设置会试内核无法运行在386上,建议不熟悉配置的使用make oldconfig。
3、运行新的内核
- Booting a kernel directly from a floppy without the assistance of a
bootloader such as LILO, is no longer supported.
If you boot Linux from the hard drive, chances are you use LILO, which
uses the kernel image as specified in the file /etc/lilo.conf. The
kernel image file is usually /vmlinuz, /boot/vmlinuz, /bzImage or
/boot/bzImage. To use the new kernel, save a copy of the old image
and copy the new image over the old one. Then, you MUST RERUN LILO
to update the loading map! If you don't, you won't be able to boot
the new kernel image.
上面说现在启动新的内核需要一个叫 LILO (linux loader)的软件,下面安装并让其自动配置。
( 安装之后执行 liloconfig会自动帮我们检测并生成配置文件 /etc/lilo.conf 和/boot/map等, 这个文件里是具体的配置和说明)
bensonlaur@b-lenovo:~$ lilo
程序“lilo”尚未安装。 您可以使用以下命令安装:
sudo apt install lilo
bensonlaur@b-lenovo:~$ sudo apt install lilo
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列【新】软件包将被安装:
lilo
升级了 个软件包,新安装了 个软件包,要卸载 个软件包,有 个软件包未被升级。
需要下载 kB 的归档。
解压缩后会消耗 kB 的额外空间。
获取: http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 lilo amd64 1:24.2-1 [252 kB]
已下载 kB,耗时 1秒 ( kB/s)
正在预设定软件包 ...
正在选中未选择的软件包 lilo。
(正在读取数据库 ... 系统当前共安装有 个文件和目录。)
正准备解包 .../lilo_1%3a24.-1_amd64.deb ...
正在解包 lilo (:24.2-) ...
正在处理用于 man-db (2.7.-) 的触发器 ...
正在设置 lilo (:24.2-) ... bensonlaur@b-lenovo:~$ sudo liloconfig
images '/boot/vmlinuz*' found.
New file created as: /etc/lilo.conf
Now you must execute '/sbin/lilo' to activate this new configuation! bensonlaur@b-lenovo:~$ sudo /sbin/lilo
Added Linux + *
Added Linux_Old +
bensonlaur@b-lenovo:~$
安装lilo 并配置
配置完之后从启便可进入我们自己编译的内核了。
重启前查看下自己的当前内核版本:
uname -r
重启后菜单里有两个选项:linux linux_old (T_T我的windows不见了,算了后面再解决)(解决办法:linux——启动引导程序 LILO 与 grub 中的第5点)
选择第一个【linux】,等待一定时间就启动了,所有一切看上去好像没什么变化,再执行一遍:
uname -r
如果看到的版本是最新的你编译的版本,那么恭喜,你正在体验的就是世界上最新鲜的linux内核。
那么,接下来想办法去玩一下这个内核吧。:)
获得帮助
订阅Linux内核邮件列表 :http://www.wowotech.net/linux_application/lkml.html
工具介绍:
Oprofile 工具:一个功能强大的性能分析工具,在这里 被推荐下载,下载地址:在这里 (好像直接系统下载跟方便:
sudo apt install oprofile
)
Oprofile的安装和使用:
安装说明:这里
安装时缺少2个库:
configure: error: popt library not found
相应的安装包:sudo apt install popt-devel configure: error: liberty library not found
相应的安装包:sudo apt install libiberty-dev 测试时间:2016/9/16
linux —— 编译linux内核的更多相关文章
- Linux 编译安装内核
一.简介 内核,是一个操作系统的核心.它负责管理系统的进程.内存.设备驱动程序.文件和网络系统,决定着系统的性能和稳定性.Linux作为一个自由软件,在广大爱好者的支持下,内核版本不断更新.新的内核修 ...
- 编译Linux内核
下面的实验以 debian7.5 64bit 为例. 获取源码 获取 debian7.5 本身的源码非常简单: sudo apt-get install linux-source https://ww ...
- 【原创】Linux编译内核
Linux 编译内核 大致分这几个步骤 1.准备编译工具.内核文件 2.开始编译 3.将编译好的新内核install进系统 4.查看是否成功. 一.准备好必备的库和内核文件 1.添加必备的编译 ...
- 如何解决编译linux内核(解决声卡问题),遭遇fatal error: linux/limits.h: 没有那个文件或目录
最近帮一位上海的朋友搞一块小板,在ubuntu15.04 vivid上已经加载了对应了.ko驱动包 但关键是系统根本就枚举不到该声卡ALC5640,试了OpenSUSE也是一样的结果,看来是内核漏加载 ...
- Linux 4.1内核编译报告
编译环境 Arch Linux on VirtualBox 下载内核 https://www.kernel.org/ 下载的内核压缩包,此时的最新内核版本为4.1: 解压包 # tar -xvJf l ...
- 【转】Linux驱动模块编译进内核中
原文网址:http://blog.chinaunix.net/uid-29287950-id-4573481.html BQ27501驱动编译进内核 一. 驱动程序编译进内核的步骤 在 l ...
- Centos下编译Linux内核
Linux内核编译是一件简单却费事的事.但是独立的编译linux内核会帮助你很好的理解Linux内核的工作机理. 首先编译linux内核我们需要在当前linux操作系统下安装gcc编译器,因为我是Ce ...
- Linux内核分析(一)---linux体系简介|内核源码简介|内核配置编译安装
原文:Linux内核分析(一)---linux体系简介|内核源码简介|内核配置编译安装 Linux内核分析(一) 从本篇博文开始我将对linux内核进行学习和分析,整个过程必将十分艰辛,但我会坚持到底 ...
- 编译linux内核时出错
在编译linux内核的时候使用make menuconfig 可能出现下面的错误 *** Unable to find the ncurses libraries or the*** required ...
随机推荐
- [LeetCode OJ] Word Search 深度优先搜索DFS
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- 授权(Authorization)
介绍 除了认证服务,laravel还提供了授权服务,laravel同样提供了一个简单的方式去组织授权的逻辑来控制资源的访问.我们提供了各种各样的方法协助你们组织授权的逻辑,这些都在下面的文档之中. 定 ...
- tomcat gc问题总结
Java内存泄露监控工具:JVM监控工具介绍 http://developer.51cto.com/art/201203/321431.htm 关于施用full gc频繁的分析及解决 http:/ ...
- C#中的Invoke
在用.NET Framework框架的WinForm构建GUI程序界面时,如果要在控件的事件响应函数中改变控件的状态,例如:某个按钮上的文本原先叫“打开”,单击之后按钮上的文本显示“关闭”,初学者往往 ...
- 看es6 字符串新方法有感
'x'.repeat(3) // "xxx" 'hello'.repeat(2) // "hellohello" 'na'.repeat(0) // " ...
- js 中的流程控制—while和do while
while语句: while(exp){ }如果为true ,执行代码块里的语句,如果为false,跳出循环 <script> var i =1 ; while (i<10){ / ...
- Java:对象的序列化
一.对象序列化机制 序列化机制允许将实现序列化的Java对象转换为字节序列,这些字节序列可以被保存在磁盘上或通过网络传输,以备以后重新恢复原来的对象: 序列化机制使得对象可以脱离程序的运行而独立存在: ...
- Python资源汇集
Python资源汇集 一 实用教程 廖雪峰网站 第一,Python教程:提供了循序渐进,重点是可操作的实用教程. 第二,Web App 项目教程.给出一个用16天完成的Python Web APP项目 ...
- Linux Kernel Makefile Test
一.本文说明 本文为linux内核Makefile整体分析的续篇,是依据Linux内核Makefile体系的主要内容编写一个简要的测试工程.Linux内核Makefile体系就好像一只“大鸟”,而这篇 ...
- C51应用 Modbs Rtu协议实现与KEPServerEx 通信
最近一客户要求使用STC12C5A60S2实现Modbus Rtu协议与KEPServerEx V4.0软件通信,采集单片机P2口每位的状态,设置P0口每位的状态,实现三路AD转换其中一路采集的是C0 ...