科技常识:linux如何编译安装新内核支持NTFS文件系统(以redhat7.2x64为例)

2021-04-18 11:40:29
导读 今天小编跟大家讲解下有关科技常识:linux如何编译安装新内核支持NTFS文件系统(以redhat7 2x64为例),相信小伙伴们对这个话题应该也很关注

今天小编跟大家讲解下有关科技常识:linux如何编译安装新内核支持NTFS文件系统(以redhat7.2x64为例),相信小伙伴们对这个话题应该也很关注吧,小编也收集到了有关科技常识:linux如何编译安装新内核支持NTFS文件系统(以redhat7.2x64为例)的相关资料,希望小伙伴会喜欢也能够帮助大家。

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

本文将以kernel 4.7.2版本为实验,操作平台为RedHat 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

虚拟机硬件的要求:

硬盘可用空间大于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 tableBuilding a new DOS disklabel with disk identifier 0x63b985bb.

Command (m for help): m //查看帮助信息。Command actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitiong create a new empty GPT partition tableG create an IRIX (SGI) partition tablel list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)

Command (m for help): nPartition type:p primary (0 primary, 0 extended, 4 free)e extendedSelect (default p): pPartition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039Partition 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 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk 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/sdb1meta-data=/dev/sdb1 isize=256 agcount=4, agsize=1310656 blks= sectsz=512 attr=2, projid32bit=1= crc=0 finobt=0data = bsize=4096 blocks=5242624, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal log bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =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 makeautomake-1.13.4-3.el7.noarchmake-3.82-21.el7.x86_64[root@xiaolyu ~]# rpm -qa | grep gccgcc-4.8.5-4.el7.x86_64gcc-gfortran-4.8.5-4.el7.x86_64libgcc-4.8.5-4.el7.x86_64gcc-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-managerThis 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 SummaryTotal download size: 713 kInstalled size: 2.1 MDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : 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]# lslinux-4.7.2.tar.xz[root@xiaolyu sdb1]# xz -d linux-4.7.2.tar.xz[root@xiaolyu sdb1]# lslinux-4.7.2.tar[root@xiaolyu sdb1]# tar xf linux-4.7.2.tar[root@xiaolyu sdb1]# lslinux-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]# lsarch CREDITS firmware ipc lib net scripts usrblock crypto fs Kbuild MAINTAINERS README security virtcerts Documentation include Kconfig Makefile REPORTING-BUGS soundCOPYING 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 -mtotal used free shared buff/cache availableMem: 7969 611 5341 10 2015 7040Swap: 2047 0 2047[root@xiaolyu linux-4.7.2]#

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

[root@xiaolyu linux-4.7.2]# free -mtotal used free shared buff/cache availableMem: 7969 611 5341 10 2015 7040Swap: 2047 0 2047[root@xiaolyu linux-4.7.2]# cat /proc/sys/vm/drop_caches0[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 -mtotal used free shared buff/cache availableMem: 7969 571 7214 10 183 7194Swap: 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 menuconfigHOSTCC scripts/basic/fixdepHOSTCC scripts/kconfig/mconf.oSHIPPED scripts/kconfig/zconf.tab.cSHIPPED scripts/kconfig/zconf.lex.cSHIPPED scripts/kconfig/zconf.hash.cHOSTCC scripts/kconfig/zconf.tab.oHOSTCC scripts/kconfig/lxdialog/checklist.oHOSTCC scripts/kconfig/lxdialog/util.oHOSTCC scripts/kconfig/lxdialog/inputbox.oHOSTCC scripts/kconfig/lxdialog/textbox.oHOSTCC scripts/kconfig/lxdialog/yesno.oHOSTCC scripts/kconfig/lxdialog/menubox.oHOSTLD scripts/kconfig/mconfscripts/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 1make: *** [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

            http://www.linuxidc.com/Linux/2012-06/63092.htm

新旧内核的差别在于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/.configcp: 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 Configuration13d12< CONFIG_HAVE_LATENCYTOP_SUPPORT=y14a14,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 4CHK include/config/kernel.releaseCHK include/generated/uapi/linux/version.hCHK include/generated/utsrelease.hCHK include/generated/timeconst.hCHK include/generated/bounds.hCHK include/generated/asm-offsets.hCALL scripts/checksyscalls.shCC [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@xiaolyuDesktop ~]# unmae -r

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持爱蒂网。

来源:爱蒂网

免责声明:本文由用户上传,如有侵权请联系删除!

猜你喜欢

最新文章