ubuntu 16.04的boot区满了,如何删除(缩减版)

Short Version

注意:这个只针对于有经验的认识,你必须清楚你在删什么,不然有重装的风险;如果不清楚,请读Long version

  1. 首先看一下磁盘空间中,/boot分区的空间对不对。我用df -h,看到/boot分区已经100%的使用率。
  2. 然后在/boot分区中,直接删文件。但是注意同类的保持两个不删。
  3. 然后再执行apt-get install -f,安装新的kernel包。
  4. 最后执行apt-get autoremove,删除不用的包。
  5. 最终可以看到/boot分区不再是满的了。
'Filesystem      Size  Used Avail Use% Mounted on
udev            362M     0  362M   0% /dev
tmpfs            77M   13M   64M  17% /run
/dev/sda2        11G  3.0G  7.0G  30% /
tmpfs           381M     0  381M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           381M     0  381M   0% /sys/fs/cgroup
/dev/sda1       361M  151M  192M  44% /boot
tmpfs            77M     0   77M   0% /run/user/1000

参考链接

Long Version

背景

  1. 我想apt-get安装一个包,结果系统一直提醒我”Unmet dependencies. Try ‘apt-get -f install’ with no packages”
'You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 linux-image-extra-4.4.0-92-generic : Depends: linux-image-4.4.0-92-generic but it is not going to be installed
 linux-image-generic : Depends: linux-image-4.4.0-92-generic but it is not going to be installed
                       Recommends: thermald but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

Trouble Shooting

  1. 于是我就按照系统提示,运行apt-get -f install,结果系统还是报错,安装不上,提示以下信息。其中重要的是 No apport report written because the error message indicates a disk full error,貌似是磁盘空间满了
Unpacking linux-image-4.4.0-93-generic (4.4.0-93.116) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-93-generic_4.4.0-93.116_i386.deb (--unpack):
 cannot copy extracted data for './boot/vmlinuz-4.4.0-93-generic' to '/boot/vmlinuz-4.4.0-93-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
  1. 接下来df -h,发现果然有一个分区满了,那就是/boot分区,已经100%了。
root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            362M     0  362M   0% /dev
tmpfs            77M   12M   65M  16% /run
/dev/sda2        11G  5.1G  4.9G  51% /
tmpfs           381M     0  381M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           381M     0  381M   0% /sys/fs/cgroup
/dev/sda1       361M  357M     0 100% /boot
tmpfs            77M     0   77M   0% /run/user/1000
  1. cd /boot之后,再ls可以得到每个文件的大小,得到以下的信息。大概有个印象是要去删除initrd.img,因为它的盘符最大。不确定哪些可以删除,于是参考了这个stackexchange链接

解决方法

接着上面,解决方法是:

  1. 根据apt-get install -f中的no longer required提示The following packages were automatically installed and are no longer required: ,删掉这个列表中对应的/boot分区的文档。
  2. 又因为initrd.img 开头的文档最大(38M),所以删除这个。另外也可以删除对应版本中的vmlinuz, System.map, abi, config等文档。
  3. 其中,至少要保证两个版本的所有类型文档都还保留着,不然等着重装系统吧。
  4. 然后空间够了,就可以重新通过apt-get install -f来安装了。

如何删除文件的英文原文如下原文在这个stackexchange链接

Freeing Up Space on the /boot File System

The Original Poster has a separate /boot partition, and that is what is full and preventing the apt system from working. It will be necessary for him to free up space there.

If there almost enough space, go to /boot and remove a config file or two:

sudo rm config-3.2.0-19-generic-pae

  1. for example, but using the name of one of the kernel versions you intend to remove anyway. This will free up a little space (about 144K apiece).
  2. If you need more space individually remove old vmlinuz initrd, abi and System.map files until you have enough space (about 22 megs for one of my i386 kernel versions).
  3. Whatever you do, don’t remove them all. You should at least keep the latest two matching versions of each kind of file, for each kind of kernel you use.

断后

最后可以做一个apt-get autoremove做cleanup。我竟然删除了1.9G的文件,看来老版本很耗存储空间呢。