2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

关于如何删除 centos linux 系统的内核镜像

Posted at

每次在你升级了 centos 的 linux 内核版本之后,默认系统并不会删除旧的镜像, 而是叠加到内核启动 list 的最上面. 当然这个并不会引发任何的问题, 你也并不需要做额外的动作来处理这些没用的旧的镜像.

不过有时候财力有限买到的磁盘没用那么大,经常要担心不够用, 所以就要去看看/ boot 这个目录了,

$ df -h /boot/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       331M  198M  112M  64% /boot

或者你可以去编辑一下启动文件/etc/grub.conf, 下面的命令会帮助你移除那些不需要的 centos linux 镜像. 我们先罗列下有那些镜像:

假如是这样的结果:

# rpm -q kernel
kernel-3.10.0-229.4.2.el7.x86_64
kernel-3.10.0-229.el7.x86_64
kernel-3.10.0-229.20.1.el7.x86_64
kernel-3.10.0-229.11.1.el7.x86_64
kernel-3.10.0-327.3.1.el7.x86_64

假如你当前加载到的就是最新的内核镜像, 如kernel-3.10.0-327.3.1.el7.x86_64,通过 uname -r 就可以获得:

$ uname -r
3.10.0-327.3.1.el7.x86_64

接下来, 我们需要这样一个工具包 package-cleanup 来协助移除除当前使用的最新的其他的所有不需要的内核.

yum install yum-utils

到这里我们就可以用 package-cleanup 这个命令来移除旧内核了. 这个-- oldkernels 选项就是告诉命令我们想要移除旧的内核. 而这个--count=1就是说别把所有的都给删了,留一个. 这样以备不时之需啊. 我们来执行这个命令:

# package-cleanup --oldkernels --count=1

来确认下:

# rpm -q kernel
kernel-3.10.0-229.20.1.el7.x86_64
kernel-3.10.0-327.3.1.el7.x86_64

ref

  1. http://serverfault.com/questions/439090/how-to-free-up-space-on-rhel6-boot-safely
  2. https://linuxconfig.org/how-to-remove-unused-kernel-images-from-centos-linux-system
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?