linux如何編譯安裝新內(nèi)核支持NTFS文件系統(tǒng)(以redhat7.2x64為例)
內(nèi)核,是一個操作系統(tǒng)的核心。它負責(zé)管理系統(tǒng)的進程、內(nèi)存、設(shè)備驅(qū)動程序、文件和網(wǎng)絡(luò)系統(tǒng),決定著系統(tǒng)的性能和穩(wěn)定性。Linux作為一個自由軟件,在廣大愛好者的支持下,內(nèi)核版本不斷更新。新的內(nèi)核修訂了舊內(nèi)核的bug,并增加了許多新的特性。如果用戶想要使用這些新特性,或想根據(jù)自己的系統(tǒng)度身定制一個更高效,更穩(wěn)定的內(nèi)核,就需要重新編譯內(nèi)核。
本文將以kernel 4.7.2版本為實驗,操作平臺為RedHat 7.2,將通過以下三個方面來說明內(nèi)核及模塊的編譯。
源碼編譯Linux內(nèi)核
使用Linux內(nèi)核模塊
實戰(zhàn):編譯一個NTFS內(nèi)核模塊,實現(xiàn)Linux掛載NTFS文件系統(tǒng)并實現(xiàn)讀寫功能
一、 源碼編譯linux內(nèi)核準備工作:
1. redhat7或者以上版本,本文以vm12+redhat7.2為例。
2. 內(nèi)核版本下載地址:到官網(wǎng):https://cdn.kernel.org
查看最新穩(wěn)定版內(nèi)核:https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.7.2.tar.xz
虛擬機硬件的要求:
硬盤可用空間大于8G.否則編譯時,會因為空間不夠,提示你安裝不成功。
虛擬機內(nèi)存要調(diào)到2.5G以上.最好是4G以上,這里是8G。
第一步: 對硬件進行設(shè)置,使其滿足要求并下載內(nèi)核:
1. 新添加一塊20G的硬盤及修改內(nèi)存:
2.檢查當前的內(nèi)核版本: uname -r
3.到官網(wǎng):https://cdn.kernel.org 查看最新穩(wěn)定版內(nèi)核并下載
如果虛擬機不能上網(wǎng)(如何讓虛擬機上網(wǎng),參考本人相關(guān)博文),那也沒有關(guān)系,直接從外網(wǎng)下載好后,用xshell工具上傳至虛擬機。如圖:
在xshell的終端輸入rz,打開下面的上傳界面:
上傳即可。
或者點擊下面按鈕也可以:
如果虛擬機可以聯(lián)網(wǎng):不妨從虛擬機直接下載。
[root@xiaolyu ~]# wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.7.2.tar.xz
第二步:使用硬盤:分區(qū)、格式化、掛載:
[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 ~]#
創(chuàng)建掛載點并進行掛載:
[root@xiaolyu ~]# mkdir /sdb1 //創(chuàng)建掛載點。
[root@xiaolyu ~]# mount /dev/sdb1 /sdb1 //掛載硬盤。
[root@xiaolyu ~]# df -h | tail -1 //驗證是否掛載成功。
/dev/sdb1 20G 33M 20G 1% /sdb1
[root@xiaolyu ~]#
第三步、編譯、安裝linux新內(nèi)核及模塊。
1.將源碼包移動到/sdb1中。
2.檢查系統(tǒng)是否安裝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動態(tài)庫。
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.解壓內(nèi)核源碼包
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. 清理系統(tǒng)緩存。
盡可能給內(nèi)核編譯留出最大的內(nèi)存空間。
查看系統(tǒng)緩存 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]#
查看默認緩存設(shè)置: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. 通過圖形界面配置內(nèi)核編譯參數(shù),生成內(nèi)核參數(shù)配置文件。
make menuconfig 生成內(nèi)核參數(shù)配置文件。
[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
說明:直接在虛擬機的終端執(zhí)行 make menuconfig出現(xiàn)上述錯誤,屏幕太小了,沒法運行Menuconfig ,于是果斷在xshell下執(zhí)行上述命令:
經(jīng)過反復(fù)研究,我將字體縮小的時候,當字體為13的時候,在終端執(zhí)行上述命令,是不會出現(xiàn)因為顯示不下而報錯的。下面是截圖。
生成.config配置文件,查看此配置文件:
[root@xiaolyu linux-4.7.2]# vim .config
選擇“File system” 然后按回車
由上圖可以看出,新內(nèi)核支持多種文件系統(tǒng)。
按【空格鍵】,進入下圖:
用原內(nèi)核的配置文件,覆蓋新內(nèi)核的配置文件。這里說明一下:為什么要用原內(nèi)核覆蓋新內(nèi)核,因為內(nèi)核的配置,比較復(fù)雜,可以參考: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
新舊內(nèi)核的差別在于ntfs文件系統(tǒng)的支持,所以用老的來覆蓋一下。
如果出現(xiàn)是否覆蓋 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]#
比較原內(nèi)核的配置文件和備份的新生成的配置文件的差異:
[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內(nèi)核更新前后配置文件的比較>http://www.cnblogs.com/jasmine-Jobs/p/5808949.html
差異還是蠻大的。因為太長了,這里僅僅給出一個局部的截圖:
這個地方為了快速完成新內(nèi)核的安裝,采用了修改原配置文件的方法。
修改配置文件,使其支持ntfs讀寫。
[root@xiaolyu linux-4.7.2]# vim .config
5、編譯內(nèi)核
先檢查openssl-devel 這個包安裝沒有 ,如果沒有,提前安裝這個包openssl-devel
rpm -qa | grep openssl-devel
yum -y install openssl-devel
[root@xiaolyu linux-4.7.2]# make bzImage //生成內(nèi)核。這個過程非常非常的慢。
中間多次問你y/n,全部選y,就可以了。這個過程比較慢。
說明,上述的問題,我已經(jīng)完全解決了,問題出在,我是先執(zhí)行make menuconfig ,然后cp /boot/config-3.10.0-327.el7.x86_64 /sdb1/linux-4.7.2/.config
這樣的結(jié)果使得,新生成的內(nèi)核被完全覆蓋掉,毫無用處,4.7.2的內(nèi)核比3.1的內(nèi)核多的東西都沒有做任何配置。
正確的做法是:先執(zhí)行cp /boot/config-3.10.0-327.el7.x86_64 /sdb1/linux-4.4/.config 然后再make menuconfig 。
如下圖:
說明在編譯內(nèi)核: make bzImage 之前,要先安裝一下這個包:openssl-devel,即:
yum -y install openssl-devel
否則會報如下錯誤:
即:
重新: make bzImage:
這里也是需要一段時間
出現(xiàn)此界面OK!
6、下面生成新內(nèi)核的驅(qū)動模塊:
[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
出現(xiàn)下面的界面說明模塊安裝成功:
2)安裝新編譯的系統(tǒng)內(nèi)核 :make install
[root@xiaolyu linux-4.7.2]# make install
重新啟動系統(tǒng),測試新內(nèi)核的工作情況
注意,在啟動的時候,需要自己進來一下選擇,否則默認還是以前的內(nèi)核啟動哦。除非你在上一步把默認啟動項給改了。
如果你將默認啟動項給修改為4.7.2,那么會變成如下界面:
使用新內(nèi)核啟動系統(tǒng)后,查看內(nèi)核版本:
[root@xiaolyuDesktop ~]# unmae -r
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Linux proc目錄下子文件或子文件夾的作用
- Linux中如何查看已掛載的文件系統(tǒng)類型詳解
- Linux中對lvm邏輯卷分區(qū)大小的調(diào)整教程(針對xfs與ext4不同文件系統(tǒng))
- 詳解Linux文件系統(tǒng):ext4及更高版本
- 詳細分析Linux文件系統(tǒng)
- linux查看文件系統(tǒng)塊大小與內(nèi)存頁大小的簡單方法
- 查看linux文件系統(tǒng)塊大小的實現(xiàn)方法
- linux系統(tǒng)之間通過nfs網(wǎng)絡(luò)文件系統(tǒng)掛載設(shè)置方法
- linux文件系統(tǒng)調(diào)整大小的方法(linux調(diào)整分區(qū)大小)
- Linux內(nèi)核設(shè)備驅(qū)動之proc文件系統(tǒng)筆記整理
相關(guān)文章
【專家教程】xmrig挖礦病毒清除攻略,保護你的服務(wù)器免受侵害!
面對日益猖獗的XMRig挖礦病毒,是時候采取行動了!這份攻略將帶你一步步清除這個隱蔽的威脅,讓你的設(shè)備再次安全起來,快來看看我們的秘訣,讓病毒無處遁形!2024-02-02解決Linux常用命令“l(fā)l”失效或命令未找到的問題
這篇文章主要介紹了Linux常用命令“l(fā)l”失效或命令未找到的問題及解決方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06Centos7 Mysql 5.6 多主一從 解決方案與詳細配置
這篇文章主要介紹了Centos7 Mysql 5.6 多主一從 解決方案與詳細配置,需要的朋友可以參考下2016-04-04