本文主要是和另一篇手动安装内核配对的https://www.anidays.com/2024/79.html,更新内核后就得内核基本没啥用了,我喜欢把他们卸载掉,节约点VPS存储空间,虽然是杯水车薪,但乐于折腾。

环境:CentOS 7 X64 2009,其他机器仅供参考。

1、首先通过uname -r命令获取当前使用内核版本,返回数据如下:

[root@wiki-hk-web ~]# uname -r
3.10.0-1160.92.1.el7.x86_64

然后我们看下系统上一共有多少内核,执行:

rpm -qa | grep kernel

返回如下

[root@wiki-hk-web ~]# rpm -qa | grep kernel
kernel-3.10.0-1160.92.1.el7.x86_64
kernel-tools-3.10.0-1160.95.1.el7.x86_64
kernel-devel-3.10.0-1160.95.1.el7.x86_64
kernel-3.10.0-1160.95.1.el7.x86_64
kernel-ml-5.15.60-1.el7.x86_64
kernel-ml-devel-5.15.60-1.el7.x86_64
kernel-devel-3.10.0-1160.83.1.el7.x86_64
kernel-devel-3.10.0-1160.92.1.el7.x86_64
kernel-tools-libs-3.10.0-1160.95.1.el7.x86_64
kernel-headers-3.10.0-1160.95.1.el7.x86_64
kernel-3.10.0-1160.45.1.el7.x86_64
kernel-devel-3.10.0-1160.88.1.el7.x86_64
kernel-3.10.0-1160.88.1.el7.x86_64
kernel-3.10.0-1160.83.1.el7.x86_64

因为我们使用的内核是3.10.0-1160.92.1.el7.x86_64,一般来说内核需要kernel-kernel-devel-kernel-headers-+版本号的文件,我这里就是如下内核是正在运行的,不要删除:

kernel-3.10.0-1160.92.1.el7.x86_64
kernel-devel-3.10.0-1160.92.1.el7.x86_64
kernel-headers-3.10.0-1160.95.1.el7.x86_64

我这个当前版本还少了个对应版本的kernel-headers-,所以系统是使用kernel-headers-3.10.0-1160.95.1.el7.x86_64,所以他不能删除。

2、下面我们就删除指定内核文件,使用如下命令:

yum remove kernel-tools-3.10.0-1160.95.1.el7.x86_64

返回如下:

[root@wiki-hk-web ~]# yum remove kernel-tools-3.10.0-1160.95.1.el7.x86_64
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package kernel-tools.x86_64 0:3.10.0-1160.95.1.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================
 Package                         Arch                      Version                                  Repository                   Size
======================================================================================================================================
Removing:
 kernel-tools                    x86_64                    3.10.0-1160.95.1.el7                     @updates                    337 k

Transaction Summary
======================================================================================================================================
Remove  1 Package

Installed size: 337 k
Is this ok [y/N]:

这里我们可以看到只会卸载指定的文件,所以没啥问题,输入Y,确认删除。
如果出现

