AWS-issue with Cloud-init service/cloud-config script

In certain cases, the cloud-init service might stop and that would cause the AWS instance to not boot. Use the following steps to recover:

  1. Launch a new recovery instance of type t2.micro(x86x64) in the same Availability Zone (ie us-east-1a). Ensure that you enable a public ip or associate an elastic ip with this recovery instance to access internet.
  2. Detach the root volume of the impaired instance
  3. Attach the volume as a secondary volume to the recovery instance.
  4. SSH into the recovery instance and mount the volume the secondary volume.
    # sudo su <—————— become a root user.
    # sudo mkdir /mnt/recovery <—————— make a directory.
    # sudo mount /dev/xvdf1 /mnt/recovery <—————— Mount the secondary volume to the recovery instance.
    # mount -o bind /proc /mnt/recovery/proc
    # mount -o bind /dev /mnt/recovery/dev
    # mount -o bind /sys /mnt/recovery/sys
    # chroot /mnt/recovery # cd / # ll /etc/resolv.conf # rm -f /etc/resolv.conf # echo "nameserver" > /etc/resolv.conf # apt update # apt remove cloud-init # apt purge cloud-init -y # apt install cloud-init -y # cd /var/lib/cloud/ # rm -rf * # cd # exit <———— we have come out of the chroot using exit command. # umount /mnt/recovery/{proc,sys,dev} <———— and now we have to unmount the secondary volume. # umount /mnt/recovery # lsblk <———— to confirm if volume has been unmounted.
  5. Now, you can detach the secondary volume and attach it to the original instance: as /dev/sda1.
  6. Now, create a new AMI from the impaired instance and launch a new instance of your choice.

Comments are closed.