加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

LINUX教程:Red Hat Enterprise Linux 7.2 编译安装新内核支持NT

发布时间:2020-12-13 17:35:59 所属栏目:Linux 来源:网络整理
导读:《LINUX教程:Red Hat Enterprise Linux 7.2 编译安装新内核支持NTFS文件系统》要点: 本文介绍了LINUX教程:Red Hat Enterprise Linux 7.2 编译安装新内核支持NTFS文件系统,希望对您有用。如果有疑问,可以联系我们。 内核,是一个操作系统的核心.它负责管

《LINUX教程:Red Hat Enterprise Linux 7.2 编译安装新内核支持NTFS文件系统》要点:
本文介绍了LINUX教程:Red Hat Enterprise Linux 7.2 编译安装新内核支持NTFS文件系统,希望对您有用。如果有疑问,可以联系我们。

内核,是一个操作系统的核心.它负责管理系统的进程、内存、设备驱动程序、文件和网络系统,决定着系统的性能和稳定性.Linux作为一个自由软件,在广大喜好者的支持下,内核版本不断更新.新的内核修订了旧内核的bug,并增加了许多新的特性.如果用户想要使用这些新特性,或想根据自己的系统度身定制一个更高效,更稳定的内核,就需要重新编译内核.

本文将以kernel 4.7.2版本为实验,操作平台64位为Red Hat Enterprise Linux 7.2,将通过以下三个方面来阐明内核及模块的编译.?

源码编译Linux内核?
使用Linux内核模块?
实战:编译一个NTFS内核模块,实现Linux挂载NTFS文件系统并实现读写功效

一、 源码编译Linux内核

?准备事情:

1. RedHat7或者以上版本,本文以vm12+redhat7.2为例.

2. 内核版本下载地址:?到官网:https://cdn.kernel.org?

?查看最新稳固版内核:?https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.7.2.tar.xz

?也可以通过敕令行下载:?wget?https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.7.2.tar.xz

虚拟机硬件的要求:

硬盘可用空间大于8G.不然编译时,会因为空间不够,提示你安装不成功.

虚拟机内存要调到2.5G以上.最好是4G以上,这里是8G.

第一步: 对硬件进行设置,使其满足要求并下载内核:

1. 新添加一块20G的硬盘及改动内存:

2.反省当前的内核版本: uname -r?

3.到官网:https://cdn.kernel.org? 查看最新稳固版内核并下载

如果虚拟机不克不及上网(如何让虚拟机上网,参考本人相关博文),那也没有关系,直接从外网下载好后,用xshell工具上传至虚拟机.如图:

?在xshell的终端输入rz,打开下面的上传界面:

上传即可.

或者点击下面按钮也可以:

假如虚拟机可以联网:不妨从虚拟机直接下载.

[root@xiaolyu ~]# wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.7.2.tar.xz

第二步:?使用硬盘:分区、格局化、挂载:

?

[root@xiaolyu ~]# fdisk /dev/sdb //对磁盘/dev/sdb进行格局化.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only,until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x63b985bb.

Command (m for help): m //查看赞助信息.
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

?

