Reinstall base Ubuntu without formatting or removing manually installed packages

Solution 1:

For the future:

If you have a remote server in a Data centre 1000 miles away you'd better have an IPKVM switch installed so you don't have to rely solely on ssh to reach it.

If the server is on Mount Everest: add an Iridium phone and a modem as well...

Then you can have a bootable 512MB FAT CloneZilla partition on that machine (I use an SLC USB stick) and use the console to boot to that and back-up an image of your system partition(s) to your data drive and then copy the previous system image on the secondary partition of your USB stick before you start adding trusty-proposed to the server. (I keep most of my system back-ups on the data drive: they're only 6GB)

For now:

  • Take an apt-backup
  • Go through your /var/log/apt/history*
  • Make your own automagical script that does an apt-get purge of all the stuff you really don't want/need any more from the data in the previous step
  • Execute the script while praying to Linus of the Torvalds
  • Update your repositories like you want them to be (like removing trusty-proposed)
  • Reboot while praying to Richard of the Stallmans
  • If everything works out: implement the IPKVM switch solution above.

Solution 2:

OK, My answer assumes you can, and have backed up your user directory, and everything you want to save. which reduces your question to how do I install Ubuntu on a remote server? To which there are many solutions.

For this, you could use DRBL, to remotely deploy an operating system, with a variety of options for booting. You can look into it here: http://drbl.org/installation/

There is Clobber: http://cobbler.github.io/manuals/quickstart/

There is cloneZilla, which can back up and restore over a network. The link is for windows, but the same methods apply for linux. Alternatively, you could make an ubuntu boot image locally, and install it using clonezilla. http://opensourceforu.efytimes.com/2013/12/restore-partitions-network-using-clonezilla/

Alternatively, you could try using dd_rescue, or netcat

A useful search term might be "Server Provisioning". There are more options then these.

There are bruteforce methods too.

$ ls /
bin  boot  cdrom  dev  etc  home  initrd.img  initrd.img.old  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  vmlinuz  vmlinuz.old

and your PATH were like this:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

if your root directory were something like this, if you over wrote /etc, and /usr with "clean" versions, you would be overwriting, pretty much every piece of installed software, and the config files for it. That would be hackerish to say the least, if not a completely horrible idea. Running apt-get purge would be much safer, Or perhaps you could fine tune the process a little bit. You might then also want to include a clone of your old ssh config file in /etc/ssh/ before trying to restart the services with new config files.

There is also a tool that lets you dump a running kernel and upgrade without rebooting. For that you could check out Kslpice, or kGraft

If all you are having trouble with is repos and package management, I'm not sure why you would want to dump the kernel, mbr, boot partition etc..

So any how, I hope Ive given you some ideas to look into. There are many ways to depoly a server remotely.