虚假磁盘已满错误: apt-get 无法安装或删除

在升级我的Ubuntu 12.04服务器时,我遇到了以下错误。现在apt-get无法安装或删除任何软件包。
解压缩linux-headers-3.13.0-62(来自.../linux-headers-3.13.0-62_3.13.0-62.102~precise1_all.deb)... 处理/var/cache/apt/archives/linux-headers-3.13.0-62_3.13.0-62.102~precise1_all.deb时出错: 无法创建`/usr/src/linux-headers-3.13.0-62/arch/arm/include/asm/ptrace.h.dpkg-new' (在处理`./usr/src/linux-headers-3.13.0-62/arch/arm/include/asm/ptrace.h'时):设备上没有剩余空间 未写入任何apport报告,因为错误消息指示磁盘已满 dpkg-deb: 错误: 子进程paste被信号终止(Broken pipe) 处理过程中遇到错误: /var/cache/apt/archives/linux-headers-3.13.0-62_3.13.0-62.102~precise1_all.deb E: 子进程/usr/bin/dpkg返回错误代码(1)
虽然我并没有真正的磁盘空间不足,
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       6.8G  4.7G  1.8G  69% /  

无论如何,我的索引节点已满。
# df -i
Filesystem     Inodes   IUsed  IFree IUse% Mounted on
/dev/sda1      458752  455214   3538  100% /

我有十多个旧内核,但由于我的apt-get本身不好用,所以我无法删除它们。因此,我无法按照这篇帖子中报告的类似问题进行操作。

唯一的选择似乎是手动删除一些旧内核。这会引起任何问题吗?

有没有更好的方法?我能否暂时使用root保留空间并删除旧内核?


1确实,我手动从/usr/src中删除了几个旧内核,以摆脱这种情况。幸运的是一切顺利,apt又开始工作了。但是在对生产机器进行此类操作之前,请务必备份数据。我是在一个有完整备份的虚拟机上进行的操作。 - sourav c.
它有效!我在这里做了相同的事情(ubutu 14.04.1),以更新到内核4.4.0-51-generic。我只是不确定它是否会在将来引起任何问题。谢谢。 - Moreno
2个回答

I know this post is a bit old, but I found an answer here for anybody that may stumble upon this post: https://help.ubuntu.com/community/RemoveOldKernels

In case that link is broken, here is the relevant snippet:

Safely Removing Old Kernels

For users of LVM systems, encrypted systems or limited-storage systems, the most frequent problem is that the /boot partition is simply full. The package manager cannot install a pending upgrade due to lack of space. Besides, apt-get can not remove a package due to broken dependency.

This problem can be fixed quickly and easily from the shell. Simply identify one or two old kernels to remove manually, which will provide the package manager enough space to install the queued upgrade.


$ sudo rm -rv ${TMPDIR:-/var/tmp}/mkinitramfs-*  
                                  ## In Ubuntu 16.04 and earlier there may be leftover temporary
                                  ## files to delete.
                                  ## See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=814345

$ uname -r                        ## This command identifies the currently-running kernel
4.2.0-21-generic                  ## This is the current kernel.
                                  ## DO NOT REMOVE it!

$ dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r)
                                  ## This command lists all the kernels excluding the booted
                                  ## kernel in the package database, and their status.
rc  linux-image-4.2.0-14-generic  ## The oldest kernel in the database
                                  ## Status 'rc' means it's already been removed
ii  linux-image-4.2.0-15-generic  ## The oldest installed kernel. Eligible for removal.
                                  ## Status 'ii' means Installed.
ii  linux-image-4.2.0-16-generic  ## Another old installed kernel. Eligible for removal
ii  linux-image-4.2.0-18-generic  ## Another old installed kernel. Eligible for removal
ii  linux-image-4.2.0-19-generic  ## The previous good kernel. Keep
iU  linux-image-4.2.0-22-generic  ## DO NOT REMOVE. Status 'iU' means it's not installed,
                                  ## but queued for install in apt.
                                  ## This is the package we want apt to install.
## Purge the oldest kernel package using dpkg instead of apt. ## First you need to remove the image initrd.img file manually ## due to Bug #1678187. $ 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 tells the name ## of the package. Purge it first.
## Also purge the respective header package. $ sudo dpkg --purge linux-headers-4.2.0-15-generic ## Try also purging the common header package. $ sudo dpkg --purge linux-headers-4.2.0-15 ## Do not worry, if the previous command fails. $ sudo apt-get -f install ## Try to fix the broken dependency.

I followed this with:

sudo apt-get autoremove --purge


如果当前的内核版本(通过uname -r命令找到)比当前安装的版本要旧,会怎么样呢?例如,我发现当前版本是5.4.0-71-generic,但已安装的版本是...-74-generic...-77-generic(而iU版本是...-80-generic)。 - Saaru Lindestøkke

我发现了解决问题的方法,并从/usr/src中删除了几个旧内核,以摆脱困境。幸运的是,一切顺利,apt又开始正常工作了。
强烈建议在生产机器上删除旧内核之前进行备份。

任何更好的解决方案仍然受欢迎。我将此评论发布为答案,因为它可能对某人有所帮助。这是我的评论链接 - sourav c.
1删除了一些旧内核并运行了apt-get autoremove,然后安装了一些依赖项apt-get -f install来解决我的问题。 - Thamaraiselvam
谢谢。我在/boot下删除了所有的linux-*文件,但没有使用dkpg命令,所以/usr/src目录下仍然存在*-header文件。 - Dylan Pierce

  • 相关问题