本文共 4164 字,大约阅读时间需要 13 分钟。
编译安装内核
升级内核到 linux-4.20.3.tar.xz
查看当前内核版本:[root@centos7 data]#uname -r3.10.0-862.el7.x86_64获取内核源代码包:www.kernel.orglinux-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/6Server3. 解压linux-4.20.3.tar.xz4. 配置内核编译的参数make menuconfig5. 开始编译make //等价于这两个命令make bzImage make modules6. 安装模块make modules_install //安装到了 /lib/modules/$(uname -r)7. 安装内核make install //安装到了 /boot8. 检查 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 NTFSCONFIG_NTFS_FS=mCONFIG_NTFS_RW=y
可选操作:定制kernel版本名
[root@centos7 linux-4.20.3]#head MakefileVERSION = 4
PATCHLEVEL = 20SUBLEVEL = 3EXTRAVERSION =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 directorymake: *** [modinst] Error 1原因: 内核配置项General setup——》Local version - append to kernel release,所填内容有空格。
解决办法:
删除空格,然后make modules, 再安装模块。由于版本信息改变,需要重新编译安装内核。安装内核相关文件
[root@centos7 linux-4.20.3]#make installsh ./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.gzefi System.mapextlinux System.map-3.10.0-862.el7.x86_64grub System.map-4.20.3-1.0-xinzhoulinuxgrub2 vmlinuzinitramfs-0-rescue-18ed42c1c89e4d28870e69320e88d637.img vmlinuz-0-rescue-18ed42c1c89e4d28870e69320e88d637initramfs-3.10.0-862.el7.x86_64.img vmlinuz-3.10.0-862.el7.x86_64initramfs-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 $menuentry_id_option 'gnulinux-3.10.0-862.el7.x86_64-advanced-576ed6fe-d3e8-403d-832f-2dc117ba8d2f' { load_videoset gfxpayload=keepinsmod gzioinsmod part_msdosinsmod xfsset root='hd0,msdos1'if [ x$feature_platform_search_hint = xy ]; thensearch --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-509621e5fc1eelsesearch --no-floppy --fs-uuid --set=root 6e6694fc-5a2f-47a1-b96b-509621e5fc1efilinux16 /vmlinuz-4.20.3-1.0-xinzhoulinux root=UUID=576ed6fe-d3e8-403d-832f-2dc117ba8d2f ro crashkernel=auto rhgb quiet LANG=en_US.UTF-8initrd16 /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转载于:https://blog.51cto.com/8845692/2345381