![由于无法运行“apt-get -f install”,我无法升级 Ubuntu 或自动清理](https://linux22.com/image/1009017/%E7%94%B1%E4%BA%8E%E6%97%A0%E6%B3%95%E8%BF%90%E8%A1%8C%E2%80%9Capt-get%20-f%20install%E2%80%9D%EF%BC%8C%E6%88%91%E6%97%A0%E6%B3%95%E5%8D%87%E7%BA%A7%20Ubuntu%20%E6%88%96%E8%87%AA%E5%8A%A8%E6%B8%85%E7%90%86.png)
我无法通过运行自动清理来清理磁盘空间,也无法升级,因为系统不断要求我运行apt-get -f install
,但由于磁盘已满,因此无法安装。自动清理不起作用,清除不起作用。以下是我尝试运行升级时的结果:
agiles@agiles-23-1015:~$ sudo apt-get upgrade
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-image-extra-4.4.0-128-generic : Depends: linux-image-4.4.0-128-generic but it is not installed
linux-image-extra-4.4.0-130-generic : Depends: linux-image-4.4.0-130-generic but it is not installed
linux-image-extra-4.4.0-131-generic : Depends: linux-image-4.4.0-131-generic but it is not installed
linux-image-generic : Depends: linux-image-4.4.0-131-generic but it is not installed
E: Unmet dependencies. Try using -f.
当我运行-f install时:
agiles@agiles-23-1015:~$ 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-4.4.0-124 linux-headers-4.4.0-124-generic linux-headers-4.4.0-128 linux-headers-4.4.0-128-generic linux-headers-4.4.0-130
linux-headers-4.4.0-130-generic linux-image-4.4.0-124-generic linux-image-4.4.0-128-generic linux-image-4.4.0-130-generic linux-image-extra-4.4.0-124-generic
linux-image-extra-4.4.0-128-generic linux-image-extra-4.4.0-130-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
linux-image-4.4.0-128-generic linux-image-4.4.0-130-generic linux-image-4.4.0-131-generic
Suggested packages:
fdutils linux-doc-4.4.0 | linux-source-4.4.0 linux-tools
The following NEW packages will be installed:
linux-image-4.4.0-128-generic linux-image-4.4.0-130-generic linux-image-4.4.0-131-generic
0 upgraded, 3 newly installed, 0 to remove and 194 not upgraded.
7 not fully installed or removed.
Need to get 0 B/66.4 MB of archives.
After this operation, 204 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 425417 files and directories currently installed.)
Preparing to unpack .../linux-image-4.4.0-131-generic_4.4.0-131.157_amd64.deb ...
Examining /etc/kernel/preinst.d/
run-parts: executing /etc/kernel/preinst.d/intel-microcode 4.4.0-131-generic /boot/vmlinuz-4.4.0-131-generic
Done.
Unpacking linux-image-4.4.0-131-generic (4.4.0-131.157) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-131-generic_4.4.0-131.157_amd64.deb (--unpack):
cannot copy extracted data for './boot/vmlinuz-4.4.0-131-generic' to '/boot/vmlinuz-4.4.0-131-generic.dpkg-new': failed to write (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)
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-131-generic /boot/vmlinuz-4.4.0-131-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-131-generic /boot/vmlinuz-4.4.0-131-generic
Preparing to unpack .../linux-image-4.4.0-128-generic_4.4.0-128.154_amd64.deb ...
Examining /etc/kernel/preinst.d/
run-parts: executing /etc/kernel/preinst.d/intel-microcode 4.4.0-128-generic /boot/vmlinuz-4.4.0-128-generic
Done.
Unpacking linux-image-4.4.0-128-generic (4.4.0-128.154) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-128-generic_4.4.0-128.154_amd64.deb (--unpack):
cannot copy extracted data for './boot/vmlinuz-4.4.0-128-generic' to '/boot/vmlinuz-4.4.0-128-generic.dpkg-new': failed to write (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)
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-128-generic /boot/vmlinuz-4.4.0-128-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-128-generic /boot/vmlinuz-4.4.0-128-generic
Preparing to unpack .../linux-image-4.4.0-130-generic_4.4.0-130.156_amd64.deb ...
Examining /etc/kernel/preinst.d/
run-parts: executing /etc/kernel/preinst.d/intel-microcode 4.4.0-130-generic /boot/vmlinuz-4.4.0-130-generic
Done.
Unpacking linux-image-4.4.0-130-generic (4.4.0-130.156) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-130-generic_4.4.0-130.156_amd64.deb (--unpack):
cannot copy extracted data for './boot/vmlinuz-4.4.0-130-generic' to '/boot/vmlinuz-4.4.0-130-generic.dpkg-new': failed to write (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)
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-130-generic /boot/vmlinuz-4.4.0-130-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-130-generic /boot/vmlinuz-4.4.0-130-generic
Errors were encountered while processing:
/var/cache/apt/archives/linux-image-4.4.0-131-generic_4.4.0-131.157_amd64.deb
/var/cache/apt/archives/linux-image-4.4.0-128-generic_4.4.0-128.154_amd64.deb
/var/cache/apt/archives/linux-image-4.4.0-130-generic_4.4.0-130.156_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
答案1
不过,这是一个有点老的问题了...正如@vanadium 提到的,您的分区可能空间不足/boot
。因此,需要进行清理。
我清理启动的方法是这样的:
cd /boot
sudo find . -maxdepth 1 -not -type d -not -name "*-4.4.0-116-*" -delete
替换4.4.0-116
为当前正在使用的内核。您可以使用 来确定uname -r
。在本例中,4.4.0-116
是我正在清理的服务器上的当前内核。
PS:不要忘记更新 grub。
sudo update-grub
答案2
您可能有一个单独的 /boot 分区,或者一个非常小的根分区。不幸的是,Ubuntu 升级不会自动删除内核。因此,空间有限,可能会填满,甚至可能让您无法再使用 apt 工具删除旧内核。
如果您的 Ubuntu 只有一个分区,其中包含系统和数据(您的主文件夹),那么只需暂时移走数据,以便 apt 工具有磁盘空间可以工作。否则,请继续阅读。
- 首先尝试直接从 /boot 目录中删除与最旧内核相关的文件。请参阅这个 Askbuntu 问题. 这应该会在 /boot 上释放足够的空间,以便 apt 工具完成其余的清理工作。
- 然后使用命令完成中断的安装
sudo apt-get -f install
。这将安装最新的内核并使软件包再次处于一致状态。 - 此后,用来
sudo apt autoremove
自动清除剩余的旧内核,除了倒数第二个内核。
如果一切正常,请记住定期发出“sudo apt autoremove”。遗憾的是,Ubuntu 不会自动执行此操作。