[root@wiki-hk-web ~]# yum remove kernel-headers-3.10.0-1160.95.1.el7.x86_64
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package kernel-headers.x86_64 0:3.10.0-1160.95.1.el7 will be erased
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-326.el7_9.x86_64
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-326.el7_9.x86_64
--> Processing Dependency: kernel-headers >= 2.6.27-0.144.rc0.git2.fc10 for package: libdrm-devel-2.4.97-2.el7.x86_64
--> Running transaction check
---> Package glibc-headers.x86_64 0:2.17-326.el7_9 will be erased
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-326.el7_9.x86_64
--> Processing Dependency: glibc-headers = 2.17-326.el7_9 for package: glibc-devel-2.17-326.el7_9.x86_64
---> Package libdrm-devel.x86_64 0:2.4.97-2.el7 will be erased
--> Processing Dependency: pkgconfig(libdrm) >= 2.4.75 for package: mesa-libEGL-devel-18.3.4-12.el7_9.x86_64
--> Processing Dependency: pkgconfig(libdrm) >= 2.4.75 for package: mesa-libGL-devel-18.3.4-12.el7_9.x86_64
--> Running transaction check
---> Package glibc-devel.x86_64 0:2.17-326.el7_9 will be erased
--> Processing Dependency: glibc-devel for package: 4:perl-devel-5.16.3-299.el7_9.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-44.el7.x86_64
---> Package mesa-libEGL-devel.x86_64 0:18.3.4-12.el7_9 will be erased
--> Processing Dependency: pkgconfig(egl) for package: cairo-devel-1.15.12-4.el7.x86_64
---> Package mesa-libGL-devel.x86_64 0:18.3.4-12.el7_9 will be erased
--> Running transaction check
---> Package cairo-devel.x86_64 0:1.15.12-4.el7 will be erased
---> Package gcc.x86_64 0:4.8.5-44.el7 will be erased
--> Processing Dependency: gcc = 4.8.5-44.el7 for package: gcc-c++-4.8.5-44.el7.x86_64
--> Processing Dependency: gcc = 4.8.5 for package: libtool-2.4.2-22.el7_3.x86_64
---> Package perl-devel.x86_64 4:5.16.3-299.el7_9 will be erased
--> Processing Dependency: perl-devel for package: 1:perl-ExtUtils-ParseXS-3.18-3.el7.noarch
--> Processing Dependency: perl-devel for package: perl-ExtUtils-Install-1.58-299.el7_9.noarch
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-44.el7 will be erased
---> Package libtool.x86_64 0:2.4.2-22.el7_3 will be erased
---> Package perl-ExtUtils-Install.noarch 0:1.58-299.el7_9 will be erased
--> Processing Dependency: perl(ExtUtils::Install) for package: perl-ExtUtils-MakeMaker-6.68-3.el7.noarch
--> Processing Dependency: perl(ExtUtils::Installed) for package: perl-ExtUtils-MakeMaker-6.68-3.el7.noarch
--> Processing Dependency: perl(ExtUtils::Packlist) for package: perl-ExtUtils-MakeMaker-6.68-3.el7.noarch
---> Package perl-ExtUtils-ParseXS.noarch 1:3.18-3.el7 will be erased
--> Running transaction check
---> Package perl-ExtUtils-MakeMaker.noarch 0:6.68-3.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================
 Package                                 Arch                   Version                                Repository                Size
======================================================================================================================================
Removing:
 kernel-headers                          x86_64                 3.10.0-1160.95.1.el7                   @updates                 3.8 M
Removing for dependencies:
 cairo-devel                             x86_64                 1.15.12-4.el7                          @base                    2.2 M
 gcc                                     x86_64                 4.8.5-44.el7                           @base                     37 M
 gcc-c++                                 x86_64                 4.8.5-44.el7                           @base                     16 M
 glibc-devel                             x86_64                 2.17-326.el7_9                         @updates                 1.0 M
 glibc-headers                           x86_64                 2.17-326.el7_9                         @updates                 2.2 M
 libdrm-devel                            x86_64                 2.4.97-2.el7                           @base                    543 k
 libtool                                 x86_64                 2.4.2-22.el7_3                         @base                    2.2 M
 mesa-libEGL-devel                       x86_64                 18.3.4-12.el7_9                        @updates                  89 k
 mesa-libGL-devel                        x86_64                 18.3.4-12.el7_9                        @updates                 1.6 M
 perl-ExtUtils-Install                   noarch                 1.58-299.el7_9                         @updates                  75 k
 perl-ExtUtils-MakeMaker                 noarch                 6.68-3.el7                             @base                    635 k
 perl-ExtUtils-ParseXS                   noarch                 1:3.18-3.el7                           @base                    174 k
 perl-devel                              x86_64                 4:5.16.3-299.el7_9                     @updates                 1.8 M

Transaction Summary
======================================================================================================================================
Remove  1 Package (+13 Dependent packages)

Installed size: 70 M
Is this ok [y/N]:

说明有的软件依赖于他,卸载的话,这些软件都会被卸载,为了谨慎起见,建议不要卸载。如果你已经下载了新的kernel-headers文件,这里也可以先卸载,然后安装新的kernel-headers文件,然后再把软件一个一个装回来。所以我建议VPS重装后第一件是是把内核更新了,然后再装软件。
排除后,我们又使用rpm -qa | grep kernel查看剩余内核,再使用yum remove[空格]内核名称来一个一个手动删除,手动删除的好处是可以保留需要的内核。

当然,也有自动命令,执行以下命令可以自动获取当前系统中的无用内核(未使用的)并进入卸载:

yum remove $(rpm -qa | grep kernel | grep -v $(uname -r))

执行上面命令后,会有卸载确认操作。确认下卸载内核列表中没有当前正在使用的内核,然后输入y确认卸载即可。

3、卸载完毕后,可以执行以下命令查看下/boot分区的占用情况

df -h /boot

返回如下

[root@wiki-hk-web ~]# df -h /boot
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  5.8G   45G  12% /

参考文献:
https://www.cnblogs.com/jykn92/p/15094919.html

最后修改:2024 年 10 月 23 日
如果觉得我的文章对你有用,请随意赞赏