我无法运行 apt update。dpkg 在尝试打开 /var/lib/dpkg/status 时返回错误

我无法运行 apt update。dpkg 在尝试打开 /var/lib/dpkg/status 时返回错误

我正在尝试在 WSL 上升级 Ubuntu,但无法获取 dpkg 包并尝试打开 /ver/lib/dpkg 中的文件状态。该文件存在。

我已经尝试了所有我能找到的补救措施:

sudo dpkg --configure -a
sudo apt-get -f install
sudo apt-get --fix-missing install
sudo apt-get clean
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get clean
sudo apt-get autoremove
sudo dpkg --clear-avail && sudo apt-get update

sudo dpkg--configure-a

dpkg: error: failed to open package info file '/var/lib/dpkg/status' for reading: No such file or directory

$ ll /var/lib/dpkg/

total 1396
drwxr-xr-x 1 root root   4096 Nov  7 17:31 ./
drwxr-xr-x 1 root root   4096 Jul 25 11:56 ../
drwxr-xr-x 1 root root   4096 Jul 25 11:54 alternatives/
-rw-r--r-- 1 root root 181793 Jul 25 11:51 available
-rw-r--r-- 1 root root      8 Jul 25 11:51 cmethopt
-rw-r--r-- 1 root root    362 Jul 25 11:56 diversions
-rw-r--r-- 1 root root    414 Jul 25 11:56 diversions-old
drwxr-xr-x 1 root root   4096 Nov  7 17:31 info/
-rw-r----- 1 root root      0 Nov  7 17:33 lock
---------- 1 root root      0 Nov  7 17:33 lock-frontend
drwxr-xr-x 1 root root   4096 Apr 15  2018 parts/
-rw-r--r-- 1 root root    135 Jul 25 11:53 statoverride
-rw-r--r-- 1 root root 473812 Nov  7 17:31 status
-rw-r--r-- 1 root root 473779 Nov  7 17:31 status-old
drwxr-xr-x 1 root root   4096 Jul 25 11:56 triggers/
drwxr-xr-x 1 root root   4096 Nov  7 17:31 updates/

在这里重新安装 Ubuntu:

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: username
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

从这里再次启动 apt update

:~$ sudo apt update

[sudo] password for username:
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
   ......
Get:24 http://archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [1200 B]
Fetched 15.8 MB in 23s (700 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
106 packages can be upgraded. Run 'apt list --upgradable' to see them.
:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
...

The following packages will be upgraded:
...
106 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 42.1 MB of archives.
After this operation, 686 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y


Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 base-files amd64 10.1ubuntu2.3 [60.4 kB]
...
Get:105 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 cloud-initramfs-copymods all 0.40ubuntu1.1 [3804 B]]
Get:108 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 overlayroot all 0.40ubuntu1.1 [15.2 kB]

Fetched 42.1 MB in 1min 24s (499 kB/s)

Extracting templates from packages: 100%
Preconfiguring packages ...
(Reading database ... 28490 files and directories currently installed.)
...
Preparing to unpack .../dpkg_1.19.0.5ubuntu2.1_amd64.deb ...
Unpacking dpkg (1.19.0.5ubuntu2.1) over (1.19.0.5ubuntu2) ...
dpkg: error: failed to open package info file '/var/lib/dpkg/status' for reading: No such file or directory

E: Sub-process /usr/bin/dpkg returned an error code (2)
sudo dpkg --configure -a

dpkg: error: failed to open package info file '/var/lib/dpkg/status' for reading: No such file or directory

$ ll /var/lib/dpkg/

total 1396
drwxr-xr-x 1 root root   4096 Nov  7 17:31 ./
drwxr-xr-x 1 root root   4096 Jul 25 11:56 ../
drwxr-xr-x 1 root root   4096 Jul 25 11:54 alternatives/
-rw-r--r-- 1 root root 181793 Jul 25 11:51 available
-rw-r--r-- 1 root root      8 Jul 25 11:51 cmethopt
-rw-r--r-- 1 root root    362 Jul 25 11:56 diversions
-rw-r--r-- 1 root root    414 Jul 25 11:56 diversions-old
drwxr-xr-x 1 root root   4096 Nov  7 17:31 info/
-rw-r----- 1 root root      0 Nov  7 17:33 lock
---------- 1 root root      0 Nov  7 17:33 lock-frontend
drwxr-xr-x 1 root root   4096 Apr 15  2018 parts/
-rw-r--r-- 1 root root    135 Jul 25 11:53 statoverride
-rw-r--r-- 1 root root 473812 Nov  7 17:31 status
-rw-r--r-- 1 root root 473779 Nov  7 17:31 status-old
drwxr-xr-x 1 root root   4096 Jul 25 11:56 triggers/
drwxr-xr-x 1 root root   4096 Nov  7 17:31 updates/

$ sudo apt-get -f install
$ sudo apt-get upgrade
...
After this operation, 0 B of additional disk space will be used.
...
dpkg: error: failed to open package info file '/var/lib/dpkg/status' for reading: No such file or directory
E: Sub-process /usr/bin/dpkg returned an error code (2)

$ sudo apt-get clean
$ sudo apt-get update

Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done

:~$ sudo apt-get 升级

Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  libfreetype6
Use 'sudo apt autoremove' to remove it.
The following packages have been kept back:
  lxd lxd-client netplan.io
The following packages will be upgraded:
....

100 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
1 not fully installed or removed.
Need to get 32.6 MB of archives.
After this operation, 250 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
   .....

Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libuuid1 amd64 2.31.1-0.4ubuntu3.2 [20.0 kB]
Get:99 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 open-vm-tools amd64 2:10.3.0-0ubuntu1~18.04.2 [542 kB]
Get:100 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 overlayroot all 0.40ubuntu1.1 [15.2 kB]
   .....

Fetched 32.6 MB in 24s (1340 kB/s)
Extracting templates from packages: 100%
Preconfiguring packages ...

dpkg: error: failed to open package info file '/var/lib/dpkg/status' for reading: No such file or directory
E: Sub-process /usr/bin/dpkg returned an error code (2)

重新安装不起作用。

我之前在 PC 上安装过 Ubuntu,现在其他发行版也能用。这台机器上的 apt 进程坏了,我不知道该怎么修复。

相关内容