编译安装内核、启动管理、内核卸载

1、编译安装kernel,启用支持ntfs文件系统功能
# 下载内核包
[root@localhost ~]# wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.7.5.tar.xz

# 解压
[root@localhost ~]# tar xf linux-4.20.2.tar.xz -C /usr/

# 进入 /usr/src 目录,创建软链接
[root@localhost ~]# cd /usr/src
[root@localhost src]# ln -sv linux-5.7.5 linux

# 复制 .config 文件
[root@localhost src]# cd linux
[root@localhost linux]# cp /boot/config-$(uname -r) ./.config

# 查看编译帮助
[root@localhost linux]# make help

# 安装需要的文件(否则会报错)
[root@localhost linux]# yum install -y ncurses-devel flex bison elfutils-libelf-devel bc

# 运行 menuconfig,选择 NTFS 支持
[root@localhost linux]# make menuconfig
  • 移到“File System”按回车键进入下一级
    在这里插入图片描述
  • 选择“DOS/FAT/EXFAT/NT Filesystems”,按回车进入下一级
    在这里插入图片描述
  • 选中“NTFS file system support”,并在新弹出的选项中选中“NTFS write support”,然后按 tab 键选中 save 并按回车保存
    在这里插入图片描述
  • 直接 OK 保存
    在这里插入图片描述
  • 保存成功,退出
    在这里插入图片描述
# 编译
[root@localhost linux]# make -j 2

# 生成模块
[root@localhost linux]# make modules_install

# 生成内核
[root@localhost linux]# make install

# 重启
[root@localhost linux]# reboot

# 查看 ntfs 模块
[root@localhost ~]# modinfo ntfs
filename:       /lib/modules/5.7.5/kernel/fs/ntfs/ntfs.ko
license:        GPL
version:        2.1.32
description:    NTFS 1.2/3.x driver - Copyright (c) 2001-2014 Anton Altaparmakov and Tuxera Inc.
author:         Anton Altaparmakov <anton@tuxera.com>
alias:          fs-ntfs
srcversion:     4D306484D5B0E54E4EA7EF4
depends:        
retpoline:      Y
intree:         Y
name:           ntfs
vermagic:       5.7.5 SMP mod_unload modversions 

# 插入一个 NTFS 分区的硬盘(在 windows 虚拟机创建分区),可以看到是 NTFS 分区
[root@localhost ~]# blkid
/dev/sdb1: LABEL="M-gM-3M-;M-gM-;M-^_M-dM-?M-^]M-gM-^UM-^Y" UUID="F6A4F0B2A4F07689" TYPE="ntfs" 
/dev/sdb2: UUID="884E7F8A4E7F7034" TYPE="ntfs" 
/dev/sda1: UUID="9d738e10-ef5f-4070-9901-5dc4bb08f4a9" TYPE="xfs" 
/dev/sda2: UUID="d271b5a3-9e48-488c-ab2a-68960b75475a" TYPE="xfs" 
/dev/sda3: UUID="9092aafc-239d-4096-ab05-2d77a0aec194" TYPE="swap" 

# 挂载分区、查看分区内容
[root@localhost ~]# mount /dev/sdb2 /mnt
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        952M     0  952M   0% /dev
tmpfs           979M     0  979M   0% /dev/shm
tmpfs           979M  8.7M  971M   1% /run
tmpfs           979M     0  979M   0% /sys/fs/cgroup
/dev/sda2        50G   17G   34G  33% /
/dev/sda1      1014M  201M  814M  20% /boot
tmpfs           196M     0  196M   0% /run/user/0
/dev/sdb2        60G   11G   50G  18% /mnt
[root@localhost ~]# ls /mnt
bootmgr  BOOTNXT  Documents and Settings  pagefile.sys  PerfLogs  ProgramData  Program Files  Program Files (x86)  Recovery  $Recycle.Bin  System Volume Information  Users  Windows

# 查看内核
[root@localhost ~]# uname -r
5.7.5
2、修改默认的启动内核为新编译内核
# 备份 grub.cfg
[root@localhost ~]#  cp -p /boot/grub2/grub.cfg{,.bak}

# 查看默认启动项
[root@localhost ~]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)

# 修改默认启动项(在/boot/grub2/grub.cfg中查看启动名称,menuentry后面的内容)
[root@localhost ~]# grub2-set-default "CentOS Linux (5.7.5) 7 (Core)"
[root@localhost ~]# grub2-editenv list
saved_entry=CentOS Linux (5.7.5) 7 (Core)

# 生成 grub.cfg 文件
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.7.5
Found initrd image: /boot/initramfs-5.7.5.img
Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-9510e6308f1245a19dbe52175fa625bd
Found initrd image: /boot/initramfs-0-rescue-9510e6308f1245a19dbe52175fa625bd.img
Found Windows Recovery Environment (loader) on /dev/sdb1
done

# 重启验证(成功)
3、启动时临时禁用 SELinux
  • 确保SELinux是启用状态
[root@localhost ~]# cat /etc/sysconfig/selinux | grep '^SELINUX='
SELINUX=enforcing
  • 开机启动进入内核选择界面时按 e
    在这里插入图片描述
  • 在 Linux 这行添加 selinux=0,然后按 Ctrl + x 重启
    在这里插入图片描述
4、启动时进入 emergency 模式
  • 开机启动进入内核选择界面时按 e
  • 在 Linux 这行添加 systemd.unit=emergency.target,然后按 Ctrl + x 重启
    在这里插入图片描述
  • 进入 emergency 模式
    在这里插入图片描述
5、卸载编译安装的新内核
# 删除 /lib/modules/ 目录下不需要的内核库文件
[root@localhost ~]# ls /lib/modules
3.10.0-1062.el7.x86_64  5.7.5
[root@localhost ~]# rm -rf /lib/modules/5.7.5

# 删除 /usr/src/linux/ 目录下不需要的内核源码
[root@localhost ~]# ls /usr/src/
debug  kernels  linux  linux-5.7.5
[root@localhost ~]# rm -rf /usr/src/linux-5.7.5

# 删除 /boot 目录下启动的内核和内核映像文件
[root@localhost ~]# ll /boot/*5.7.5*
-rw------- 1 root root 49327962 Jun 23 15:14 /boot/initramfs-5.7.5.img
-rw-r--r-- 1 root root  4513366 Jun 23 15:12 /boot/System.map-5.7.5
-rw-r--r-- 1 root root  8434688 Jun 23 15:12 /boot/vmlinuz-5.7.5
[root@localhost ~]# rm -f /boot/initramfs-5.7.5.img
[root@localhost ~]# rm -f /boot/System.map-5.7.5
[root@localhost ~]# rm -f /boot/vmlinuz-5.7.5

# 更改grub的配置文件,删除不需要的内核启动列表
[root@localhost ~]# vim /boot/grub2/grub.cfg

## 删除 menuentry 'CentOS Linux (5.7.5) 7 (Core)' 到下一个 menuentry 的所有行
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值