安全删除旧内核

安全删除旧内核

升级 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)...
dpkg: 处理 /var/cache/apt/archives/linux-headers-3.13.0-62_3.13.0-62.102~precise1_all.deb (--unpack) 时出错:
 无法创建“/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”时):设备上没有剩余空间
没有写报告,因为错误消息表明磁盘已满
 dpkg-deb:错误:子进程 paste 被信号终止(管道断裂)
处理时遇到错误:
 /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% /  

无论如何我的 inode 已经满了,

# df -i
Filesystem     Inodes   IUsed  IFree IUse% Mounted on
/dev/sda1      458752  455214   3538  100% /

我有十多个旧内核,但我无法删除它们,因为我的内核apt-get本身就很差劲。所以我无法跟进这个帖子报告了类似的问题。

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

有没有更好的办法?我可以使用为 root 保留空间暂时删除旧内核?

答案1

我知道这篇文章有点旧了,但我在这里为任何可能偶然发现这篇文章的人找到了答案:https://help.ubuntu.com/community/RemoveOldKernels

如果该链接坏了,以下是相关代码片段:

安全删除旧内核

对于 LVM 系统、加密系统或有限存储系统的用户来说,最常见的问题是 /boot 分区已满。由于空间不足,软件包管理器无法安装待处理的升级。此外,apt-get 无法删除因依赖关系中断而导致的软件包。

这个问题可以通过 shell 快速轻松地修复。只需手动识别一两个旧内核并删除,这将为包管理器提供足够的空间来安装排队的升级。


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

我接着说:

sudo apt-get autoremove --purge

答案2

我找到了摆脱这种情况的方法,并删除了几个较旧的内核以/usr/src摆脱这种情况。幸运的是,一切进展顺利,apt 又开始工作了。

强烈建议在生产机器上删除旧内核之前进行备份。

相关内容