Skip to content

Why did my Amazon EC2 Linux instance reboot or restart itself?

4 minute read
2

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.
  • You activated Reboot instance during Amazon Machine Image (AMI) creation.
  • AWS Systems Manager rebooted a managed instance.

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 How do I troubleshoot status check failures for my EC2 Linux instance?

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 AMI, Amazon EC2 activates Reboot instance by default and reboots the instance before it creates the AMI. This reboot appears in the CreateImage event, not the RebootInstances event.

If you created an AMI lifecycle policy, under Instance reboot, check whether you set Reboot instance at policy run to Yes. If it is, then the instance rebooted during AMI creation.

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

View Run Command History to check whether Systems Manager rebooted the instance

If you configure a patching operation on your instance with RebootOption set to RebootIfNeeded, then Systems Manager reboots the instance during a patch.

To check whether Systems Manager ran a Run Command, complete the following steps:

  1. Open the Systems Manager console.
  2. In the navigation pane, choose Run Command.
  3. Choose the Command history tab
  4. In the search box, enter your instance ID to see all commands that Systems Manager ran for the instance.

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 blocks my EC2 instance reboot?

AWS OFFICIALUpdated 5 months ago