Why did my EC2 Linux instance reboot or restart itself?

3 minute read
1

I want to know why my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance unexpectedly reboots or restarts.

Short description

Your instance might unexpectedly reboot or restart because of the following reasons:

  • The instance failed its status checks.
  • There's an issue with the underlying hardware that hosts your instance, and Amazon EC2 restarted the instance to move it to healthy hardware.
  • Scheduled maintenance on your instance initiated a reboot.
  • A user or application inside your server rebooted the instance.
  • There's a kernel bug.

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Check your Health Dashboard

Check the AWS Health Dashboard for instance reboot events, such as simplified automatic recovery, scheduled maintenance, and retirement. To act on the health notifications, reschedule the scheduled event, or manually stop and start the instance.

View status checks

Use the Amazon EC2 console or the AWS CLI to view the instance's status checks. If the instance failed a status check, then see Why is my EC2 Linux instance unreachable and failing its status checks?

View system logs

If the instance didn't fail a status check, then the instance might reboot because of issues with the operating system (OS). To troubleshoot OS-level issues, check the /var/log/messages and /var/log/syslog system logs. If the instance failed the status check, then reboot the instance to retrieve the system logs.

Then, troubleshoot the error that's listed in the system log.

View reboot history

To check whether a user or an application inside the server initiated the reboot, run the following commands:

grep reboot /home/*/.bash_history# grep reboot /root/.bash_history# history | grep -i reboot
history | grep -i init
last reboot

Check the CloudTrail event history

Instance reboots that you initiated on the Amazon EC2 console or AWS CLI appear in AWS CloudTrail Event history. Check your CloudTrail event history for RebootInstances events.

Note: When you create an Amazon Machine Image (AMI), the NoReboot parameter is set to false by default. Because Amazon EC2 automatically reboots the instance before it creates the AMI, the reboot appears in the CreateImages trail, not the RebootInstances trail.

To automatically recover instances that reboot because of hardware issues, configure Amazon CloudWatch action based recovery.

Update your kernel

Note: It's a best practice to create an AMI backup of the instance before you update packages on it. This configuration allows you to revert changes, if needed.

To update your kernel, complete the following steps:

  1. To check the kernel version that the instance uses, run the following command:

    sudo uname -r
  2. To update the kernel, run one of the following commands based on your Linux OS:
    Red Hat Enterprise Linux (RHEL) or Amazon Linux:

    sudo yum update kernel

    SUSE Linux Enterprise Server (SLES):

    sudo zypper up kernel-default

    Ubuntu:

    sudo apt upgrade linux-image-aws
  3. To reboot the instance and use the new kernel, run the following command:

    sudo reboot

Related information

Troubleshoot Amazon EC2 Linux instances with failed status checks

Types of status checks

Manage AWS Health notifications in AWS User Notifications

How do I revert to a known stable kernel after an update prevents my Amazon EC2 instance from rebooting successfully?

AWS OFFICIAL
AWS OFFICIALUpdated a month ago