Command (m for help): n
Partition type:
p primary (0 primary,0 extended,4 free)
e extended
Select (default p): p
Partition number (1-4,default 1):
First sector (2048-41943039,default 2048):
Using default value 2048
Last sector,+sectors or +size{K,M,G} (2048-41943039,default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

?

Command (m for help): p

?

Disk /dev/sdb: 21.5 GB,21474836480 bytes,41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x63b985bb

?

Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux

?

Command (m for help):
Command (m for help): w

?

?

对磁盘进行格局化: mkfs -t ?xfs /dev/sdb1

[root@xiaolyu ~]# ls /dev/sdb1
/dev/sdb1
[root@xiaolyu ~]# mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=4,agsize=1310656 blks
= sectsz=512 attr=2,projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=5242624,imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560,version=2
= sectsz=512 sunit=0 blks,lazy-count=1
realtime =none extsz=4096 blocks=0,rtextents=0
[root@xiaolyu ~]#

创立挂载点并进行挂载:

[root@xiaolyu ~]# mkdir /sdb1 ?//创建挂载点.
[root@xiaolyu ~]# mount /dev/sdb1 /sdb1 ?//挂载硬盘.
[root@xiaolyu ~]# df -h | tail -1 ?//验证是否挂载胜利.
/dev/sdb1 20G 33M 20G 1% /sdb1
[root@xiaolyu ~]#

第三步、编译、安装linux新内核及模块.

1.?将源码包移动到/sdb1中.

2.?反省系统是否安装make、gcc、gcc-c++ 、ncurses-devel和库工具等等

使用rpm -qa 检测上述对象及库是否存在.

[root@xiaolyu ~]# rpm -qa | grep make
automake-1.13.4-3.el7.noarch
make-3.82-21.el7.x86_64
[root@xiaolyu ~]# rpm -qa | grep gcc
gcc-4.8.5-4.el7.x86_64
gcc-gfortran-4.8.5-4.el7.x86_64
libgcc-4.8.5-4.el7.x86_64
gcc-c++-4.8.5-4.el7.x86_64
[root@xiaolyu ~]# rpm -qa |grep gcc-c++
gcc-c++-4.8.5-4.el7.x86_64

[root@xiaolyu ~]# rpm -qa | grep ncurses-devel
[root@xiaolyu ~]#?yum -y install ncurses-devel? #yum? 安装 ncurses-devel动态库.

Loaded plugins: langpacks,product-id,search-disabled-repos,subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel7-yum | 4.1 kB 00:00:00
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 rhel7-yum 713 k

Transaction Summary
Total download size: 713 k
Installed size: 2.1 M
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!
[root@xiaolyu ~]#

?

?

3.解压内核源码包

xz -d 解压 .xz的紧缩包

tar xf 解压.tar的紧缩包

[root@xiaolyu sdb1]# ls
linux-4.7.2.tar.xz
[root@xiaolyu sdb1]# xz -d linux-4.7.2.tar.xz
[root@xiaolyu sdb1]# ls
linux-4.7.2.tar
[root@xiaolyu sdb1]# tar xf linux-4.7.2.tar
[root@xiaolyu sdb1]# ls
linux-4.7.2 linux-4.7.2.tar
[root@xiaolyu sdb1]#

?

[root@xiaolyu sdb1]# ls

linux-4.7.2 linux-4.7.2.tar
[root@xiaolyu sdb1]# cd linux-4.7.2
[root@xiaolyu linux-4.7.2]# ls
arch CREDITS firmware ipc lib net scripts usr
block crypto fs Kbuild MAINTAINERS README security virt
certs Documentation include Kconfig Makefile REPORTING-BUGS sound
COPYING drivers init kernel mm samples tools
[root@xiaolyu linux-4.7.2]# more README?

#阐明:这个地方可以查看README文件,每个源码包都有,里面给出了详细的安装编译配置信息.

?

?

4. 清算系统缓存.

尽可能给内核编译留出最年夜的内存空间.

查看体系缓存 free -m :

[root@xiaolyu linux-4.7.2]# free -m
total used free shared buff/cache available
Mem: 7969 611 5341 10 2015 7040
Swap: 2047 0 2047
[root@xiaolyu linux-4.7.2]#

查看默认缓存设置:cat /proc/sys/vm/drop_caches

[root@xiaolyu linux-4.7.2]# free -m
total used free shared buff/cache available
Mem: 7969 611 5341 10 2015 7040
Swap: 2047 0 2047
[root@xiaolyu linux-4.7.2]# cat /proc/sys/vm/drop_caches
0?
[root@xiaolyu linux-4.7.2]# sync
[root@xiaolyu linux-4.7.2]# echo 3 > /proc/sys/vm/drop_caches? #buff和cache都清空
[root@xiaolyu linux-4.7.2]# free -m
total used free shared buff/cache available
Mem: 7969 571 7214 10 183 7194
Swap: 2047 0 2047
[root@xiaolyu linux-4.7.2]#

#阐明:/proc/sys/vm/drop_cashes的值有三个:

  0:buff/cache都不要清算.

  1:只清算buff.

  2:只清算cache.

  3:buff和cache都清算.

阐明:重启(reboot和init 6)一样能清空缓存.

5. 通过图形界面设置装备摆设内核编译参数,生成内核参数设置装备摆设文件.

make menuconfig? 生成内核参数设置装备摆设文件.

[root@xiaolyu linux-4.7.2]# make menuconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/mconf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTCC scripts/kconfig/lxdialog/checklist.o
HOSTCC scripts/kconfig/lxdialog/util.o
HOSTCC scripts/kconfig/lxdialog/inputbox.o
HOSTCC scripts/kconfig/lxdialog/textbox.o
HOSTCC scripts/kconfig/lxdialog/yesno.o
HOSTCC scripts/kconfig/lxdialog/menubox.o
HOSTLD scripts/kconfig/mconf
scripts/kconfig/mconf Kconfig
#
# using defaults found in /boot/config-3.10.0-327.el7.x86_64
#
Your display is too small to run Menuconfig!
It must be at least 19 lines by 80 columns.
make[1]: 淫乱 [menuconfig] Error 1
make: 淫乱 [menuconfig] Error 2

说明:直接在虚拟机的终端执行 make menuconfig出现上述差错,屏幕太小了,没法运行Menuconfig,于是果断在xshell下执行上述命令:

经过反复研究,我将字体缩小的时候,当字体为13的时候,在终端执行上述命令,是不会呈现因为显示不下而报错的.下面是截图.

生成.config设置装备摆设文件,查看此设置装备摆设文件:

[root@xiaolyu linux-4.7.2]# vim .config

?

?


选择“File system”? 然后按回车

?

由上图可以看出,新内核支持多种文件体系.

?

按【空格键】,进入下图:

?

?

?

?

?

?

?

?

?

用原内核的配置文件,覆盖新内核的配置文件.这里说明一下:为什么要用原内核覆盖新内核,因为内核的配置,比拟复杂,可以参考:http://blog.csdn.net/star_xiong/article/details/17357821

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://blog.csdn.net/xuyuefei1988/article/details/8635539? ? ? ? ? ? ? ? ? ? ? ?

           

? ? ?

新旧内核的差异在于ntfs文件系统的支持,所以用老的来覆盖一下.

如果呈现是否覆盖? n不覆盖? y 覆盖,这里选y覆盖.

[root@xiaolyu linux-4.7.2]# cp /boot/config-3.10.0-327.el7.x86_64 /sdb1/linux-4.7.2/.config
cp: overwrite ‘/sdb1/linux-4.7.2/.config’? y
[root@xiaolyu linux-4.7.2]#

比拟原内核的配置文件和备份的新生成的配置文件的差异:

[root@xiaolyu linux-4.7.2]# diff .config .config_bak ?
3c3
< # Linux/x86_64 3.10.0-327.el7.x86_64 Kernel Configuration
---
> # Linux/x86 4.7.2 Kernel Configuration
13d12
< CONFIG_HAVE_LATENCYTOP_SUPPORT=y
14a14,17
> CONFIG_ARCH_MMAP_RND_BITS_MIN=28

?因为差别实在太大了,想了解具体的差别的朋友,可以看我另一篇博文:

<linux内核更新前后配置文件的比拟>?http://www.cnblogs.com/jasmine-Jobs/p/5808949.html

差别还是蛮大的.因为太长了,这里仅仅给出一个局部的截图:

这个地方为了快速完成新内核的安装,采用了修改原配置文件的办法.

改动配置文件,使其支持ntfs读写.

[root@xiaolyu linux-4.7.2]# vim .config

?

?

5、编译内核

先反省openssl-devel 这个包安装没有,如果没有,提前安装这个包openssl-devel

rpm -qa | grep ?openssl-devel

yum -y install? openssl-devel

?

[root@xiaolyu linux-4.7.2]# make bzImage ?//生成内核.这个过程异常异常的慢.

中间多次问你y/n,全部选y,就可以了.这个过程比拟慢.

说明,上述的问题,我已经完全办理了,问题出在,我是先执行make menuconfig,然后cp /boot/config-3.10.0-327.el7.x86_64 /sdb1/linux-4.7.2/.config

这样的成果使得,新生成的内核被完全覆盖掉,毫无用处,4.7.2的内核比3.1的内核多的东西都没有做任何配置.

正确的做法是:先执行cp /boot/config-3.10.0-327.el7.x86_64 /sdb1/linux-4.4/.config ?然后再make menuconfig .

如下图:

?

阐明在编译内核: make bzImage 之前,要先安装一下这个包:openssl-devel,即:

yum -y install? openssl-devel

不然会报如下错误:

?即:

重新: make bzImage:

?

这里也是必要一段时间

呈现此界面OK!

6、下面?天生新内核的驱动模块:

[root@xiaolyu linux-4.7.2]# make modules -j 4
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK include/generated/timeconst.h
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CC [M] arch/x86/crypto/glue_helper.o

?因为这个模块编译的过程非常漫长,所以当编译完成的时候,要echo $? 判断一下是否胜利:

安装模块:make modules ?install?

[root@xiaolyu linux-4.7.2]# make modules_install

出现下面的界面阐明模块安装成功:

?

?

2)安装新编译的体系内核 :?make install?

[root@xiaolyu linux-4.7.2]# make install

重新启动系统,测试新内核的工作环境

注意,在启动的时候,需要本身进来一下选择,否则默认还是以前的内核启动哦.除非你在上一步把默认启动项给改了.

如果你将默认启动项给修改为4.7.2,那么会酿成如下界面:

使用新内核启动体系后,查看内核版本:

[root@xiaolyu?Desktop ~]# unmae -r

更多RedHat相关信息见RedHat 专题页面 /topicnews.aspx?tid=10

本文永远更新链接地址

《LINUX教程:Red Hat Enterprise Linux 7.2 编译安装新内核支持NTFS文件系统》是否对您有启发,欢迎查看更多与《LINUX教程:Red Hat Enterprise Linux 7.2 编译安装新内核支持NTFS文件系统》相关教程,学精学透。编程之家PHP学院为您提供精彩教程。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读