(30) Ubuntu solves the problem of insufficient /boot space

Foreword: After using linux for several months, it will always remind /boot that the space is insufficient. I thought that when I reinstall the system next time, I must allocate a few G to /boot. More than 100 M is not enough. However, when I clicked the report problem corresponding to linux, Linux suggested that this is a known problem, which has been solved, and then I learned the solution.


Reference link: https://help.ubuntu.com/community/RemoveOldKernels


1. The cause of the problem

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.

To put it simply, with the update of the Linux kernel, the system contains more and more kernels, and eventually the small /boot space will be filled. There are two solutions, one is to configure automatic removal of old kernels, and the other is to remove manually.


As shown in the figure below, the marked red is in the installed state before I clean the kernel, and they all occupy the space of /boot, so the new kernel version cannot be installed.

PS:

1. Check the version command of your own kernel

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


2. View historical kernel installation commands

dpkg --get-selections|grep linux


3. Uninstall a kernel version

sudo apt-get remove linux-image-4.13.0-32 (the version number is obtained from the historical kernel above)

This method was found on the Internet, and the safe uninstall method is mentioned in the reference link:

$ 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. Solution

2.1 Manual resolution

sudo apt-get autoremove --purge

See what this command does:

So the role of this command should be to uninstall all automatically installed and no longer used packages and uninstall and clear the configuration of the corresponding packages.


2.2 Automatic resolution

14.04 has two steps, 16.04 only has the second step, and the first step is implemented by default.

2.2.1 Enable Unattended Upgrades (Ubuntu 14.04)

Simply put, it is to turn on automatic software updates and installations.


Corresponding English paragraph:

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

The second step is to remove kernels that are no longer needed when configuring automatic upgrades, but the configuration will remove all dependencies that are no longer needed, including kernels.

Modify the file /etc/apt/apt.conf.d/50unattended-upgrades as shown below, remove the comment and change the default false to true.


At the same time, it was mentioned that the above file should not contain the following statement, I checked it.

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

Corresponding English paragraph:

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.


There is also a manual removal section that is more complicated, and friends who encounter problems can modify it by comparison.




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325763639&siteId=291194637