升级时 dpkg 错误:找不到 dpkg-preconfigure

升级时 dpkg 错误:找不到 dpkg-preconfigure

我正在运行 Ubuntu 服务器 16.04.3。我启用了安全更新的自动安装。今天早上,服务器被关闭(不知道为什么,它应该正在运行)。重新启动后,我尝试使用更新它apt-get dist-upgrade。它给了我以下错误:

Fetched 351 kB in 0s (1 760 kB/s)           
/bin/sh: 1: /usr/sbin/dpkg-preconfigure: not found
dpkg: warning: files list file for package 'libpam-runtime' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'python3.5' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libpython3-stdlib:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'makedev' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libnettle6:amd64' missing; assuming package has no files currently installed
dpkg: unrecoverable fatal error, aborting:
 unable to open files list file for package 'libicu55:amd64': No such device or address
E: Sub-process /usr/bin/dpkg returned an error code (2)

然后我假设当服务器因未知原因关闭时正在安装某些东西。我尝试过了apt-get install -f。它给了我以下内容:

/bin/sh: 1: /usr/sbin/dpkg-preconfigure: not found
Setting up linux-firmware (1.157.16) ...
/usr/sbin/update-initramfs: 233: /usr/sbin/update-initramfs: linux-version: not found
dpkg: error processing package linux-firmware (--configure):
 subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
 linux-firmware
E: Sub-process /usr/bin/dpkg returned an error code (1)

系统上存在 dpkg-preconfigure

root@lelouch:~# whereis dpkg-preconfigure
dpkg-preconfigure: /usr/sbin/dpkg-preconfigure /usr/share/man/man8/dpkg-preconfigure.8.gz

linux-version 也存在但无法执行

root@lelouch:~# whereis linux-version
linux-version: /usr/bin/linux-version /usr/share/man/man1/linux-version.1.gz
root@lelouch:~# /usr/bin/linux-version
bash: /usr/bin/linux-version: /usr/bin/perl: bad interpreter: No such file or directory

dpkg -C 给出以下内容

root@lelouch:~# dpkg -C
The following packages are only half configured, probably due to problems
configuring them the first time.  The configuration should be retried using
dpkg --configure <package> or the configure menu option in dselect:
 linux-firmware       Firmware for Linux kernel drivers

