Linux – Remote reinstall of linux over ssh

debianinstallationlinuxremote

I have a small linux server that I need to reinstall linux on (Debian stable 64 bit x86).

I have physical access to the machine but it doesn't have any external devices such as a cdrom and does not appear to be able to boot from a network or USB stick.

It does have an existing installation of linux on though and I can ssh to the machine and have root access but it's badly broken and I have no real idea what state the machine is in so wish to wipe it out and do a completely fresh install.

Is there any way I can do this using only remote access using ssh and what i can download to the machine?

Best Answer

The way to achieve your goal, without having the ability to boot from cd/network/external device, is to use the existing installation to install a fresh OS to another filesystem and then, once you're done, tell the bootloader to boot to the new filesystem. This was much more common in times past (perhaps 10 years or more ago) than it is now, and if you search you will find discussion of exactly this. I have done this in the distant past with slackware, gentoo, linuxfromscratch and others, but I think it can be done, without too much effort, with most modern linux/BSD distributions.

For example, in Slackware's setup you can specify a 'target' which by default is /, but you would set it to where you had mounted your secondary filesystem.

Gentoo's installation handbook makes it quite clear; all you would need to think about would be the sections on 'preparing your disks' and 'configuring your bootloader'.

Having said all that, this is not trivial and if you don't have a good understanding of how things work, you're unlikely to get it right the first time. It will be an interesting educational experience, but since you have physical access, you'll probably get a quicker, better result by working out how to remove the constraint that means you can't use a more typical installation process. In other words, add a cd drive or something.