Removed /var/lib. Can't open Desktop

5,466

Solution 1

I was able to copy the directory from a Live DVD, and now I can work on my computer.

The reason why I couldn't do this before was because of my CD ROM. Apparently, it was damaged, and that's what all the "Kernel panic" was all about.

I chose to do this instead of reinstalling the whole operative system because I didn't really have many programs installed more then those given by default with this distribution of Linux.

As @Gilles suggested, I'm now making backups to prevent future incidents. And as he said, if some weird problem comes, I know what's to blame. But still, I'd like to try to solve them before formatting.

I'm yet not sure why I couldn't reinstall the packages I found in /var/backups/dpkg.status.0, so if anyone knows why, it'd be great if you could tell us.

Thanks to all of you who gave your help.

Solution 2

Restore from backup.

Yes, I know, you didn't make backups. Well, now you understand why backups are important.

/var/lib contains a lot of important files. Recovering from deleting /var/lib is going to leave you with a system that doesn't work well; even if you manage to limp along, you're going to get all sorts of weird problems later on. If you try to repair, and run into any strange issues later on, the deletion of /var/lib is likely to blame (so you've lost any hope of getting support online — and don't even think of not mentioning it, it would only lead to deep frustration).

/var/lib/dpkg contains the database of installed packages and additional information about installed packages, and /var/lib/apt contains additional information managed by APT rather than dpkg. While there's an almost-up-to-date backup of /var/lib/dpkg/status in /var/backups, that's only a small part of what you'd need to restore.

You can obtain the list of installed packages with

</var/backups/dpkg.status.0 awk -v 'RS=' -F '\n' '
    /\nStatus: .*installed\n/ {sub(/^Package: /,""); print $1}
' | sort >/var/tmp/packages0.list

Check /var/log/dpkg.log for the latest package installations and removals and manually edit the list accordingly. You now have a list of installed packages; the indication of which ones were installed manually and which ones were installed automatically was lost with /var/lib/apt.

At this point, you can reinstall all the packages with

apt-get update
apt-get --reinstall install `cat /var/tmp/packages0.list`

You may need to create a few more directories under /var/lib before this works — you'll know which directories are missing because there'll be error messages. All the directories under /var/lib/dpkg and /var/lib/apt should be owned by root:root, mode 755.

I urge you to back up /etc and the package list and reinstall your system. Install etckeeper to keep a history of changes in /etc, and run etckeeper commit 'some meaningful messages' when you change something in /etc, that way it'll be easier to do a similar installation in the future.

Solution 3

The easiest method may be to reinstall all the packages that were installed. If you don't have a list of what was installed, you may need to reinstall based on Priorites.

You may want to start with:

aptitude reinstall ?essential
aptitude reinstall ~pstandard
aptitude reinstall ~prequired
aptitude reinstall ~pimportant

If you have a list of the packages that were installed, you can use that to reinstall. If not you will need to identify the packages. This should rebuild the /var/lib subdirectory.

You likely have additional packages installed, and will have to identify them. If you haven't cleaned the /var/cache/apt/archives directory, you can get a list with the command.

ls /var/cache/apt/archives | cut -d_ -f1
Share:
5,466

Related videos on Youtube

Joshua
Author by

Joshua

Updated on September 18, 2022

