I am having some trouble with an installed debian on a machine. While I have all data backed up, the configuration of installed packages is also critical to me. Does anybody know a way to either re-install the OS while keeping ideally all of /etc and /home or alternatively at least get a fresh debian install will all previously installed packages which I would only have to reconfigure plus copy my data


2 Answers 2


I don't know what problem you are trying to solve.

What I do

What I do in order to get upgrades is:

  • I keep my home/ mount (and backups of it too)
  • I run etckeeper (and I have the history mirrored to a remote machine)

So upgrading is:

  • dpkg --get-selections | grep -w 'install$' > installed.txt
  • install fresh OS
  • install the packages from installed.txt (some manual steps there that I didn't bother automating because it happens <1x p/yr)
  • install etckeeper, diff my /etc/ tree with the original and merge the important configuration stuff

Simple hint: Without starting from scratch

You should be able to get a long way with something like

sudo apt-get install --reinstall $(dpkg --get-selections | grep -w 'install$' | cut -f1)

I havent't tried it, on my system it would download about 3 Gb of packages :)

Sample output from my system (note a list of packages that aren't in the Debian/Ubuntu repositories):

sehe@meerkat:/tmp$ sudo apt-get install --reinstall $(dpkg --get-selections | grep -w 'install$' | cut -f1) -d Reading package lists... Done Building dependency tree
Reading state information... Done Reinstallation of nxagent is not possible, it cannot be downloaded. Reinstallation of freenx-server is not possible, it cannot be downloaded. Suggested packages: multiboot-doc grub-emu xorriso desktop-base The following packages will be upgraded: grub-common grub-pc 2 upgraded, 0 newly installed, 3043 reinstalled, 0 to remove and 0 not upgraded. Need to get 3,153MB/3,333MB of archives. After this operation, 205kB of additional disk space will be used. E: You don't have enough free space in /var/cache/apt/archives/.

Don't forget

Keep backups

  • Essentially, the problem is to avoid that period of occasional annoyance after reinstalling when you run into packages you haven't reinstalled. (Build dependencies can be a pain, since you don't always remember the package name, or even what they all were!)
    – Cascabel
    Jun 18, 2011 at 13:41
  • Well, I used to have the same annoyance. But recently I have grown accustomed to just starting from scratch, installing a few essentials from the top of my mind and for the reset ubuntu will automatically suggest which 'apt-get install' command will install a missing program in bash. Don't know whether that is Ubuntu-specific, but it sure rocks. It's always a matter of seconds, no slowdown at all (I must add, that I do have skipped a minor ubuntu-release in the recent past)
    – sehe
    Jun 18, 2011 at 14:21
  • Yeah, it's usually not too bad. But sometimes it's trickier - say you're trying to build something like mpd from scratch, and you know it needs some libraries for certain audio formats, but they're nonfree, so they're not listed build dependencies of the mpd package. Hopefully you know the name of the desired library, but you still have to go search a bit. Having a list from your previous install could be handy - maybe a list of manually installed packages.
    – Cascabel
    Jun 18, 2011 at 14:32

It depends on how your disk is partitioned.

If you have /home on it's own partition, you might be able to reinstall the OS without formatting the /home partition, then its previous contents would be preserved.

It's unlikely that you would have dedicated a partition to /etc, so you wouldn't be able to take advantage of not formatting /etc.

I hope, though, the data you have backed up include your configuration files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy