由于 apt-get 损坏,无法更新我的 VPS 或进行任何安装

由于 apt-get 损坏,无法更新我的 VPS 或进行任何安装

第一次在这里发帖,因为我通常能够在谷歌的帮助下解决我的问题,但这次我觉得我有点麻烦。

我有一个在 DigitalOcean 上运行的 VPS,用于个人项目。我很久以前就设置好了它,我想它可能是 DO 为我预先安装的。它运行的是 Ubuntu 14.04,所以我决定是时候升级它了——这是一个大错误。

sudo apt-get update && sudo apt-get upgrade我在运行之前进行了一些随意的更新sudo do-release-upgrade

其中一个问题出现了——似乎apt-get remove无法删除旧内核版本?但我可能完全误读了这些信息,因为遗憾的是,我对 Linux 更新并不那么熟练。

我将尝试列出我读过的所有可能有用的命令输出。任何关于如何摆脱这种困境的提示都将不胜感激。

df -hT输出:

root@web:~# df -hT

Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  487M  4.0K  487M   1% /dev
tmpfs          tmpfs     100M  344K  100M   1% /run
/dev/vda1      ext4       20G  4.7G   14G  25% /
none           tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
none           tmpfs     5.0M     0  5.0M   0% /run/lock
none           tmpfs     497M     0  497M   0% /run/shm
none           tmpfs     100M     0  100M   0% /run/user

看来我对服务器空间很满意

sudo apt-get autoremovesudo apt-get remove --purge --auto-remove输出:

root@web:~# 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-image-3.13.0-79-generic : Depends: initramfs-tools (>= 0.36ubuntu6) but it is not installed
                                 Recommends: grub-pc or
                                             grub-efi-amd64 or
                                             grub-efi-ia32 or
                                             grub but it is not installed or
                                             lilo (>= 19.1) but it is not installed
 linux-image-3.13.0-83-generic : Depends: initramfs-tools (>= 0.36ubuntu6) but it is not installed
                                 Recommends: grub-pc or
                                             grub-efi-amd64 or
                                             grub-efi-ia32 or
                                             grub but it is not installed or
                                             lilo (>= 19.1) but it is not installed
E: Unmet dependencies. Try using -f.

带有修复标志的自动删除:

root@web:~# sudo apt-get -f autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  bash-completion cloud-guest-utils coreutils dpkg ifupdown
  init-system-helpers initramfs-tools initramfs-tools-bin initramfs-tools-core
  initscripts klibc-utils libalgorithm-diff-xs-perl libapparmor-perl libblkid1
  libdbd-mysql-perl libdbi-perl libfdisk1 libfile-fcntllock-perl libgcrypt20
  libgpg-error0 libklibc liblocale-gettext-perl libmount1 libmysqlclient20
  libncurses5 libncursesw5 libperl5.22 libselinux1 libsmartcols1
  libsub-name-perl libsystemd0 libtext-charwidth-perl libtext-iconv-perl
  libtinfo5 libudev1 lsb-base perl perl-base perl-modules-5.22 rename
  sysvinit-utils udev util-linux
Suggested packages:
  rdnssd libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl
  rng-tools perl-doc libterm-readline-gnu-perl libterm-readline-perl-perl
  bootlogd sash kbd console-tools util-linux-locales
The following packages will be REMOVED:
  libterm-readkey-perl libtext-soundex-perl linux-headers-3.13.0-79
  linux-headers-3.13.0-79-generic linux-image-3.13.0-79-generic
  linux-image-extra-3.13.0-79-generic mysql-client-5.5 perl-modules
The following NEW packages will be installed:
  initramfs-tools initramfs-tools-core libfdisk1 libgcrypt20 libmysqlclient20
  libperl5.22 libsmartcols1 libsystemd0 perl-modules-5.22 rename udev
The following packages will be upgraded:
  bash-completion cloud-guest-utils coreutils dpkg ifupdown
  init-system-helpers initramfs-tools-bin initscripts klibc-utils
  libalgorithm-diff-xs-perl libapparmor-perl libblkid1 libdbd-mysql-perl
  libdbi-perl libfile-fcntllock-perl libgpg-error0 libklibc
  liblocale-gettext-perl libmount1 libncurses5 libncursesw5 libselinux1
  libsub-name-perl libtext-charwidth-perl libtext-iconv-perl libtinfo5
  libudev1 lsb-base perl perl-base sysvinit-utils util-linux
