編譯安裝內核
升級內核到 linux-4.20.3.tar.xz
查看當前內核版本:
[root@centos7 data]#uname -r
3.10.0-862.el7.x86_64
獲取內核源代碼包:www.kernel.org
linux-4.20.3.tar.xz
==實施步驟
1. 安裝編譯所需的工具 gcc ncurses-devel make(開發工具)
2. 下載內核源碼
a. www.kernel.org(最新)
b. ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server
ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server
3. 解壓linux-4.20.3.tar.xz
4. 配置內核編譯的參數make menuconfig
5. 開始編譯make //等價於這兩個命令make bzImage make modules
6. 安裝模塊make modules_install //安裝到了 /lib/modules/$(uname -r)
7. 安裝內核make install //安裝到了 /boot
8. 檢查 ls /boot, /boot/grub/grub.conf, /lib/modules
==具體實施
1、安裝工具:
[root@centos7 data]#yum -y install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree screen lsof
tcpdump wget ntpdate net-tools iotop bc zip unzip
[root@centos7 data]#yum -y install ncurses-devel
[root@centos7 linux-4.20.3]#yum -y install elfutils-libelf-devel //第一次編譯時報錯,未安裝此包。
-
上傳安裝包,解壓
[root@centos7 data]#tar xvf linux-4.20.3.tar.xz //解壓
[root@centos7 data]#cd linux-4.20.3/
[root@centos7 linux-4.20.3]#cp /boot/config-3.10.0-862.el7.x86_64 .config //準備文本配置文件 -
配置內核選項
[root@centos7 linux-4.20.3]#make menuconfig
[root@centos7 linux-4.20.3]#less .config |grep NTFS
CONFIG_NTFS_FS=mCONFIG_NTFS_DEBUG is not set
CONFIG_NTFS_RW=y
可選操作:定製kernel版本名
[root@centos7 linux-4.20.3]#head MakefileSPDX-License-Identifier: GPL-2.0
VERSION = 4
PATCHLEVEL = 20
SUBLEVEL = 3
EXTRAVERSION =
NAME = Li xinzhou -
開始編譯make
[root@centos7 linux-4.20.3]#make -j 8 && echo -e '\a' -
安裝模塊
[root@centos7 linux-4.20.3]#make modules_install第一次遇到下面的錯誤:
ln: target ‘Linux/source’ is not a directory
make: *** [modinst] Error 1原因: 內核配置項General setup——》Local version - append to kernel release,所填內容有空格。
解決辦法:
刪除空格,然後make modules, 再安裝模塊。由於版本信息改變,需要重新編譯安裝內核。 -
安裝內核相關文件
[root@centos7 linux-4.20.3]#make install
sh ./arch/x86/boot/install.sh 4.20.3-1.0-xinzhoulinux arch/x86/boot/bzImage \
System.map "/boot"安裝bzImage爲/boot/vmlinuz-VERSION-RELEASE 生成initramfs文件 編輯grub的配置文件
-
檢查 ls /boot, /boot/grub2/grub.cfg, /lib/modules
[root@centos7 linux-4.20.3]#ls /boot/ //查看是否有新kernel
config-3.10.0-862.el7.x86_64 symvers-3.10.0-862.el7.x86_64.gz
efi System.map
extlinux System.map-3.10.0-862.el7.x86_64
grub System.map-4.20.3-1.0-xinzhoulinux
grub2 vmlinuz
initramfs-0-rescue-18ed42c1c89e4d28870e69320e88d637.img vmlinuz-0-rescue-18ed42c1c89e4d28870e69320e88d637
initramfs-3.10.0-862.el7.x86_64.img vmlinuz-3.10.0-862.el7.x86_64
initramfs-4.20.3-1.0-xinzhoulinux.img vmlinuz-4.20.3-1.0-xinzhoulinux[root@centos7 linux-4.20.3]#vim /boot/grub2/grub.cfg
menuentry 'CentOS Linux (4.20.3-1.0-xinzhoulinux) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $m
enuentry_id_option 'gnulinux-3.10.0-862.el7.x86_64-advanced-576ed6fe-d3e8-403d-832f-2dc117ba8d2f' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='
hd0,msdos1' 6e6694fc-5a2f-47a1-b96b-509621e5fc1e
else
search --no-floppy --fs-uuid --set=root 6e6694fc-5a2f-47a1-b96b-509621e5fc1e
fi
linux16 /vmlinuz-4.20.3-1.0-xinzhoulinux root=UUID=576ed6fe-d3e8-403d-832f-2dc117ba8d2f ro crashkernel=auto rhgb quiet LANG=e
n_US.UTF-8
initrd16 /initramfs-4.20.3-1.0-xinzhoulinux.img
}[root@centos7 linux-4.20.3]#ls /lib/modules/4.20.3-1.0-xinzhoulinux/kernel/fs/ntfs/ //檢查模塊是否存在
ntfs.ko[root@centos7 ~]#du -sh /data/linux-4.20.3 //編譯後的文件大小11G
11G /data/linux-4.20.3[root@centos7 ~]#uname -r //reboot, 查看到新的內核
4.20.3-1.0-xinzhoulinux[root@centos7 data]#locate ntfs.ko
[root@centos7 data]#updatedb // updatedb - update a database for mlocate
[root@centos7 data]#locate ntfs.ko //已經支持新的ntfs模塊
/data/linux-4.20.3/fs/ntfs/.ntfs.ko.cmd
/data/linux-4.20.3/fs/ntfs/ntfs.ko
/usr/lib/modules/4.20.3-1.0-xinzhoulinux/kernel/fs/ntfs/ntfs.ko - 卸載內核
刪除/lib/modules/目錄下不需要的內核庫文件
刪除/usr/src/linux/目錄下不需要的內核源碼
刪除/boot目錄下啓動的內核和內核映像文件
更改grub的配置文件,刪除不需要的內核啓動列表