Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to restore a Ubuntu installation back into the state it had when it was freshly installed without actually doing an actually reinstall, i.e. I want to remove all packages that where installed afterwards and are not part of the default installation.

How would one accomplish this or where could I find a list of packages that are installed on a default Ubuntu installation (for diff'ing against dpkg -l)?

share|improve this question

5 Answers 5

Well, the base package list (assuming this is a desktop system) is built by the combination of the ubuntu-minimal and ubuntu-desktop packages. These are metapackages that exist solely to depend on other packages. The problem, of course, is that their dependency list is not the complete package list. The packages they depend on may have other dependencies.

So... I would suggest playing around in aptitude. Perhaps try flagging all installed packages for removal, then specifically selecting your active kernel, ubuntu-minimal, and ubuntu-desktop to be installed. With a little finagling, you should be able to reach a point where the only packages flagged to be removed are the ones not required by the two metapackages.

I haven't tried this. I haven't even experimented with it. You may hose your system by following my suggestions.

Have fun!

share|improve this answer
    
Throw ubuntu-standard in there as well. You also have language-pack-gnome-en, language-pack-en, and language-support-en (or whatever language). –  koenigdmj Aug 6 '09 at 17:29
up vote 2 down vote accepted

I created three lists:

With those its just a matter of:

dpkg -l | grep ^ii | awk "{ print \$2 }" | sort > /tmp/pkgs

diff -u Ubuntu9.04-required /tmp/pkgs | sed -n "s/^\\+//p" > /tmp/pkgs-to-delete

apt-get remove $(cat /tmp/pkgs-to-delete)

To clear an Ubuntu to back to the desired state. The lists haven't been created on a clean Ubuntu install, so they might not be perfect reproduction of the original state, but they should be good enough to cleanup a system a bit.

share|improve this answer

Is there something in particular you're aiming for as a goal in doing this? Maybe there's another solution to the issue, unless your entire goal is just to roll it back. But if that were your goal, I don't know why you wouldn't just reinstall with a format...?

share|improve this answer
    
...because most linux installs can be returned to near-pristine condition, and re-installation is usually considered a last resort, more akin to "it's gone to crap and it'll never come back". –  Avery Payne Aug 6 '09 at 15:18
    
The goal here is simply a more or less complete rollback to pristine default conditions and the reason why via apt-get instead of reinstall is simply that apt-get remove could run unattended via remote ssh without reboot, while reinstall would involve a good bit manual work and rebooting. –  Grumbel Aug 6 '09 at 15:30
    
Avery - if you have a home system and you're trying to roll it back to rebooted state, reformat/reinstall isn't a last resort...last resort is if you fubar'd it so you're doing the ref/rei as a repair. Grumbel has a case illustrated in his comment where it appears to make sense to do this though. Best I can see is to get a list of installed programs from /var/log/dpkg.log and /var/log/apt/* and from there figure out which programs to uninstall. –  Bart Silverstrim Aug 6 '09 at 16:00
    
Whoops, mean pristine, not rebooted state. –  Bart Silverstrim Aug 6 '09 at 16:00

Usually, a distro logs those things in /var/log/something. Ubuntu logs in /var/log/aptitude if you use aptitude or /var/log/dpkg.log if you used dpkg. I'm not sure what the logfile would be called when using apt-get.

Fedora uses /var/log/yum.log by the way, and older RHELs use /var/log/up2date.

If you write a little script to parse those files, you should be able to manage. I don't think the logs take updates into account, though, so be careful not to just remove the world.

share|improve this answer
    
Presumably it is always logged in dpkg.log whether you use aptitude, apt-get or anything else is that right? –  thomasrutter May 31 at 10:22

Personally, I would use CloneZilla to make a disk image immediately after the initial installation. Then you can restore the disk image whenever you want. This works really well if you have your /home directory on a different physical disk because then you can restore the system and keep all your user settings. The whole restore process takes about 30 minutes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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