32 upgraded, 11 newly installed, 8 to remove and 277 not upgraded.
4 not fully installed or removed.
Need to get 0 B/16.2 MB of archives.
After this operation, 279 MB disk space will be freed.
Do you want to continue? [Y/n] Y
Extracting templates from packages: 100%
(Reading database ... 143659 files and directories currently installed.)
Removing linux-image-extra-3.13.0-79-generic (3.13.0-79.123) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-79-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-79-generic /boot/vmlinuz-3.13.0-79-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-79-generic /boot/vmlinuz-3.13.0-79-generic
/etc/kernel/postinst.d/initramfs-tools: 33: /etc/kernel/postinst.d/initramfs-tools: update-initramfs: not found
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 127
dpkg: error processing package linux-image-extra-3.13.0-79-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-3.13.0-79-generic (3.13.0-79.123) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-79-generic /boot/vmlinuz-3.13.0-79-generic
/etc/kernel/postrm.d/initramfs-tools: 33: /etc/kernel/postrm.d/initramfs-tools: update-initramfs: not found
run-parts: /etc/kernel/postrm.d/initramfs-tools exited with return code 127
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-3.13.0-79-generic.postrm line 328.
dpkg: error processing package linux-image-3.13.0-79-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-3.13.0-79-generic
 linux-image-3.13.0-79-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo apt-get -f install输出:

root@web:~# sudo apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  bash-completion cloud-guest-utils coreutils dpkg ifupdown
  init-system-helpers initramfs-tools initramfs-tools-bin initramfs-tools-core
  initscripts klibc-utils libalgorithm-diff-xs-perl libapparmor-perl libblkid1
  libdbd-mysql-perl libdbi-perl libfdisk1 libfile-fcntllock-perl libgcrypt20
  libgpg-error0 libklibc liblocale-gettext-perl libmount1 libmysqlclient20
  libncurses5 libncursesw5 libperl5.22 libselinux1 libsmartcols1
  libsub-name-perl libsystemd0 libtext-charwidth-perl libtext-iconv-perl
  libtinfo5 libudev1 lsb-base perl perl-base perl-modules-5.22 rename
  sysvinit-utils udev util-linux
Suggested packages:
  rdnssd libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl
  rng-tools perl-doc libterm-readline-gnu-perl libterm-readline-perl-perl
  bootlogd sash kbd console-tools util-linux-locales
The following packages will be REMOVED:
  libterm-readkey-perl libtext-soundex-perl linux-image-3.13.0-79-generic
  linux-image-extra-3.13.0-79-generic mysql-client-5.5 perl-modules
The following NEW packages will be installed:
  initramfs-tools initramfs-tools-core libfdisk1 libgcrypt20 libmysqlclient20
  libperl5.22 libsmartcols1 libsystemd0 perl-modules-5.22 rename udev
The following packages will be upgraded:
  bash-completion cloud-guest-utils coreutils dpkg ifupdown
  init-system-helpers initramfs-tools-bin initscripts klibc-utils
  libalgorithm-diff-xs-perl libapparmor-perl libblkid1 libdbd-mysql-perl
  libdbi-perl libfile-fcntllock-perl libgpg-error0 libklibc
  liblocale-gettext-perl libmount1 libncurses5 libncursesw5 libselinux1
  libsub-name-perl libtext-charwidth-perl libtext-iconv-perl libtinfo5
  libudev1 lsb-base perl perl-base sysvinit-utils util-linux
32 upgraded, 11 newly installed, 6 to remove and 277 not upgraded.
4 not fully installed or removed.
Need to get 0 B/16.2 MB of archives.
After this operation, 202 MB disk space will be freed.
Do you want to continue? [Y/n] Y
Extracting templates from packages: 100%
(Reading database ... 143659 files and directories currently installed.)
Removing linux-image-extra-3.13.0-79-generic (3.13.0-79.123) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-79-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-79-generic /boot/vmlinuz-3.13.0-79-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-79-generic /boot/vmlinuz-3.13.0-79-generic
/etc/kernel/postinst.d/initramfs-tools: 33: /etc/kernel/postinst.d/initramfs-tools: update-initramfs: not found
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 127
dpkg: error processing package linux-image-extra-3.13.0-79-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-3.13.0-79-generic (3.13.0-79.123) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-79-generic /boot/vmlinuz-3.13.0-79-generic
/etc/kernel/postrm.d/initramfs-tools: 33: /etc/kernel/postrm.d/initramfs-tools: update-initramfs: not found
run-parts: /etc/kernel/postrm.d/initramfs-tools exited with return code 127
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-3.13.0-79-generic.postrm line 328.
dpkg: error processing package linux-image-3.13.0-79-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-3.13.0-79-generic
 linux-image-3.13.0-79-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

ls -l /boot输出:

