0

Like another user, I have accidentally deleted /var/lib/dpkg and have poor backups. I need to reinstall dpkg from beginning. The solution provided to that answer is not working for me.

$ lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.5 LTS
Release:    16.04
Codename:   xenial

$ ls -l /var/lib/dpkg
total 16
drwxr-xr-x 2 root root 4096 Mar 25 21:26 alternatives
drwxr-xr-x 2 root root 4096 Mar 25 21:26 info
-rw-r----- 1 root root    0 Mar 25 21:46 lock
-rw-r----- 1 root root    0 Mar 25 21:46 lock-frontend
drwxr-xr-x 2 root root 4096 Mar 25 21:26 parts
drwxr-xr-x 2 root root 4096 Mar 25 21:26 status

What I've tried

References to what I've tried:

  1. Solution 1
  2. Solution 2
  3. Solution 3
  4. Solution 4

From (1), I was able to recover sudo cp /var/backups/dpkg.status.0 into /var/lib/dpkg/status. But attempting apt-get download dpkg fails. So, trying the solution from link (2) above, I get partway:

mkdir /tmp/dpkg
cd /tmp/dpkg
wget http://security.ubuntu.com/ubuntu/pool/main/d/dpkg/dpkg_1.17.5ubuntu5.2_i386.deb

ar x dpkg*.deb data.tar.gz
tar xvzf data.tar.gz ./usr/bin/dpkg
cp ./usr/bin/dpkg /usr/bin/
sudo apt-get update

apt-get update gets my package lists, but then returns an error. Attempting apt-get clean first, as suggested in Solution 3, returns the same error. I get the same error with anything related to apt-get (except apt-get clean):

Reading package lists... Error!
E: Read error - read (21: Is a directory)
E: The package lists or status file could not be parsed or opened.

Note that I am missing / have deleted file /var/lib/dpkg/status-old.

Continuing to run down the rabbit hole of help resources, I found Solution 4. But when I tried sudo dpkg -a configure, it produces:

dpkg: error while loading shared libraries: libselinux.so.1: cannot open shared object file: No such file or directory `

This is the same error I get from solution (1) when running sudo dpkg -i dpkg*.deb

Solution 4 further suggests using the program synaptic. But I cannot install since package manager is broken :(.

Any help would be greatly appreciated!!

1 Answers1

1

Always try the simple step first. Since you haven't mentioned it, try this.

In terminal type the following:

sudo apt install dpkg

Press Enter and it should work fine.

Hope that helps. If you get an error, report back here. We'll take it one step at a time.

  • Unfortunately, the same error as above Reading package lists... Error! E: Read error - read (21: Is a directory) E: The package lists or status file could not be parsed or opened. – alexwhitworth Mar 27 '19 at 00:23
  • It may very well be that you have a pretty messed up system. Unless you can remember all the steps you performed to get to this place, it may just be easier to do a reinstall of the operating system to get things back to normal. You can then also consider coming up to a later LTS release. Check Ubuntu for the correct procedure in any case. – Searcher Mar 27 '19 at 14:28