磁盘已满时如何删除未使用的软件包?

磁盘已满时如何删除未使用的软件包?

磁盘已满时如何卸载未使用的软件包?我正在尝试安装未满足的依赖项linux-headers-4.4.0-108并更新内核。

我尝试使用sudo apt-get autoremove但由于磁盘已满错误而失败。

版本:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:    16.04
Codename:   xenial

文件系统:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M   46M  350M  12% /run
/dev/xvda1      7.8G  5.0G  2.4G  69% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           396M     0  396M   0% /run/user/1000

我尝试运行时收到同样的错误sudo apt-get -f install

$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  linux-headers-4.4.0-108
The following NEW packages will be installed:
linux-headers-4.4.0-108
0 upgraded, 1 newly installed, 0 to remove and 160 not upgraded.
7 not fully installed or removed.
Need to get 0 B/9927 kB of archives.
After this operation, 70.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
  LANGUAGE = (unset),
  LC_ALL = (unset),
  LC_CTYPE = "UTF-8",
  LANG = "en_US.UTF-8"
  are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
(Reading database ... 501671 files and directories currently installed.)
Preparing to unpack .../linux-headers-4.4.0-108_4.4.0-108.131_all.deb ...
Unpacking linux-headers-4.4.0-108 (4.4.0-108.131) ...
dpkg: error processing archive /var/cache/apt/archives/linux-headers-
4.4.0-108_4.4.0-108.131_all.deb (--unpack):
  error creating directory './usr/src/linux-headers-4.4.0-
108/arch/powerpc/platforms/pasemi': No space left on device
No apport report written because the error message indicates a disk full error

dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
  /var/cache/apt/archives/linux-headers-4.4.0-108_4.4.0-108.131_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

我还发现安装了许多未使用的内核,可以将其删除以腾出更多空间,但我不确定最好的方法是什么,因为我通常使用sudo apt-get autoremove

当前的:

$ uname -r
4.4.0-93-generic

没用过:

$ dpkg --list | grep linux-image

ii  linux-image-4.4.0-101-generic    4.4.0-101.124 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-103-generic    4.4.0-103.126 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-104-generic    4.4.0-104.127 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
iU  linux-image-4.4.0-108-generic    4.4.0-108.131 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-31-generic     4.4.0-31.50 amd64   Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-78-generic     4.4.0-78.99 amd64   Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-79-generic     4.4.0-79.100 amd64  Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-81-generic     4.4.0-81.104 amd64  Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-83-generic     4.4.0-83.106 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-87-generic     4.4.0-87.110 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-89-generic     4.4.0-89.112 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-91-generic     4.4.0-91.114 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-92-generic     4.4.0-92.115 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-93-generic     4.4.0-93.116 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-96-generic     4.4.0-96.119 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-97-generic     4.4.0-97.120 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-98-generic     4.4.0-98.121 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
iU  linux-image-virtual              4.4.0.108.113 amd64 This package will always depend on the latest minimal generic kernel image.

我也刚刚尝试手动删除内核但是收到以下错误。

$ sudo apt-get purge linux-image-4.4.0-78
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'linux-image-4.4.0-78-generic' for regex 'linux-image-4.4.0-78'
Note, selecting 'linux-image-4.4.0-78-lowlatency' for regex 'linux-image-4.4.0-78'
Package 'linux-image-4.4.0-78-lowlatency' is not installed, so not removed
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
  linux-headers-4.4.0-108-generic : Depends: linux-headers-4.4.0-108 but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

inode 统计信息:

$ df -iH
Filesystem     Inodes IUsed IFree IUse% Mounted on
udev             504k   360  504k    1% /dev
tmpfs            506k   495  506k    1% /run
/dev/xvda1       525k  514k   11k   98% /
tmpfs            506k     1  506k    1% /dev/shm
tmpfs            506k     4  506k    1% /run/lock
tmpfs            506k    16  506k    1% /sys/fs/cgroup
tmpfs            506k     4  506k    1% /run/user/1000

答案1

检查你的内核头文件

您已安装了 16 个内核映像,并且在安装内核头文件时出现失败。

  • 核心图片不消耗大量的 inode,但是内核标题做。
  • 如果您安装了 16 个内核映像,请检查是否还安装了 16 组内核头文件。
  • 内核头可能会阻止内核映像被自动删除。

看看整个问题是如何聚集成一个紧密的球的?

如果您确实安装了 16 组内核映像和内核头,请使用 dpkg 删除一个包,通常会释放足够的空间让 apt 删除其余包。

答案2

你的索引节点状态显示您的服务器包含大量文件。inode 基本上是存储文件信息的文件。因此,由于大量创建/存储/不当处理文件,您的 inode 可能已被用尽。

您的服务器上是否正在运行网站?如果是,请检查创建的会话文件数量,这些文件处理得不好,或者可能有一些脚本正在大规模生成文件。

您可以使用以下脚本查找每个目录中的文件数量:

for i in /*; do echo "$i"; find "$i" |wc -l; done

您也可以在 shell 中输入上述命令。

答案3

嘿-还有另一个查尔斯格林!

因此,您的磁盘上没有文件,但您的 inode 数量几乎已满。这表明您的磁盘上某处有大量小文件。

要查找所有这些小文件,请尝试以下操作:

cd /
sudo du -a -d 1 --inodes . | sort -nr | head -20

第一个命令切换到根目录,第二个命令生成计算机上占用 inode 最多的 20 个目录的列表。例如,在我的计算机上,“/proc”使用了 266672 个 inode...

跟踪大量消耗 inode 的路径,看看是否能找到一个目录,里面全是 0 字节文件或很多非常小的文件。这就是问题所在。


有关 inode 的一些信息位于https://unix.stackexchange.com/questions/117093/find-where-inodes-are-being-used以及索引节点用尽

相关内容