How to duplicate an installation (packages only)

This page was written with the following problem in mind - suppose you have an ubuntu system which you have been running for a while, and you have spent some time deciding which packages you want on the system and installing them using apt-get, synaptic or similar. For whatever reason, you then need to either:

  • reinstall the system from CD/DVD after a severe breakage.
  • do a clean upgrade from a new CD/DVD rather than upgrading in place. (E.g. if you are skipping several releases when upgrading, or just want to start again with a clean system).
  • install the same list of packages on a different machine - for example if you have bought a new computer and want to duplicate your installation.

In any of these cases, the procedure given below will allow you to keep the same set of installed packages on a new system.

Please note that this procedure will only duplicate the packages you have installed through apt-get or other package management tools like synaptic. It will not keep your home directory, other user data, or any programs you have installed manually from outside the ubuntu repositories. Neither will it keep any changes you have made to the system level configuration in /etc. Please look elsewhere or ask on the forums / mailing list for advice on how to do this.

Important commands

The important commands you need are:

dpkg --get-selections # prints a list of currently installed packages
dpkg --set-selections # sets the list of packages to install
apt-get dselect-upgrade # actually installs the packages set above.

Step by Step guide

Before you start, you need to have some writable storage medium on which you can record the list of installed packages from your old system. This could be a floppy disk, partition on your hard disk, usb stick, etc. The important thing is that it should be accessible from the new system you are trying to install once the base system is up and running, and shouldn't get wiped over during the process of installing this system. You also need to know how to mount and access this storage medium from the linux command line. If you don't know how to do this, you won't be able to follow these instructions, so ask for more detailed help on the forums.

Once you have sorted this out, the step by step procedure is as follows (comments after the '#' sign)... On the original installation (i.e. before reinstalling) do this:

sudo -i  # starts a root session
  # ... run whatever commands you need to mount the safe storage device ...
dpkg --get-selections > /<path to safe storage device>/dpkg-selections
  # records a list of installed packages into the file named after the > sign.
  # ... now run commands you need to safely unmount the storage device ...
<ctrl-D>  # end the root session.

Now install the new base system from whatever medium you are using (CD/DVD/Network). If possible, choose to install a minimal list of packages this way, and let the procedure below take care of installing the rest. It may be easier to do this if you use the alternate install disk rather than the standard live CD. Once you have reinstalled, do this:

sudo -i # starts a root session.
  # ... commands to mount the storage device ...
dpkg --set-selections < /<path to safe storage device>/dpkg-selections
  # sets the list of packages to install from the list kept previously
apt-get dselect-upgrade # actually installs the packages.
  # ... now unmount the device ...
<ctrl-D>  # end the root session

This will install all the packages that were listed as installed on your previous system.

Known Problems

There are two known problems with this method:

  • The list of packages installed on the new system is not guaranteed to be identical, only to include all of the packages that were installed on your old system which are still in the repositories. I.e. there may be extra programs which are installed by the base system installer which weren't in your old installation.
  • This method doesn't preserve information from your old system about which packages were installed manually and which were installed automatically. This means that if you later on remove an application package and it is the only package which uses a certain library, that library won't be removed automatically by 'apt-get autoremove' as it would normally. This will make it harder to manage the amount of disk space used by your system; whether this matters will depend on how much space you have available, how often you find yourself removing applications you don't use any more, and how often you do a clean reinstall of the system from original media (e.g. the ubuntu CD).

ReinstallingSamePackages (last edited 2008-07-25 10:40:29 by andy-earthsong)