0

I am using ubuntu 13.10, and I have deleted the dpkg directory. I removed /var/lib/dpkg, after the system gave me an error like:

Could not open lock file /var/lib/dpkg/lock

when i was installing ubuntu-restricted-extras.

Could anyone help me?

1

You have to restore dpkg's directory in the following state:

$ ls /var/lib/dpkg/ -l
total 12543
drwxr-xr-x 2 root root    4128 апр.   8 13:01 alternatives
-rw-r--r-- 1 root root      11 сент. 10  2013 arch
-rw-r--r-- 1 root root 3075761 апр.   8 13:15 available
-rw-r--r-- 1 root root 3075761 апр.   8 13:00 available-old
-rw-r--r-- 1 root root       8 апр.  24  2013 cmethopt
-rw-r--r-- 1 root root    2052 апр.   2 07:51 diversions
-rw-r--r-- 1 root root    2096 апр.   2 07:50 diversions-old
drwxr-xr-x 2 root root  483752 апр.   8 13:16 info
-rw-r----- 1 root root       0 апр.   8 13:16 lock
drwxr-xr-x 2 root root      48 марта 23  2013 parts
-rw-r--r-- 1 root root     288 февр. 12 11:45 statoverride
-rw-r--r-- 1 root root     260 февр. 12 09:58 statoverride-old
-rw-r--r-- 1 root root 3081465 апр.   8 13:16 status
-rw-r--r-- 1 root root 3082826 апр.   8 13:15 status-old
drwxr-xr-x 2 root root     744 апр.   8 13:00 triggers
drwxr-xr-x 2 root root      48 апр.   8 13:16 updates

The problem is that you cut the branch on which you sit. The simple reinstallation of dpkg doesn't work because it's dependent on the directory you have deleted. Fortunately, we have dpkg status file backup in /var/backups. So you have to do this:

sudo mkdir /var/lib/dpkg
sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/
sudo mv /var/lib/dpkg/dpkg.status.0 /var/lib/dpkg/status
sudo mkdir /var/lib/dpkg/updates
sudo mkdir /var/lib/dpkg/info
sudo touch /var/lib/dpkg/available
sudo apt-get install --reinstall dpkg

After this, you should be able to use apt-get. And at last, one good advice: don't delete any file/directory in the system unless you know what are you doing!

  • when i run last step "sudo apt-get install --reinstall dpkg" it gives me an error Could not exec dpkg! E: Sub-process /usr/bin/dpkg returned an error code (100) what should i do now??? :( – user2716820 Apr 10 '14 at 9:18
  • What is the output of ls -la /usr/bin/dpkg? – Danatela Apr 10 '14 at 9:29
  • -rwxr-xr-x 1 root root 256168 Oct 4 2013 /usr/bin/dpkg – user2716820 Apr 10 '14 at 9:47
  • Strange. Download dpkg and try to unpack it. Do not overwrite /var/lib/dpkg/status – Danatela Apr 10 '14 at 9:51
  • Do it like here. Just replace that dpkg with one in /var/cache/apt/archives – Danatela Apr 10 '14 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.