2

I have a remote server (on the other side of the country) that has become corrupted in some way. I still have ssh access to it. Is it possible to overwrite the OS partition while it's running?

In the past I've managed to image a new SSD by using dd over ssh, but that computer was booted from a gparted usb stick. The only OS I have access to on that remote server is the one on the hard disk; no removable media is or will be available.

What will overwriting a currently running OS do? Can I load the disk image into a ram drive and run dd on the current disk? Perhaps I could make a second partition and dual boot with gparted or some other tool.

The image I will be writing to the disk has ssh with default credentials already enabled, so once I boot into the new image I should be able gain access.

This is my own hardware running at a remote location. The only access I have is through SSH

2 Answers2

3

Here is how I got it to work:

Step 1: Create a new partition. You can use any number of utilities to do this, I used cfdisk since it was available

Step 2: Image that new partition with a live distro that has SSH enabled and default username and password. In my case the old OS was on /dev/sda1 and the new one was on /dev/sda2. The new OS must be able to accept an SSH connection from boot without any prompts, or you will lose contact with your remote computer. It must also have the network properly configured. Either set a proper static IP, subnet mask, gateway, etc; or use DHCP and use your remote router to find the computer's new IP address.

Step 3: Run update-grub to add it to the boot options.

Step 4: View the file /boot/grub/grub.cfg and find the menuentry for the new OS image. It should look something like this: menuentry "KUbuntu 16.04 amd64 desktop (live)" --class windows --class os. What you need is the label in the quotes, in this case: KUbuntu 16.04 amd64 destop (live)

Step 5: Open /etc/default/grub in any editor and look for GRUB_DEFAULT=. Make sure it is set to GRUB_DEFAULT=saved.

Step 6: Run grub-reboot followed by your chosen menu entry in quotes. In this case grub-reboot "KUbuntu 16.04 amd64 desktop (live)"

Step 7: Run sudo reboot to get your remote computer to reboot. If you have done everything right you should be able to SSH into the new system once it boots.

Step 8: From your new operating system, overwrite the image of the original OS. In my case it was on /dev/sda1. This will also overwrite the grub settings on the boot partition causing you to boot into the updated OS on the original partition next time you boot. Again, what ever OS you put on that partition must have SSH enabled, default username and password, and network settings configured already.

Step 9: Reboot and you should be in your newly imaged operating system.

0

It is impossible to overwrite your system's installation while running that system.

You need to either have physical access to the server or access to tools provided by your server's host to do the tasks you want to do.

Consult with the hosting provider, their documentation, or the owner of the physical server to find out the method to complete your tasks.

Nmath
  • 12,664