(三十) Ubuntu解决/boot 空间不足问题

前言:在linux使用好几个月后,开机的时候总是会提醒/boot 空间不足,我当时想下次重装系统的时候一定给/boot 分配个几个G,100多M不大够用,可是我点linux对应的报告问题的时候,Linux提示这是已知问题,已解决,然后学习了一下解决方法。


参考链接:https://help.ubuntu.com/community/RemoveOldKernels


1. 问题产生原因

LVM installs and encrypted installs use a separate /boot partition. The partition by default is capable of holding only four or five kernels, and can fill to capacity quickly. To prevent your /boot partition from getting full, you need to configure automatic removal of old kernels, or manually remove old kernels regularly.

Changing the kernel providing packages on your system requires commands with root access, so please read RootSudo.

简单说来就是随着linux kernel的更新,系统中包含的kernel越来越多,最后会将本来就不大的/boot空间填满。解决方法有两个,一个是配置自动移除老的kernels,另外是手动移除。


如下图所示,标红处在我进行kernel清除之前都是installed的状态,都占着/boot的空间,导致新的kernel版本安装不了。

PS:

1.查看自己kernel所处版本命令

jiatai@jiatai:~$ uname -r
4.13.0-39-generic


2.查看历史kernel安装命令

dpkg --get-selections|grep linux


3.卸载某个kernel版本

sudo apt-get remove linux-image-4.13.0-32(版本号见上面历史kernel获取)

这个方法是从网上找到的,参考链接中有提到安全卸载方法:

$ sudo update-initramfs -d -k 4.2.0-15-generic
$ sudo dpkg --purge linux-image-4.2.0-15-generic linux-image-extra-4.2.0-15-generic
                                  ## If the previous command fails, some installed package
                                  ## depends on the kernel. The output of dpkg displays the name
                                  ## of the package. Purge it first.
$ sudo apt-get -f install         ## Try to fix the broken dependency.


2. 解决方法

2.1 手动解决

sudo apt-get autoremove --purge

看下这个命令的作用:

所以这个命令的作用应该是卸载所有自动安装且不再使用的软件包并且卸载和清除对应软件包的配置。


2.2 自动解决

14.04有两个步骤,16.04只有第二步,第一步默认实现。

2.2.1 Enable Unattended Upgrades (Ubuntu 14.04)

简单说来就是打开软件自动更新和安装。


对应英文段落:

In Ubuntu 16.04 and later unattended-upgrades is enabled by default, however in Ubuntu 14.04 you will need to enable it either via the GUI or a command-line.

GUI WAY

Enable unattended upgrades using Software & Updates application's "Updates" tab:

  • Check the box for *-security (and/or any other repositories you wish)
  • Automatically check for updates: Set to any frequency (except 'Never')
  • When there are security updates: Set to Download and Install Automatically

SHELL WAY

sudo dpkg-reconfigure -plow unattended-upgrades


2.2.2 Configure Unattended Upgrades to Remove Unneeded Kernels Automatically

第二步是配置自动升级的时候移除不再需要的kernels,但是配置会将所有不再需要的依赖都移除,其中包括kernels。

修改文件/etc/apt/apt.conf.d/50unattended-upgrades 中如下所示,去除注释以及将默认的false改成true。


同时有提及说上面的文件不要包含如下语句,我检查了下没有。

Unattended-Upgrade::Remove-New-Unused-Dependencies "false"

对应英文段落:

Note: The following methods will only remove kernels that are marked as being automatically installed as described above. In Ubuntu 16.04 kernels installed by Software Updater are marked as being automatically installed. In Ubuntu 14.04 only kernels installed by unattended-upgrades are marked as being automatically installed. See bug #1439769 for details.

Note: This way will not remove all automatically installed old kernel providing packages as fallback versions are kept; the list of kept kernels is maintained and automatically updated in the file /etc/apt/apt.conf.d/01autoremove-kernels as a list of matching regular expressions.

The second step is to edit the configuration file /etc/apt/apt.conf.d/50unattended-upgrades to enable automatic removal. It's owned by root, so remember to use sudo!

Option for All Ubuntu Releases

The following setting configures unattended-upgrade to remove unused dependencies after an unattended upgrade.

Make sure /etc/apt/apt.conf.d/50unattended-upgrades contains line

Unattended-Upgrade::Remove-Unused-Dependencies "true";

and that it is not commented out. Comments start with '//' in this file.

Thereafter unattended-upgrades will remove automatically remove packages providing old kernels as part of unattended upgrade. (It does not purge them, however.) It also removes other unneeded packages, as well.

Option for Ubuntu 16.04 and newer

Unattended-upgrades version 0.90 supports a new configuration variable that makes it possible to automatically remove only packages that become excessive during a run of unattended-upgrades. It is enabled i.e. "true" by default, so make sure /etc/apt/apt.conf.d/50unattended-upgrades does not contain:

Unattended-Upgrade::Remove-New-Unused-Dependencies "false"
The way this is designed, it is important that you let unattended-upgrades handle installion of security updates. Otherwise unattended-uprades will not remove old kernels and you may have to do some manual removing of kernels.


后面还有一段手动移除的讲了比较复杂,遇到问题的小伙伴可以对照修改。




猜你喜欢

转载自blog.csdn.net/sinat_20059415/article/details/80211487