Comments

  • Joshua
    Joshua almost 2 years

    Well, I'm pretty scared now.
    I was trying to delete a folder by

    sudo rm /var/lib/texmf -r
    

    but instead, wrote

    sudo rm /var/lib -r
    

    I read some documentation about it, and found this thread.

    I tried to follow all the steps from the last comment (2nd page), but I didn't know how to do some of the things listed there.
    So this is all I did:

    First, I created these folders:

    mkdir /var/lib/dpkg/alternatives/  /var/lib/dpkg/info/  /var/lib/dpkg/methods/  /var/lib/dpkg/parts/  /var/lib/dpkg/  triggers/  /var/lib/dpkg/updates/  /var/lib/apt/  /var/lib/aptitude  /var/lib/binfmts/  /var/lib/misc/
    

    I had to do it by sudo, and had to create subfolders first, in order to create all the folders.

    Then I did:

    aptitude update && aptitude upgrade
    

    Here is where confusion started.
    First of all, the warnings listed by user @marco.org didn't appear to me (I'm not even sure in what language they're written), but instead another error appeard, saying that it couln't create some-file because some-folder (a subfolder in /var/lib) didn't exist.
    I created the folder (using sudo mkdir), the process finished (with some errors I don't remember).

    Then I moved the file dpkg.status.0, mentioned in the link above, by:

    sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status
    

    (Again, I had to create the folder. I'm not really sure why I did this, I just read about it somewhere)

    So apparently the first problem was solved. I then tried installing some program, using

    sudo apt-get install some_program
    

    and even though it showed some warnings (all about files missing from sub directories of /var/lib), the program was installed, and I could use it with no problem.

    A few minutes later, I wanted to relax a little bit and watch some video on youtube (I had installed the latest version of Google Chrome), but instead of relaxing, I got yet another reason to panic:
    There was no sound output for the video, or for any other application on Chrome (other programs did have sound).

    So I panicked and shutdown my computer.
    Then, when I turned it on, and after Linux started, I didn't see my desktop, but a console screen asking me for a login and password.
    I gave the information, and some message appeared, saying it couldn't creat a file, because a folder was missing. I created it with:

    sudo mkdir /var/lib/ubuntu-release-upgrader
    

    Then another message said that it couldn't move the file, so I moved it manually with:

    sudo mv /usr/lib/ubuntu-release-upgrader/release-upgrader-motd -t /var/lib/ubuntu-release-upgrader/
    

    Then I restarted the system, hoping to see my desktop. But instead, the same console screen showed, saying, after giving my login and password:

    Last login: Tue Apr 8 13:19:16 CST 2014 on tty1
    Welcome to Linux Mint 15 Olivia (GNU/LINUX 3.8.0-26-generic i686)
    
    Welcome to Linux Mint
    * Documentation: http://www.linuxmint.com
    

    Now I can't get back to GUI mode, or use any of my programs.

    I guess there should be a way of getting the folder I deleted from the installation dvd, but I'm kind of new with this, and am not sure of how to do it.
    Could anybody please help me? I would really appreciate it.


    P.S: Also, after deleting /var/lib, whenever I used sudo, a line appeared saying something like:

    couldn't mkdir /var/lib/sudo, file not existing
    

    but it got solved after the

    aptitude update && aptitude upgrade
    
    • Admin
      Admin about 10 years
      We don't handle Mint here, but I will move this somewhere where they do. In the meantime, can you get into recovery mode from GRUB?
    • Admin
      Admin about 10 years
      I am now into the Recovery Menu (filesystem state: read-only) What shall I do next?
    • Admin
      Admin about 10 years
      sudo rm /var/lib shouldn't remove so much --- I have all dirs and one symlink. Are you sure you didn't do a rm -r or similar?
    • Admin
      Admin about 10 years
      @Joshua Well I was going to say recreate the file you deleted, but now that I think about it you can't do that.
    • Admin
      Admin about 10 years
      @Rmano Sorry, I forgot that. I did rm -r
    • Admin
      Admin about 10 years
      Now you panic.
    • Admin
      Admin about 10 years
      Well, I suppose that there are two options here: if you have a full backup, deploy it. Otherwise, backup your personal files (/home) and reinstall --- it will be probably easier than try to recreate that directory tree (I have 77 directories under /var/lib).
    • Admin
      Admin about 10 years
      Is there a /var/cache of any kind? I mean, can't you get a package list of what you used to have?
    • Admin
      Admin about 10 years
      You do: mount /dev/something /path/something. initramfs is a Linux disk image - it contains a /var/lib as well almost definitely, but it will be as minimal as possible. The point of initramfs is to get your main disk mounted and switch to it. But if you're using sudo at all - I was wrong. sudo has no purpose in initramfs because it would run as the root user anyway. Really, though, it's no big deal. Stick a live disc in and install over it. Worst that can happen is you have to update again - or maybe wipe your disk after a backup.
    • Admin
      Admin about 10 years
      @mikeserv There are some directories inside of /var/cache (e.g: apt, apt-xapian-index, cups, davfs2, debconf, etc). Inside of /dev I see some files that look nothing alike to the directories I saw before (in /var/cache/)
    • Admin
      Admin about 10 years
      @mikeserv Could you give me an example of what should I mount?
    • Admin
      Admin about 10 years
      There you go - apt - that's your package manager. If everything has been stored since you installed everything is already there - you don't even need the live disc. Still, find out how to dpkg -i those things and install them. Well, you don't have to mount anything - you're already there man.
    • Admin
      Admin about 10 years
      @mikeserv Ok. I'm not really sure of how to use dpkg. I tried sudo dpkg -i apt (inside of /var/cache/) the following error shows, followed by other two exiting errors: error reading apt: Is a directory
    • Admin
      Admin about 10 years
      @Rmano I'm not sure about that. Last time I needed some help that's now unavailable for me in order to install my operative system. Anyway, I guess I'll have to try that if I get no other solution for this.
    • Admin
      Admin about 10 years
      I think that reinstalling (unless you have some strange graphic drivers or device that need proprietary drivers) will require a lot less Unix skills than recovering the damage. But that's just my opinion, so you're perfectly entitled to differ ;-)
    • Admin
      Admin about 10 years
      Definitely. I was just saying it might get you working? I don't know debians so I don't know dpkg. I think sudo dpkg -i /path/to/package.deb would be all you need to install one but I don't know - and you did mention a sudo problem. Also, that is just a cache it gets flushed from time to time so I wouldn't know everything you would need would be there. Though it would definitely be where I would start.
  • Joshua
    Joshua about 10 years
    Greetings. When I try to sudo aptitude reinstall ?essential I get some of these: Err http://archive.ubuntu.com/ubuntu raring/main base-passwd i386 3.5.26 That's for many other archives. And the last line says: E: Internal Error, No file name for base-files:i386
  • BillThor
    BillThor about 10 years
    Try reinstalling base-files then retrying reinstalling the essential packages. You are likely to encounter some more dependency failures. You can also try a -force option to reinstall anyway.
  • Joshua
    Joshua about 10 years
    Same thing happened. The previous lines before the final error says: [Working]E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/b/base-files/base‌​-files_6.12ubuntu2_i‌​386.deb: Something wicked happened resolving 'archive.ubuntu.com:http' (-11 - System error)
  • Joshua
    Joshua about 10 years
    BTW. When I get the list of installed packages (ls /var/cache/apt/archives | cut -d_ -f1) I can only see the last few packages listed, since I can not scroll with the mouse. Is there any way to see them all, or to fix the mouse problem?
  • Joshua
    Joshua about 10 years
    I'm sad to say that non of the commands you wrote work for me. When I try to update or reinstall the packages, I get errors like "Failed to fetch some-ubuntu-direction Something wicked happene...." and nothing of missing directories. So I guess the best solution is to make a backup and reinstall my operative system. Although, when I get a kernel panic error when I try to start linux mint from the live dvd. I will create another thread for this issue, and paste the link here.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 10 years
    @Joshua You're probably missing one of the directories, perhaps sometimes there's no clear error message (it isn't a common failure type). But in any case making a backup and reinstalling is something you'll need to do.
  • BillThor
    BillThor about 10 years
    @Joshua Pipe the output to less by adding | less to the command. You can use the list to reinstall the packages by piping to xargs -n1 aptitude reinstall instead.
  • BillThor
    BillThor about 10 years
    @Joshua You may be able to work around the failure to fetch the file by using wget to fetch it. Then you can use dpkg -i to install. The essential packages are the critical ones. You should be able to get a list with the command aptitude search ?essential. The base-files package is likely the most important.