How to fix Master Boot Record (MBR) in AWS EC2 instance

This was for the first time I was working on an EC2 instance having Windows operating system installed on it. For first few months, the server was working fine but during maintenance it got crashed. It became a nightmare when me and my team found that the MBR has been crashed and the machine is unable to boot. The business got down and there was a pressure from everyone to bring server back because were loosing business. (To avoid such situation, I always recommend taking backups which can bring us back to the earlier state.).

When you come across situations like the one above, Google Search is the first place where you go to find help. Any blog article or any answer over Stackoverflow seems to be a savior but in our case, we found none to help us out. The entire team was struggling with reading AWS documentation. At last, we were able to fix the situation. Thank God!

Now, the purpose of writing this article is to help the community to find at least this as a resource on how to get the stuff fixed when it really happens.
Knowledge required:
You should have following knowledge before you start following these steps.
  • AWS credentials
  • Concept of volumes and instance. How they are connect to each other.
  • Basic steps of taking snapshots, launching a new instance and attaching/detaching of volumes from instance.
Now you are ready to start so lets get the MBR of your broken instance fixed.
  1. Take Snapshot: Before you start playing with instance, it is better to take snapshot to avoid loosing data. We want to recover MBR without loosing any data. This backup will help us restart the process in case we encounter any data loss.
  2. Label properly: Make sure you label every instance and volume properly so that we done mix them with other instances/volumes.
  3. Detach volume: Detach the volume from the instance.
  4. Launch new instance: Launch a new instance having same settings as the original instance. 
  5. Attach volume: Now attached the original volume (detached above) with the newly launched instance. If you don't see the instance in the instance list make sure the zone for both instance are same.
  6. Remote Desktop: Connect instance with RemoteDesktop. Make sure that the attached volume is available as a secondary drive and data is accessible. If you don't see your volume visible follow this to troubleshoot.
  7. Instance EC2Rescue: Download AWS EC2Rescue tool from here and install it.
  8. Fix the MBR:
  9. Run the rescue tool, select Diagnose and Repair option and proved the boot directory of the attached drive to fix. This tool will fix the Boot Record in the drive.
  10. Once the rescue tool completes the fixing. Shutdown the instance, detach the drive from this instance and attach back to the original instance.
  11. Start the original instance and it will boot successfully.

Feel free to share your experience in the comments box below.
Credits:
Thanks to my friend Safeer Ansari for proof reading the article and suggesting improvements.

Comments