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
)?
Well, the base package list (assuming this is a desktop system) is built by the combination of the
ubuntu-minimal
andubuntu-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!
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.
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...?
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.
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.