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 ...
随机推荐
- 可编辑tab选项卡
效果如图所示,基于jq开发的,用原生可能会麻烦点.所以我没写. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...
- Nginx 独立图片服务器的搭建
为什么需要独立图片服务器? 如果你留心的话,可以发现,现在主流的网站都是有单独的图片服务器的,例如,人人网的为rrimg,淘宝的为taobaocdn,下面还有很多的二级域名. 独立的图片服务器有诸多好 ...
- js上传图片并预览
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- AppDomain与进程、线程、Assembly之间关系
AppDomain是CLR的运行单元,它可以加载Assembly.创建对象以及执行程序 AppDomain是CLR实现代码隔离的基本机制. 每一个AppDomain可以单独运行.停止:每个AppD ...
- Python核心编程2第四章课后练习
4-1 Python 对象.与所有 Python 对象有关的三个属性是什么?请简单的描述一下. 身份:对象的唯一标识 类型 :对象的类型决定了该对象可以保存什么类型的值 ...
- 2016022602 - redis安装和启动
redis安装 我使用的是ubuntu15.1,打开终端,输入命令:sudo apt-get install redis-server 将会在本机安装上redis. 启动redis 启动redis命令 ...
- linux下配置NFS服务器
(声明:本文大部分文字摘自Linux NFS服务器的安装与配置) 一.NFS简介 NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Su ...
- Javascript AMD模块化规范-备用
AMD是"Asynchronous Module Definition"的缩写,意思是"异步模块定义". 模块定义define(id?, dependencie ...
- 《深入剖析Tomcat》阅读(三)
这里要介绍下Tomcat的一个重要设计方法,Catalina设计方式. Servlet容器是一个复杂系统,但是,它有三个基本任务,对每个请求,servlet容器会为其完成以下三个操作: 1.创建一个R ...
- 研究OpenRisc的高人,几十篇文章
http://blog.csdn.net/rill_zhen/article/details/8190322 流水线的实现: http://blog.csdn.net/rill_zhen/articl ...