Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I accidentlly deleted /var folder form my ubuntu istalltion. Can it be restored somehow, without loosing the installation? Please suggest what options I do have?

share|improve this question
Isn't that exactly what backups are for? – David Schwartz Nov 9 '11 at 9:33

/var contains some important folders which hold the state for programs (in /var/lib). Your program state (dpkg) has gone too, so you will end up with a reinstallation of programs anyway.

Since /var/log has gone too, you cannot analyse /var/log/apt/history.log either so you have to rely on your memory to know which programs you've installed. After restoring the dpkg and packages database (probably by sudo install -D -m755 /var/lib/dpkg && sudo apt-get update), you can use dpkg -S /path/to/file to get the package for a given path.

That said, a reinstallation would be the easiest way. Make a backup of /home (and possibly /etc if you changed system-wide settings or users/groups) and do a reinstall. If your /home was on a separate partition, it's even easier: mark that partition as /home in the installer, but do not tick "format".

share|improve this answer
I don't understand: if he lost /var, how can he look at /var/log/apt/history.log? – o0'. Nov 9 '11 at 9:20
@Lohoris: well, that's technically possible since /var/log could be a separate mount point. Updated answer with for a more likely situation. – Lekensteyn Nov 9 '11 at 9:37

I know this is old but... This problem happened to me yesterday and I found this ubuntu forum topic, it was very usefull.

I accidentally erased my /var folder... sudo nautilus, is not a good idea... Ooops, my fault.

I just created an Ubuntu VM (same version) in other computer, I copied the /var folder from this clean installation and paste it in the computer (HDD) where I erased the /var folder.

There are a couple of things that happened to me, maybe of interest:

I was able to start ubuntu without the /var folder, but there was not GUI (Unity/Gnome); I could only use the console (Like when you press ctrl+alt F1 or something like that) and for some reason the flash drives were not recognized.

From the ubuntu's LiveCD the flashdrives were readable (and writable). So my solution was to open a terminal and using "sudo cp" to copy the "clean /var directory" into the computer that was missing the /var folder

Now I am available to start ubuntu "normally" and even run every program, like GGTS (an eclipse derived), pgAdmin, firefox... except tomcat Everything seems to work as before erasing the /var folder, but I plan to reinstall Ubuntu in the moment I can, just to be sure.

NOTE: The harddrive when booting from livecd is in /media/

I was using Ubuntu 12.04

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .