Reinstalling Debian Squeeze via APT after significant core package removal

1

Some background:

I accidentally left two problematic repositories in my /etc/apt/sources.list - to be specific, the squeeze-updates repository (changed from "volatile"), and the sid repository. I was testing some things a while ago and needed those repos for some packages not available in the current one. However, I forgot about it and upgraded (apt-get dist-upgrade) with those repositories, and haven't experienced problems until now, prompting me to downgrade.

First, I removed the conflicting sources. Then I followed online instructions to apt pin the stable repositories to force a downgrade. After it completed, hundreds of obsolete packages remained. Being audacious, I crafted (and ran) the following command to attempt to remove them:

while :; do aptitude -y --without-recommends -f remove ?obsolete; if [ ! "$?" = "0" ];then break; fi; done

It did remove the obsolete packages, especially upstream things like the Linux 3.x kernel. However, I saw some other things that got removed, like the software that I installed before the repo change. I should have stopped everything then, but I thought I'd keep going and let it run, knowing that I can recover later. Coming back to the session window later, it had a dialog prompting me whether I want to keep or remove... my currently running kernel.

I really don't want to do a CD reinstall - I have no place to store the 20+ GBs of data (this is a VPS, and I have a very slow internet connection), and reconfiguring everything will take a LOT of time, and I need the server to be running again ASAP.

Supposedly (this is from the Debian mailing list archive), Debian users prefer to do reinstalls via APT, since this is theoretically possible. I have my own reasons to do it via APT.

Question:

Is there, at all, in any way possible, to install Debian without resorting to a CD, via APT or other means? I still have access to the Internet on my server.

I'm aiming to do reinstall the base system AND any categories that I've selected during the original installation (CLI) of Debian Squeeze.

Albert H

Posted 2012-03-25T01:03:38.030

Reputation: 876

A biut late, but wasn't you data in a separate partition mounted at /usr/local/ ? If it was you could just reinstall the whole OS as long as you did not reformat that partition. – Hennes – 2013-09-11T12:55:12.393

Answers

1

From any working Linux system, you can use Debootstrap or cdebootstrap to perform the initial layout for a Debian installation in a new location. If you have a spare partition, this should be pretty straightforward: format, mount, debootstrap, chroot, configure, add to bootloader, reboot.

ephemient

Posted 2012-03-25T01:03:38.030

Reputation: 20 750

I think I can still boot the system, but I'm missing some packages. Are there any alias in apt that would let me reinstall the categories, i.e. webserver or fileserver? It hasn't gotten that bad yet. ;)

I think using (c)debootstrap would wipe out my current package installation list, so I'm refraining from using it. (That is, if I were to copy the package database from the new system, it would erase the old one.)

As always, feel free to correct me - I haven't mucked with the Debian packaging system for a long time, other than apt-get install bla :) – Albert H – 2012-03-26T15:22:36.667

1Copying the package database is easy: save dpkg --get-selections, and pipe it into dpkg --set-selections. That being said, if you just need to ensure certain tasks are installed, just use tasksel. You probably want at least minimal, probably standard. – ephemient – 2012-03-26T15:29:24.160

1Wow, thanks! :)

In the end, I did the unthinkable (don't try this at home) - I removed /var/lib/dpkg, /var/lib/apt, and /var/cache/apt. In the chroot, I installed the required files. Then from the debootstrap chroot, I copied those folders to the main system. From there things will work! – Albert H – 2012-03-29T16:19:48.003

One last question - now I have a clean package DB slate, but that means any programs that were still installed now don't have packages attached to them. What should I do to restore the packages from examining my system file list? (If there's no automated tool, I'm fine with just knowing what tools I should use to look up the packages - I can write a BASH script to automate the process for me.) – Albert H – 2012-03-30T02:56:51.210

@AlbertH apt-file can look up which packages files belong to. – ephemient – 2012-03-30T02:59:29.850