apt-get 无法自动删除填满 Inode 的软件包

apt-get 无法自动删除填满 Inode 的软件包

一台旧的 Ubuntu 10.04 服务器抱怨未满足依赖关系。运行时,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 packages were automatically installed and are no longer required:
  linux-headers-2.6.32-61-server linux-headers-2.6.32-56-server linux-headers-2.6.32-44-server
  linux-headers-2.6.32-65-server linux-headers-2.6.32-53-server linux-headers-2.6.32-48-server
  linux-headers-2.6.32-62-server linux-headers-2.6.32-57-server linux-headers-2.6.32-50-server
  linux-headers-2.6.32-45-server linux-headers-2.6.32-66-server linux-headers-2.6.32-54-server
  linux-headers-2.6.32-49-server linux-headers-2.6.32-43 linux-headers-2.6.32-44 linux-headers-2.6.32-50
  linux-headers-2.6.32-45 linux-headers-2.6.32-51 linux-headers-2.6.32-46 linux-headers-2.6.32-52 linux-headers-2.6.32-47
  linux-headers-2.6.32-53 linux-headers-2.6.32-48 linux-headers-2.6.32-54 linux-headers-2.6.32-49 linux-headers-2.6.32-60
  linux-headers-2.6.32-55 linux-headers-2.6.32-61 linux-headers-2.6.32-56 linux-headers-2.6.32-62 linux-headers-2.6.32-57
  linux-headers-2.6.32-58 linux-headers-2.6.32-64 linux-headers-2.6.32-65 linux-headers-2.6.32-66 linux-headers-2.6.32-67
  linux-headers-2.6.32-58-server linux-headers-2.6.32-51-server linux-headers-2.6.32-46-server
  linux-headers-2.6.32-67-server linux-headers-2.6.32-60-server linux-headers-2.6.32-55-server
  linux-headers-2.6.32-43-server linux-headers-2.6.32-64-server linux-headers-2.6.32-52-server
  linux-headers-2.6.32-47-server
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  linux-headers-2.6.32-71 linux-headers-2.6.32-71-server
The following NEW packages will be installed:
  linux-headers-2.6.32-71 linux-headers-2.6.32-71-server
0 upgraded, 2 newly installed, 0 to remove and 43 not upgraded.
4 not fully installed or removed.
Need to get 0B/11.0MB of archives.
After this operation, 85.3MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
(Reading database ... 469386 files and directories currently installed.)
Unpacking linux-headers-2.6.32-71 (from .../linux-headers-2.6.32-71_2.6.32-71.138_all.deb) ...
dpkg: error processing /var/cache/apt/archives/linux-headers-2.6.32-71_2.6.32-71.138_all.deb (--unpack):
 unable to create `/usr/src/linux-headers-2.6.32-71/arch/arm/include/asm/limits.h.dpkg-new' (while processing `./usr/src/linux-headers-2.6.32-71/arch/arm/include/asm/limits.h'): No space left on device
No apport report written because the error message indicates a disk full error
                                                                              dpkg-deb: subprocess paste killed by signal (Broken pipe)
Unpacking linux-headers-2.6.32-71-server (from .../linux-headers-2.6.32-71-server_2.6.32-71.138_amd64.deb) ...
dpkg: error processing /var/cache/apt/archives/linux-headers-2.6.32-71-server_2.6.32-71.138_amd64.deb (--unpack):
 unable to create `/usr/src/linux-headers-2.6.32-71-server/include/config/dummy/console.h.dpkg-new' (while processing `./usr/src/linux-headers-2.6.32-71-server/include/config/dummy/console.h'): No space left on device
No apport report written because the error message indicates a disk full error
                                                                              dpkg-deb: subprocess paste killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/linux-headers-2.6.32-71_2.6.32-71.138_all.deb
 /var/cache/apt/archives/linux-headers-2.6.32-71-server_2.6.32-71.138_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

事实上系统似乎已经用完了 Inode:

$ df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda1             498736  493560    5176   99% /
none                   62559     587   61972    1% /dev
none                   63152       1   63151    1% /dev/shm
none                   63152      23   63129    1% /var/run
none                   63152       3   63149    1% /var/lock
none                   63152       1   63151    1% /lib/init/rw
none                  498736  493560    5176   99% /var/lib/ureadahead/debugfs

经过一番挖掘,我发现了过多的文件/usr/src

$ sudo find /usr/src -type f | wc -l
317741

这些是包裹的所有内容linux-headers-*