root@web:~# ls -l /boot
total 70752
-rw-r--r-- 1 root root  1165578 Mar 10  2016 abi-3.13.0-83-generic
-rw-r--r-- 1 root root   166221 May  9  2019 config-3.13.0-170-generic
-rw-r--r-- 1 root root   165918 Mar 10  2016 config-3.13.0-83-generic
-rw-r--r-- 1 root root   191071 Nov 13 22:00 config-4.4.0-170-generic
drwxr-xr-x 5 root root     4096 Dec 29 08:09 grub
-rw-r--r-- 1 root root 20352301 Dec 29 08:05 initrd.img-3.13.0-170-generic
-rw-r--r-- 1 root root 20176312 Dec 29 08:05 initrd.img-3.13.0-79-generic
-rw-r--r-- 1 root root   176500 Mar 12  2014 memtest86+.bin
-rw-r--r-- 1 root root   178176 Mar 12  2014 memtest86+.elf
-rw-r--r-- 1 root root   178680 Mar 12  2014 memtest86+_multiboot.bin
-rw------- 1 root root  3418683 May  9  2019 System.map-3.13.0-170-generic
-rw------- 1 root root  3393725 Mar 10  2016 System.map-3.13.0-83-generic
-rw------- 1 root root  3913902 Nov 13 22:00 System.map-4.4.0-170-generic
-rw------- 1 root root  5909496 May 14  2019 vmlinuz-3.13.0-170-generic
-rw------- 1 root root  5827776 Mar 10  2016 vmlinuz-3.13.0-83-generic
-rw------- 1 root root  7208856 Nov 14 10:33 vmlinuz-4.4.0-170-generic

uname -a输出:

root@web:~# uname -a
Linux web 3.13.0-83-generic #127-Ubuntu SMP Fri Mar 11 00:25:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

dpkg -l | grep linux-image输出:

root@web:~# dpkg -l | grep linux-image
ii  linux-image-3.13.0-170-generic          3.13.0-170.220                                  amd64        Signed kernel image generic
rc  linux-image-3.13.0-77-generic           3.13.0-77.121                                   amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rH  linux-image-3.13.0-79-generic           3.13.0-79.123                                   amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
iU  linux-image-3.13.0-83-generic           3.13.0-83.127                                   amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
iF  linux-image-4.4.0-170-generic           4.4.0-170.199                                   amd64        Signed kernel image generic
rc  linux-image-extra-3.13.0-77-generic     3.13.0-77.121                                   amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rH  linux-image-extra-3.13.0-79-generic     3.13.0-79.123                                   amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-generic                     4.4.0.170.178                                   amd64        Generic Linux kernel image

dpkg -l | egrep -v '^ii|rc'输出:

root@web:~# dpkg -l | egrep -v '^ii|rc'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
+++-=======================================-===============================================-============-===============================================================================
rH  linux-image-3.13.0-79-generic           3.13.0-79.123                                   amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rH  linux-image-3.13.0-83-generic           3.13.0-83.127                                   amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
iF  linux-image-4.4.0-170-generic           4.4.0-170.199                                   amd64        Signed kernel image generic
rH  linux-image-extra-3.13.0-79-generic     3.13.0-79.123                                   amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP

答案1

情况没有我想象的那么糟糕。好的,让我们尝试修复它。

首先,确实要备份你的重要数据。

确保您有足够的可用空间和 inode。

df -h;df -i

下一步是重新安装 initramfs-tools。未找到命令 update-initramfs,但这是必需的。

sudo apt install --reinstall initramfs-tools=0.122ubuntu8.16

根据软件包搜索,这是 xenial 版本,它位于 xenial-updates 中。

如果不行的话直接用wget提取包

wget -c http://mirrors.kernel.org/ubuntu/pool/main/i/initramfs-tools/initramfs-tools_0.122ubuntu8.16_all.deb

并使用 dpkg 安装它。

 sudo dpkg -i initramfs-tools_0.122ubuntu8.16_all.deb

仅当其运行时没有错误。

sudo dpkg --configure -a && sudo apt-get -f install

检查

dpkg -l | egrep -v '^ii|rc'

如果所有包裹都处于干净状态。应该和我的一样。

Desired=Unknown/Install/Remove/Purge/Hold                                                                                                                    
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend                                                                               
+++-=============================================-========================================-============-===============================================================================                                                                                                                                   

然后您就可以准备升级了。

sudo apt-get update && sudo apt-get dist-upgrade

如果出现任何问题,请告知我们。

答案2

Ubuntu 14.04 过渡至延长支持维护2019 年 5 月内核版本更新通常由单个元包处理,而不是直接手动安装特定版本。您应该遵循生命周期结束升级说明来自 Ubuntu 社区帮助 wiki,其中描述了如何升级现在不受支持的已安装版本。

相关内容