The following packages are missing the list control file in the
database, they need to be reinstalled:
 libc-bin             GNU C Library: Binaries
 libdns-export162     Exported DNS Shared Library
 libgtk2.0-common     common files for the GTK+ graphical user interface librar
 libidn11:amd64       GNU Libidn library, implementation of IETF IDN specificat
 libisc-export160     Exported ISC Shared Library
 libncursesw5:amd64   shared libraries for terminal handling (wide character su
 libnettle6:amd64     low level cryptographic library (symmetric and one-way cr
 libnewt0.52:amd64    Not Erik's Windowing Toolkit - text mode windowing with s
 libnih1:amd64        NIH Utility Library
 libp11-kit0:amd64    library for loading and coordinating access to PKCS#11 mo
 libpam-modules:amd64 Pluggable Authentication Modules for PAM
 libpam-modules-bin   Pluggable Authentication Modules for PAM - helper binarie
 libpam-runtime       Runtime support for the PAM library
 libpam0g:amd64       Pluggable Authentication Modules library
 libpcre3:amd64       Perl 5 Compatible Regular Expression Library - runtime fi
 libpng12-0:amd64     PNG library - runtime
 libpopt0:amd64       lib for parsing cmdline parameters
 libprocps4:amd64     library for accessing process information from /proc
 libpython3-stdlib:amd64 interactive high-level object-oriented language (default 
 libpython3.5:amd64   Shared Python runtime library (version 3.5)
 libreadline6:amd64   GNU readline and history libraries, run-time libraries
 libseccomp2:amd64    high level interface to Linux seccomp filter
 libselinux1:amd64    SELinux runtime shared libraries
 libsemanage-common   Common files for SELinux policy management libraries
 libsemanage1:amd64   SELinux policy management library
 libsepol1:amd64      SELinux library for manipulating binary security policies
 libslang2:amd64      S-Lang programming library - runtime version
 libsqlite3-0:amd64   SQLite 3 shared library
 libssl1.0.0:amd64    Secure Sockets Layer toolkit - shared libraries
 libtasn1-6:amd64     Manage ASN.1 structures (runtime)
 libtext-charwidth-perl get display widths of characters on the terminal
 libustr-1.0-1:amd64  Micro string library: shared library
 libuuid1:amd64       Universally Unique ID library
 libxtables11:amd64   netfilter xtables library
 linux-base           Linux image base package
 login                system login tools
 logrotate            Log rotation utility
 lsb-base             Linux Standard Base init script functionality
 lsb-release          Linux Standard Base version reporting utility
 makedev              creates device files in /dev
 mawk                 a pattern scanning and text processing language
 mime-support         MIME files 'mime.types' & 'mailcap', and support programs
 mount                tools for mounting and manipulating filesystems
 ncurses-bin          terminal-related programs and man pages
 net-tools            NET-3 networking toolkit
 netbase              Basic TCP/IP networking system
 netcat-openbsd       TCP/IP swiss army knife
 python3.5            Interactive high-level object-oriented language (version 
 systemd              system and service manager
 udev                 /dev/ and hotplug management daemon

The following packages are missing the md5sums control file in the
database, they need to be reinstalled:
 libncursesw5:amd64   shared libraries for terminal handling (wide character su
 libnettle6:amd64     low level cryptographic library (symmetric and one-way cr
 libnewt0.52:amd64    Not Erik's Windowing Toolkit - text mode windowing with s
 libnih1:amd64        NIH Utility Library
 libp11-kit0:amd64    library for loading and coordinating access to PKCS#11 mo
 libpam-modules:amd64 Pluggable Authentication Modules for PAM
 libpam-modules-bin   Pluggable Authentication Modules for PAM - helper binarie
 libpam-runtime       Runtime support for the PAM library
 libpam0g:amd64       Pluggable Authentication Modules library
 libpcre3:amd64       Perl 5 Compatible Regular Expression Library - runtime fi
 libpng12-0:amd64     PNG library - runtime
 libpopt0:amd64       lib for parsing cmdline parameters
 libprocps4:amd64     library for accessing process information from /proc
 libpython3-stdlib:amd64 interactive high-level object-oriented language (default 
 libreadline6:amd64   GNU readline and history libraries, run-time libraries
 libselinux1:amd64    SELinux runtime shared libraries
 libsemanage-common   Common files for SELinux policy management libraries
 libsemanage1:amd64   SELinux policy management library
 libsepol1:amd64      SELinux library for manipulating binary security policies
 libslang2:amd64      S-Lang programming library - runtime version
 libsmartcols1:amd64  smart column output alignment library
 libsqlite3-0:amd64   SQLite 3 shared library
 libss2:amd64         command-line interface parsing library
 libtext-charwidth-perl get display widths of characters on the terminal
 libtxc-dxtn-s2tc0:amd64 Texture compression library for Mesa
 libustr-1.0-1:amd64  Micro string library: shared library
 libuuid1:amd64       Universally Unique ID library
 linux-base           Linux image base package
 login                system login tools
 logrotate            Log rotation utility
 lsb-base             Linux Standard Base init script functionality
 lsb-release          Linux Standard Base version reporting utility
 makedev              creates device files in /dev
 mawk                 a pattern scanning and text processing language
 mime-support         MIME files 'mime.types' & 'mailcap', and support programs
 mount                tools for mounting and manipulating filesystems
 ncurses-base         basic terminal type definitions
 ncurses-bin          terminal-related programs and man pages
 net-tools            NET-3 networking toolkit
 netbase              Basic TCP/IP networking system
 netcat-openbsd       TCP/IP swiss army knife

我猜断电把一切都搞乱了。关于它的一些背景知识。服务器位于由 proxmox 运行的虚拟机中。磁盘映像 (dcow2) 已损坏。我不得不使用 proxmox 工具修复它(qemu-img check -r all /var/lib/vz/images/100/vm-100-disk-1.qcow2)。然后,我必须恢复 grub,因为它似乎已损坏。最后,我不得不运行一个,fsck -r因为服务器抱怨: EXT4-fs error (device sda3): ext4_iget:4245: inode #1835722: comm rs:main Q:Reg: bad_extra_isize (20725 != 256)。 fsck 后,系统运行良好,并且存储在其上的文件似乎未损坏。

VM 主机上的任何日志都无法说明发生了什么情况。在服务器上,没有服务器崩溃时的系统日志。然而,unattended-upgrades-dpkg.log 显示了以下内容,之后没有任何内容,因此可能与崩溃有关:

Log started: 2018-02-15  06:35:35
(Reading database ... ^M(Reading database ... 5%^M(Reading database ... 10%^M(Reading database ... 15%^M(Reading database ... 20%^M(Reading database ... 25%^M(Reading database ... 30%^M(Reading database \
... 35%^M(Reading database ... 40%^M(Reading database ... 45%^M(Reading database ... 50%^M(Reading database ... 55%^M(Reading database ... 60%^M(Reading database ... 65%^M(Reading database ... 70%^M(Read\
ing database ... 75%^M(Reading database ... 80%^M(Reading database ... 85%^M(Reading database ... 90%^M(Reading database ... 95%^M(Reading database ... 100%^M(Reading database ... 109727 files and direct\
ories currently installed.)^M
Preparing to unpack .../libvorbisenc2_1.3.5-3ubuntu0.1_amd64.deb ...^M
Unpacking libvorbisenc2:amd64 (1.3.5-3ubuntu0.1) over (1.3.5-3) ...^M
Preparing to unpack .../libvorbis0a_1.3.5-3ubuntu0.1_amd64.deb ...^M
Unpacking libvorbis0a:amd64 (1.3.5-3ubuntu0.1) over (1.3.5-3) ...^M
Preparing to unpack .../linux-firmware_1.157.16_all.deb ...^M
Unpacking linux-firmware (1.157.16) over (1.157.14) ...^M
Processing triggers for libc-bin (2.23-0ubuntu10) ...^M
Setting up libvorbis0a:amd64 (1.3.5-3ubuntu0.1) ...^M
Setting up libvorbisenc2:amd64 (1.3.5-3ubuntu0.1) ...^M
Setting up linux-firmware (1.157.16) ...^M
update-initramfs: Generating /boot/initrd.img-4.4.0-112-generic^M
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.^M

Mdadm 看起来像这样:

# mdadm.conf                                                                                                                                                                                                
#                                                                                                                                                                                                           
# Please refer to mdadm.conf(5) for information about this file.                                                                                                                                            
#                                                                                                                                                                                                           

# by default (built-in), scan all partitions (/proc/partitions) and all                                                                                                                                     
# containers for MD superblocks. alternatively, specify devices to scan, using                                                                                                                              
# wildcards if desired.                                                                                                                                                                                     
#DEVICE partitions containers                                                                                                                                                                               

# auto-create devices with Debian standard permissions                                                                                                                                                      
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system                                                                                                                                             
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts                                                                                                                                                  
MAILADDR root

# definitions of existing MD arrays                                                                                                                                                                         

# This file was auto-generated on Sat, 10 Feb 2018 17:09:37 +0100                                                                                                                                           
# by mkconf $Id$       

有人知道如何修复吗?

答案1

磁盘映像损坏是相当不寻常的......

考虑到您需要重新安装的软件包数量,以及许多重要软件包受到影响的事实,我认为是时候从其他地方的虚拟机备份您需要的任何文件,并从头开始创建一个新的虚拟机了。这极有可能比尝试修复当前虚拟机花费的时间少得多。

相关内容