$ ls -la /usr/src
total 192
drwxrwsr-x 48 root src  4096 2015-01-20 15:15 .
drwxr-xr-x 10 root root 4096 2011-03-02 17:11 ..
drwxr-xr-x 24 root root 4096 2012-09-26 11:33 linux-headers-2.6.32-43
drwxr-xr-x  7 root root 4096 2012-09-26 11:33 linux-headers-2.6.32-43-server
drwxr-xr-x 24 root root 4096 2012-10-12 06:38 linux-headers-2.6.32-44
drwxr-xr-x  7 root root 4096 2012-10-12 06:39 linux-headers-2.6.32-44-server
drwxr-xr-x 24 root root 4096 2013-02-22 06:51 linux-headers-2.6.32-45
drwxr-xr-x  7 root root 4096 2013-02-22 06:52 linux-headers-2.6.32-45-server
drwxr-xr-x 24 root root 4096 2013-04-19 06:30 linux-headers-2.6.32-46
drwxr-xr-x  7 root root 4096 2013-04-19 06:30 linux-headers-2.6.32-46-server
drwxr-xr-x 24 root root 4096 2013-05-15 06:42 linux-headers-2.6.32-47
drwxr-xr-x  7 root root 4096 2013-05-15 06:42 linux-headers-2.6.32-47-server
drwxr-xr-x 24 root root 4096 2013-06-14 06:34 linux-headers-2.6.32-48
drwxr-xr-x  7 root root 4096 2013-06-14 06:34 linux-headers-2.6.32-48-server
drwxr-xr-x 24 root root 4096 2013-07-04 06:39 linux-headers-2.6.32-49
drwxr-xr-x  7 root root 4096 2013-07-04 06:39 linux-headers-2.6.32-49-server
drwxr-xr-x 24 root root 4096 2013-07-30 06:29 linux-headers-2.6.32-50
drwxr-xr-x  7 root root 4096 2013-07-30 06:29 linux-headers-2.6.32-50-server
drwxr-xr-x 24 root root 4096 2013-09-07 06:28 linux-headers-2.6.32-51
drwxr-xr-x  7 root root 4096 2013-09-07 06:28 linux-headers-2.6.32-51-server
drwxr-xr-x 24 root root 4096 2013-09-30 06:41 linux-headers-2.6.32-52
drwxr-xr-x  7 root root 4096 2013-09-30 06:41 linux-headers-2.6.32-52-server
drwxr-xr-x 24 root root 4096 2013-11-08 06:46 linux-headers-2.6.32-53
drwxr-xr-x  7 root root 4096 2013-11-08 06:46 linux-headers-2.6.32-53-server
drwxr-xr-x 24 root root 4096 2013-12-03 06:47 linux-headers-2.6.32-54
drwxr-xr-x  7 root root 4096 2013-12-03 06:47 linux-headers-2.6.32-54-server
drwxr-xr-x 24 root root 4096 2014-01-03 06:47 linux-headers-2.6.32-55
drwxr-xr-x  7 root root 4096 2014-01-03 06:47 linux-headers-2.6.32-55-server
drwxr-xr-x 24 root root 4096 2014-02-19 06:40 linux-headers-2.6.32-56
drwxr-xr-x  7 root root 4096 2014-02-19 06:40 linux-headers-2.6.32-56-server
drwxr-xr-x 24 root root 4096 2014-03-05 06:34 linux-headers-2.6.32-57
drwxr-xr-x  7 root root 4096 2014-03-05 06:34 linux-headers-2.6.32-57-server
drwxr-xr-x 24 root root 4096 2014-05-06 06:45 linux-headers-2.6.32-58
drwxr-xr-x  7 root root 4096 2014-05-06 06:46 linux-headers-2.6.32-58-server
drwxr-xr-x 24 root root 4096 2014-05-27 06:54 linux-headers-2.6.32-60
drwxr-xr-x  7 root root 4096 2014-05-27 06:54 linux-headers-2.6.32-60-server
drwxr-xr-x 24 root root 4096 2014-06-06 06:47 linux-headers-2.6.32-61
drwxr-xr-x  7 root root 4096 2014-06-06 06:47 linux-headers-2.6.32-61-server
drwxr-xr-x 24 root root 4096 2014-07-06 06:28 linux-headers-2.6.32-62
drwxr-xr-x  7 root root 4096 2014-07-06 06:28 linux-headers-2.6.32-62-server
drwxr-xr-x 24 root root 4096 2014-07-18 06:29 linux-headers-2.6.32-64
drwxr-xr-x  7 root root 4096 2014-07-18 06:29 linux-headers-2.6.32-64-server
drwxr-xr-x 24 root root 4096 2014-08-29 06:49 linux-headers-2.6.32-65
drwxr-xr-x  7 root root 4096 2014-08-29 06:49 linux-headers-2.6.32-65-server
drwxr-xr-x 24 root root 4096 2014-09-23 06:40 linux-headers-2.6.32-66
drwxr-xr-x  7 root root 4096 2014-09-23 06:40 linux-headers-2.6.32-66-server
drwxr-xr-x 24 root root 4096 2014-10-09 06:48 linux-headers-2.6.32-67
drwxr-xr-x  7 root root 4096 2014-10-09 06:48 linux-headers-2.6.32-67-server

但如果我要求将其删除:

$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run `apt-get -f install' to correct these.
The following packages have unmet dependencies:
  linux-headers-virtual: Depends: linux-headers-2.6.32-71-server but it is not installed or
                                  linux-headers-2.6.32-71-generic-pae but it is not installable
E: Unmet dependencies. Try using -f.

或者删除特定的包:

$ sudo apt-get remove linux-headers-2.6.32-43
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run `apt-get -f install' to correct these:
The following packages have unmet dependencies:
  linux-headers-2.6.32-43-server: Depends: linux-headers-2.6.32-43 but it is not going to be installed
  linux-headers-virtual: Depends: linux-headers-2.6.32-71-server but it is not going to be installed or
                                  linux-headers-2.6.32-71-generic-pae but it is not installable
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

这又让我回到原点。我该如何打破这个循环?我该如何删除这些旧文件,以便它apt-get能够正常工作?

更新psusi 建议直接用 删除这些包dpkg。结果如下:

$ sudo dpkg -r linux-headers-2.6.32-43
dpkg: dependency problems prevent removal of linux-headers-2.6.32-43:
 linux-headers-2.6.32-43-server depends on linux-headers-2.6.32-43.
dpkg: error processing linux-headers-2.6.32-43 (--remove):
 dependency problems - not removing
Errors were encountered while processing:
 linux-headers-2.6.32-43

答案1

apt-get坚持在做其他事情之前修复所有损坏的软件包。使用dpkg -r pkgname直接删除软件包。清除这些软件包后,运行apt-get install -f修复损坏的软件包。

相关内容