Posts tagged ‘autiobiographical’

Fixing catastrophic mistakes with apt-get

Story for the patientDecorative Picture

I managed to utterly break a linux installation yesterday, by trying to install a single package with apt-get. Apt helpfully decided to suggest removing a number of important packages, and I absentmindedly agreed.

The lesson learned here would be that you should always press ‘n’ immediately and think whenever apt suggests removing more than a couple of packages, if I didn’t know this. I suppose the real lesson is just to be less dim, but alas this never seems to work. Another lesson is to especially be less dim when you only have a wireless internet connection and you decide to remove the things that make it work.

Anyway, I found a moderately nice way of reverting these damaging changes.

Although apt does not do any logging, it uses dpkg for installation (on debian type systems at least) and dpkg does do logging.

Looking at /var/log/dpkg.log I found that it neatly recorded all of dpkg’s operations so I was able to get a list of all the packages I had absentmindedly removed by using some crpytic shell commands:

cat /var/log/dpkg.log | grep remove | cut -d " " -s -f 4 > ~/removed-packages

I then could reinstall these with:

apt-get install `cat removed-packages`.

Hurrah for copious logging and shell textual data processing… or something like that.

Summary for the impatient:

Apt doesn’t store a log, but dpkg does and apt uses dpkg. The relevant log file is /var/log/dpkg.log. To get a list of the removed packages, and install them again you can run:

cat /var/log/dpkg.log | grep remove | cut -d " " -s -f 4 > ~/removed-packages; apt-get install `cat ~/removed-packages`

as a root user.

March 11, 2008 at 10:40 pm 1 comment


May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031