EC2 instance /etc folder deleted , couldnt connect now AMI- ami-04b4f1a9cf54c11d0

0

I have launched an ec2 instance ubuntu ,inside the OS , I have deleted the /etc full folder ,now the session got terminated , I couldn't able to connect through ssh, I need that ec2 instance to connect and work with same system . how to get the access to that instance access back with minimal downtime, all app server is running , I can connect to web to that server application

1 Answer
3

Try this:

  1. Stop the Instance and Create a Backup
  • Stop the Instance: Go to the AWS Management Console, navigate to the EC2 dashboard, and stop the affected instance.

  • Create a Snapshot: Take a snapshot of the root volume to ensure you have a backup before making any changes.

  1. Detach and Attach the Root Volume
  • Detach the Root Volume:

  • In the EC2 dashboard, select the instance and detach the root volume.

  • Attach the Volume to Another Instance:

  • Attach the root volume to a temporary EC2 instance as a secondary volume.

  1. Repair the /etc Folder
  • Mount the Volume:

  • SSH into the temporary instance.

  • Mount the attached volume (e.g., /dev/xvdf) to a directory:

sudo mkdir /mnt/temp
sudo mount /dev/xvdf1 /mnt/temp

  • Restore the /etc Folder:

Copy the /etc folder from the temporary instance to the mounted volume:

sudo cp -r /etc /mnt/temp/

  • Ensure permissions are correct:
sudo chmod -R 755 /mnt/temp/etc

  1. Reattach the Volume
  • Detach the repaired volume from the temporary instance.

  • Reattach it as the root volume to the original instance.

  1. Start the Original Instance
  • Start the original instance and check if it boots correctly.

  • Test SSH access to ensure the issue is resolved.

  1. Prevent Future Issues
  • Regularly back up critical system files using snapshots or AMIs.

  • Use IAM roles and policies to restrict access to sensitive directories.

EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions