博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux内核的编译(Ubuntu为例
阅读量:4134 次
发布时间:2019-05-25

本文共 3624 字,大约阅读时间需要 12 分钟。

文章目录

LINUX内核编译

1、获取linux内核源代码

在这里插入图片描述

在下载目录打开终端,输入命令

sudo tar -xvf linux*.tar.xz -C /usr/src

解压到/usr/src文件夹中

2、选择和启动内核配置程序

打开终端,输入命令cd /usr/src/linux-5.0

(最后一项为你所下载的linux内核源代码文件夹的名称)

准备安装环境,输入命令

sudo apt-get install kernel-package build-essential libncurses5-dev fakeroot

输入命令,sudo make menuconfig(文本选择界面,字符终端)

(ps:请提前安装好make,gcc,bison,flex,libncurses-dev
安装方式为,sudo apt-get install make(换成对应的名字 即可)

打开后如图

在这里插入图片描述

3.根据需要配置内核模块和参数(默认即可)

如需修改, 可参考如下

1 、Loadable module support 设置对可加载模块支持。

Enable loadable module support(y)Set version info on all module symbols (n)Kernel module loader(y)

2、 Processor type and features

设置CPU的类型	Processor family选择CPU类型	High Memory Support (n)	Math emulation (n)	MTTR support: (n)	Symmetric multi-processing support (n)

3 General setup

对普通的一些属性进行设置。		Networking support:(y)		PCI support(y)		PCI access mode PCI卡存取模式: BIOS、Direct和Any		Support for hot-pluggable devices (n)		PCMCIA/CardBus support (n)

4 Parallel port support 并口支持 (y)

5 Plug and Play configuration:即插即用配置(y)
6 Block devices 块设备支持的选项

Normal PC floppy disk support 软盘支持(y)   Network block device support 网络块设备支持(y)

7 Networking options 选取TCP/IP networking选项

8 Network device support 网络设备支持的选项

例如:使用Realtek 8139网卡	Ethernet(10 or 100Mbit) (y)	RealTeck RTL-8139 PCI Fast Ethernet Adapter support (y)

9 Mice 鼠标设置选项:串口、PS/2等类型鼠标

10 File systems 文件系统类型。

DOS FAT fs 选项:FAT16, FAT32NTFS file system support/proc file system support: (y)

11.Sound 声卡驱动,选项:声卡型号

12.USB support USB接口的支持,根据需要选择。

4、重新编译新的内核

sudo make clean        (清除旧的编译结果sudo make bzImage

5、编译和安装模块

sudo make modulessudo make modules_install(模块被编译且安装到 /usr/lib/
<内核版本号>
目录下。sudo make install

6、启动新内核

配置grub,更新grub启动信息

sudo update-grub

如下配置默认也可

cp bzImage /boot/bzImage

LILO

配置/etc/lilo.confimage=/boot/bzImagelabel=newLinux build by Zhang San Feb.28, 2012

命令 #lilo 使配置生效

GRUB (与发行版本有关)

配置/boot/grub/grub.conftitle newLinux build by Zhang San Feb.28, 2012root (hd0,1)kernel /boot/bzImage ro root=/dev/hda2

在这里插入图片描述

修改默认启动内核(转

Ubuntu 18.04+windows10双系统中

要将默认内核更改为启动,可以执行以下操作:

1.打开文件/ etc / default / grub。

2.将GRUB_DEFAULT的值更改为您希望选择的菜单选项的索引值。

例如,在启动过程中的GRUB菜单中有:

UbuntuAdvanced options for UbuntuWindows 10 (loader) (on /dev/sda1)system setup

我的 “Advananced options for Ubuntu” 子菜单如下所示:

Ubuntu, with Linux 4.13.0-26-genericUbuntu, with Linux 4.13.0-26-generic (upstart)Ubuntu, with Linux 4.13.0-26-generic (recovery mode)Ubuntu, with Linux 4.10.0-42-genericUbuntu, with Linux 4.10.0-42-generic (upstart)Ubuntu, with Linux 4.10.0-42-generic (recovery mode)
grep 'menuentry' /boot/grub/grub.cfg(也可通过这个命令查看

现在,第一个选项是索引0,第二个是1,第三个是2,依此类推。(即GRUB菜单中的 Ubuntu为0,Advanced options for Ubuntu为1,…)

在我的情况下,我想选择 “Advanced options for Ubuntu” 子菜单中的 “Ubuntu, with Linux 4.10.0-42-generic”(“以前旧的内核版本”)

设置 sudo /etc/default/grub

GRUB_DEFAULT设为:

GRUB_DEFAULT = “1> 3”

使用 '>' 符号来指定有一个子菜单(注意符号 > 和数字 3 之间有空格,所以需要双引号)。在这种情况下,我在主菜单中选择第2个选项(索引1),在子菜单中选择第四个选项(索引3)。

3.一旦对/etc/default/grub进行了更改,请保存并运行以下命令来更新GRUB配置文件(必须,否则不生效):

sudo update-grub

4.重新启动,现在应该默认启动旧的内核版本。

增加系统调用(LINUX-4.4.177为例子

1、增加系统调用函数

进入 cd /usr/src/linux-4.4.177

进入sudo gedit kernel/sys.c编写函数(最下侧在这里插入图片描述

其中,sys_后的名字自己取,本人取得testFuction,记住这个名字

2.修改头文件,增加系统调用声明

修改sudo gedit include/linux/syscalls.h

在这里插入图片描述

4.添加系统调用表

修改sudo vim arch/x86/entry/syscalls/syscall_64.tbl

在这里插入图片描述
接下来编译新内核即可

系统调用测试

在这里插入图片描述

在这里插入图片描述

精简内核

将原来的 make menuconfig 更改为 make localmodconfig 即可完成精简

make localmodconfig 会执行 lsmod 命令查看当前系统中加载了哪些模块 (Modules), 并最后将原来的 .config 中不需要的模块去掉,仅保留前面 lsmod 出来的这些模块,从而简化了内核的配置过程。

删除内核(以4.9.165为例

sudo rm -rf /lib/modules/4.9.165sudo rm -rf /usr/src/linux-headers-4.9.165sudo rm /boot/*4.9.165*sudo rm /var/lib/dpkg/info/linux-headers-4.9.165*sudo rm -rf /usr/src/linux-4.9.165sudo update-grub

转载地址:http://jpvvi.baihongyu.com/

你可能感兴趣的文章
ios 常用的30个动画效果
查看>>
iOS开发中的手势体系——UIGestureRecognizer分析及其子类的使用
查看>>
iOS图片压缩处理
查看>>
Lab、TextView文字两端对齐(中英文、标点、空格换行)
查看>>
Android进阶学习方法总结(内附阿里P7进阶学习全套资料)
查看>>
秃头警告!我把Github上6k星的Android性能优化教程和实战项目整合成了一个PDF文档
查看>>
程序员狂怒:薪水被应届生倒挂了,很不爽,天王老子也别想留住我!
查看>>
35岁程序员:“鞠躬尽瘁,死而...” 算了,我还是转行吧!
查看>>
c语言数据结构实现-数组队列/环形队列
查看>>
c语言数据结构实现-链式队列
查看>>
[学习总结】C语言
查看>>
抽象数据类型——表
查看>>
读《历史上的三种人》
查看>>
Leecode 记录——Remove Nth Node From End of List
查看>>
Leecode记录——Valid Palindrome
查看>>
leetcode记录——Count and Say
查看>>
Leetcode 记录——Happy Number
查看>>
【leetcode 两个链表的交集点】Intersection of Two Linked Lists
查看>>
leetcode-tree1
查看>>
leetcode balanced binary tree(看不懂...)
查看>>