0

Earlier, I had a problem with a package, and I (wrongly) ran this:

rm -r /var/lib/dpkg/*

See also my other question.

Now when I try to upgrade, I get this:

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
masoud@masoud-PC:~$ sudo apt-get upgrade 
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

and when I use: sudo dpkg --configure -a

I get this:

dpkg: error: cannot scan updates directory `/var/lib/dpkg/updates/': No such file or directory

enter image description here

and for sudo apt-get upgrade -f get:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... failed.
The following packages have unmet dependencies:
 ia32-libs : Depends: ia32-libs-multiarch but it is not installable
 wine1.4 : Depends: wine1.4-i386 (= 1.4.1-0ubuntu5) but it is not installable
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
E: Unable to correct dependencies
Mj125
  • 356
  • Did you do something before this? When the problems started? – Braiam Sep 11 '13 at 12:52
  • yes. when the package break, I do this: sudo rm -r /var/lib/dpkg/* – Mj125 Sep 11 '13 at 13:02
  • You will need to restore from backup or reinstall. – psusi Sep 11 '13 at 14:11
  • I don't have any backup. what else can I do? – Mj125 Sep 11 '13 at 15:07
  • Like I said before, you will have to reinstall. – psusi Sep 11 '13 at 15:41
  • if you removed dpkg then try to install it ;) Who knows, it would work for you.. sudo apt-get -f install dpkg – Saurav Kumar Sep 11 '13 at 17:26
  • Do you have deboostrap? If so, you could try recreating you environment. If you tell me if it is installed (i.e. type deboostrap in a terminal) I can think and write an answer. – Andrea Corbellini Sep 11 '13 at 18:06
  • automatic backup is made by ubuntu,but mostly you will have to reinstall most application . See my answer – Stormvirux Sep 11 '13 at 20:20
  • @psusi all the files in the /var/lib/dpkg/ are generated. None of them are in the dpkg package. – Braiam Sep 11 '13 at 23:20
  • @Braiam, yes.... and? The problem isn't dpkg per se, it's that dpkg no longer has any idea what packages are installed. – psusi Sep 11 '13 at 23:39
  • @psusi you are literally saying that there is no alternative, when he could use the files in /var/backups to restore most of his system files. For the post/pre inst/rm scripts he could use --unpack for the control files, only leaving the alternatives symlinks unreparied. – Braiam Sep 11 '13 at 23:51
  • 1
    @Braiam, yes, if you have a backup of the status file in /bar/backup, you can restore that... and then reinstall every single package it lists... that still amounts to reinstalling, just doing it the hard way. – psusi Sep 12 '13 at 01:45

4 Answers4

4

Open a terminal and type the following:

sudo mkdir -p /var/lib/dpkg/{updates,alternatives,info,parts,triggers}
sudo killall apt* software-center* dpkg
sudo apt-get update
sudo apt-get purge wine1.4 ia32-libs-multiarch
sudo apt-get upgrade

The first command gets rid of the "cannot scan updates directory" (along with the disaster of the rm -r), then we need to end any dkpg/apt instance to get rid of "Unable to lock" message. Third, lets clean the package cache, update the software list cache and upgrade.

Braiam
  • 67,791
  • 32
  • 179
  • 269
  • now I got this: 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: ia32-libs : Depends: ia32-libs-multiarch but it is not installable wine1.4 : Depends: wine1.4-i386 (= 1.4.1-0ubuntu5) but it is not installable E: Unmet dependencies. Try using -f.
    – Mj125 Sep 11 '13 at 12:39
1

To start you need to recreate your /var/lib/dpkg/status file. You should probably have a backup at /var/backups/dpkg.status.0

So first we create the dpkg folder and then copy /var/backups/dpkg.status.0 to /var/lib/dpkg/status as follows

 mkdir /var/lib/dpkg
 cp /var/backups/dpkg.status.0 /var/lib/dpkg/
 mv /var/lib/dpkg/dpkg.status.0 /var/lib/dpkg/status

Create a folder called update inside /var/lib/dpkg

 mkdir /var/lib/dkpg/update

Now you Have to reinstall all the installed Applications.

NOTE:

There are extra backups at /var/backups/ namely dpkg.status.1, dpkg.status.2 but are in zipped form. If you want to use it you will have to uncompress it.Better go with the default one as explained above.For extra info see the source below

Source

Stormvirux
  • 4,466
1

When you ran

sudo rm -r /var/lib/dpkg/*

you destroyed many important files and directories used by the dpkg software.

Unfortunately, there is no easy way to get back a working system without a full restore from backup or re-installation. You may be able to restore the missing files manually, one-by-one, but it is going to be no less than a major headache.

When you asked the same question here you were told (in a comment) to re-install or restore from backup. It is still a good idea, and opening a new question won't help you get a better answer.

Edit: I now realise you asked this question before the other question. But you also asked others. Stop creating new questions asking about this same problem.

You see, often when you hose an application, you can repair it by purging and re-installing the relevant package. In this case, the application you've hosed is the very one you would need in order to install and remove packages.

thomasrutter
  • 36,774
0

Create the directory manually with mkdir and do what you already did after that. This should fix it.

Joren
  • 5,053
  • 8
  • 38
  • 54
Josh
  • 1,440