Hibernate Your Instance
When you hibernate an instance, we signal the operating system to perform hibernation (suspend-to-disk), which saves the contents from the instance memory (RAM) to your Amazon EBS root volume. We persist the instance's Amazon EBS root volume and any attached Amazon EBS data volumes. When you restart your instance, the Amazon EBS root volume is restored to its previous state, the RAM contents are reloaded, and the processes that were previously running on the instance are resumed. Previously attached data volumes are reattached and the instance retains its instance ID.
You can hibernate an instance only if it's enabled for hibernation and it meets the hibernation prerequisites.
If an instance or application takes a long time to bootstrap and build a memory footprint to become fully productive, you can use hibernation to pre-warm the instance. To pre-warm the instance, launch it, bring it to a desired state, and then hibernate it, ready to be resumed to the same state as needed.
We don't charge usage for a hibernated instance when it is in the stopped state.
We do charge for instance usage while the instance is in the stopping state
(unlike when you stop an instance without hibernating it)
when the contents of the RAM are transferred to the Amazon EBS root volume. We don't
charge usage
for data transfer fees, but we do charge for the storage for any Amazon EBS volumes,
including
storage for the RAM contents.
If you no longer need an instance, you can terminate it at any time, including when
it is in
a stopped (hibernated) state. For more information, see Terminate Your Instance.
Important
Hibernation is currently not supported on Windows instances.
Contents
Overview of Hibernation
The following diagram shows a basic overview of the hibernation process.
When you hibernate a running instance, the following happens:
-
When you initiate hibernation, the instance moves to the
stoppingstate. We signal the operating system to perform hibernation (suspend-to-disk), which freezes all the processes, saves the contents of the RAM to the Amazon EBS root volume, and then performs a regular shutdown. -
After the shutdown is complete, the instance moves to the
stoppedstate. -
Any Amazon EBS volumes remain attached to the instance, and their data persists, including the saved contents of the RAM.
-
In most cases, the instance is migrated to a new underlying host computer when it's restarted, which is the same as what happens when you stop and restart an instance.
-
When you restart the instance, the instance boots up and the operating system reads in the contents of the RAM from the Amazon EBS root volume before unfreezing processes to resume its state.
-
The instance retains its private IPv4 addresses and any IPv6 addresses when hibernated and restarted. We release the public IPv4 address and assign a new one when you restart it.
-
The instance retains its associated Elastic IP addresses. You're charged for any Elastic IP addresses associated with a hibernated instance. With EC2-Classic, an Elastic IP address is dissociated from your instance when you hibernate it. For more information, see EC2-Classic.
-
When you hibernate a ClassicLink instance, it's unlinked from the VPC to which it was linked. You must link the instance to the VPC again after restarting it. For more information, see ClassicLink.
For information about how hibernation differs from reboot, stop, and terminate, see Differences Between Reboot, Stop, Hibernate, and Terminate.
Hibernation Prerequisites
To hibernate an instance, the following prerequisites must be in place:
-
Instance families - The following instance families are supported: C3, C4, C5, M3, M4, M5, R3, R4, and R5, with less than 150 GB of RAM. Hibernation is not supported for *.metal instances.
-
Instance RAM size - The instance RAM size must be less than 150 GB.
-
Amazon Machine Image (AMI) - The AMI must be an HVM AMI that supports hibernation. The following AMIs support hibernation. To configure your own AMI to support hibernation, see Configuring an Existing AMI to Support Hibernation.
-
Amazon Linux AMI 2018.03 released 2018.11.16 or later
-
Ubuntu 18.04 LTS - Bionic* AMI released with serial 20190722.1 or later
* Disabling KASLR: To run hibernation on a newly launched instance with Ubuntu 18.04 LTS - Bionic, we recommend disabling KASLR (Kernel Address Space Layout Randomization). On Ubuntu 18.04 LTS, KASLR is enabled by default. For more information, see Disabling KASLR on an Instance (Ubuntu only).
-
-
Root volume type - The instance root volume must be an Amazon EBS volume, not an instance store volume.
-
Amazon EBS root volume size - The root volume must be large enough to store the RAM contents and accommodate your expected usage, for example, OS or applications. If you enable hibernation, space is allocated on the root volume at launch to store the RAM.
-
Amazon EBS root volume encryption - To use hibernation, the root volume must be encrypted to ensure the protection of sensitive content that is in memory at the time of hibernation. When RAM data is moved to the Amazon EBS root volume, it is always encrypted. Encryption of the root volume is enforced at instance launch. Use one of the following three options to ensure that the root volume is an encrypted Amazon EBS volume:
-
EBS “single-step” encryption: In a single run-instances API call, you can launch encrypted EBS-backed EC2 instances from an unencrypted AMI and also enable hibernation at the same time. For more information, see Using Encryption with EBS-Backed AMIs.
-
EBS encryption by default: You can enable EBS encryption by default to ensure all new EBS volumes created in your AWS account are encrypted. This way, you can enable hibernation for your instances without specifying encryption intent at instance launch. For more information, see Encryption by Default.
-
Encrypted AMI: You can enable EBS encryption by using an encrypted AMI to launch your instance. If your AMI does not have an encrypted root snapshot, you can copy it to a new AMI and request encryption. For more information, see Encrypt an Unencrypted Image during Copy and Copying an AMI.
-
-
Enable hibernation at launch - At launch, enable hibernation using the Amazon EC2 console or the AWS CLI. You cannot enable hibernation on an existing instance (running or stopped). For more information, see Enabling Hibernation for an Instance.
-
Purchasing options - This feature is available for On-Demand Instances and Reserved Instances. It is not available for Spot Instances. For more information, see Hibernating Interrupted Spot Instances.
Limitations
The following actions are not supported for hibernation:
-
Changing the instance type or size of a hibernated instance
-
Creating snapshots or AMIs from instances for which hibernation is enabled
-
Creating snapshots or AMIs from hibernated instances
You can't stop or hibernate instance store-backed instances.*
You can't hibernate an instance that has more than 150 GB of RAM.
You cannot hibernate an instance that is in an Auto Scaling group or used by Amazon ECS. If your instance is in an Auto Scaling group and you try to hibernate it, the Amazon EC2 Auto Scaling service marks the stopped instance as unhealthy, and may terminate it and launch a replacement instance. For more information, see Health Checks for Auto Scaling Instances in the Amazon EC2 Auto Scaling User Guide.
We do not support keeping an instance hibernated for more than 60 days. To keep the instance for longer than 60 days, you must restart the hibernated instance, stop the instance, and restart it.
We constantly update our platform with upgrades and security patches, which can conflict with existing hibernated instances. We notify you about critical updates that require a restart for hibernated instances so that we can perform a shutdown or a reboot to apply the necessary upgrades and security patches.
*For C3 and R3 instances that are enabled for hibernation, do not use instance store volumes.
Configuring an Existing AMI to Support Hibernation
To hibernate an instance that was launched using your own AMI, you must first configure your AMI to support hibernation. For more information, see Updating Instance Software.
If you use one of the supported AMIs, or you create an AMI based on one of the supported AMIs, you do not need to configure it to support hibernation. These AMIs are preconfigured to support hibernation.
- Amazon Linux
-
To configure an Amazon Linux AMI to support hibernation
-
Update to the latest kernel to 4.14.77-70.59 or later using the following command:
[ec2-user ~]$sudo yum update kernel -
Install the
ec2-hibinit-agentpackage from the repositories using the following command:[ec2-user ~]$sudo yum install ec2-hibinit-agent -
Reboot the instance.
-
Confirm that the kernel version is updated to 4.14.77-70.59 or greater using the following command:
[ec2-user ~]$uname -a -
Stop the instance and create an AMI. For more information, see Creating a Linux AMI from an Instance.
-
- Ubuntu
-
To configure an Ubuntu 18.04 LTS AMI to support hibernation
-
Update to the latest kernel to 4.15.0-1044 or later using the following command:
[ec2-user ~]$sudo apt update[ec2-user ~]$sudo apt dist-upgrade -
Install the
ec2-hibinit-agentpackage from the repositories using the following command:[ec2-user ~]$sudo apt install ec2-hibinit-agent -
Reboot the instance using the following command.
[ec2-user ~]$sudo reboot -
Confirm that the kernel version is updated to 4.15.0-1044 or greater using the following command:
[ec2-user ~]$uname -a
-
Enabling Hibernation for an Instance
To hibernate an instance, it must first be enabled for hibernation. At launch, enable hibernation using the console or the command line.
Important
You can't enable or disable hibernation for an instance after you launch it.
- Console
-
To enable hibernation using the console
-
Follow the Launching an Instance Using the Launch Instance Wizard procedure.
-
On the Choose an Amazon Machine Image (AMI) page, select an AMI that supports hibernation. For more information about supported AMIs, see Hibernation Prerequisites.
-
On the Choose an Instance Type page, select a supported instance type, and choose Next: Configure Instance Details. For information about supported instance types, see Hibernation Prerequisites.
-
On the Configure Instance Details page, for Stop - Hibernate Behavior, select the Enable hibernation as an additional stop behavior check box.
-
Continue as prompted by the wizard. When you've finished reviewing your options on the Review Instance Launch page, choose Launch. For more information, see Launching an Instance Using the Launch Instance Wizard.
-
- AWS CLI
-
To enable hibernation using the AWS CLI
Use the run-instances command to launch an instance. Enable hibernation using the
--hibernation-options Configured=trueparameter.aws ec2 run-instances --image-idami-0abcdef1234567890--instance-typem5.large--hibernation-options Configured=true --count1--key-nameMyKeyPair
- Console
-
To view if an instance is enabled for hibernation using the console
-
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
-
In the navigation pane, choose Instances.
-
Select the instance and, in the details pane, inspect Stop - Hibernation behavior. Enabled indicates that the instance is enabled for hibernation.
-
- AWS CLI
-
To view if an instance is enabled for hibernation using the AWS CLI
Use the describe-instances command and specify the
--filters "Name=hibernation-options.configured,Values=true"parameter to filter instances that are enabled for hibernation.aws ec2 describe-instances --filters "Name=hibernation-options.configured,Values=true"The following field in the output indicates that the instance is enabled for hibernation:
"HibernationOptions": { "Configured": true }
Disabling KASLR on an Instance (Ubuntu only)
To run hibernation on a newly launched instance with Ubuntu 18.04 LTS - Bionic, released with serial 20190722.1 or later, we recommend disabling KASLR (Kernel Address Space Layout Randomization). On Ubuntu 18.04 LTS, KASLR is enabled by default. KASLR is a standard Linux kernel security feature that helps to mitigate exposure to and ramifications of yet-undiscovered memory access vulnerabilities by randomizing the base address value of the kernel. With KASLR enabled, there is a possibility that the instance might not resume after it has been hibernated.
To learn more about KASLR, see Ubuntu Features.
To disable KASLR on an instance launched with Ubuntu
-
Connect to your instance using SSH. For more information, see Connecting to Your Linux Instance Using SSH.
-
Open the
/etc/default/grub.d/50-cloudimg-settings.cfgfile in your editor of choice. Edit theGRUB_CMDLINE_LINUX_DEFAULTline to append thenokaslroption to its end, as shown in the following example.GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295 nokaslr" -
Save the file and exit your editor.
-
Run the following command to rebuild the grub configuration.
[ec2-user ~]$sudo update-grub -
Reboot the instance.
[ec2-user ~]$sudo reboot -
Confirm that
nokaslrhas been added when running the following command.[ec2-user ~]$cat /proc/cmdlineThe output of the command should include the
nokaslroption.
Hibernating an Instance
You can hibernate an instance using the console or the command line if the instance is enabled for hibernation and meets the hibernation prerequisites. If an instance cannot hibernate successfully, a normal shutdown occurs.
- Console
-
To hibernate an Amazon EBS-backed instance using the console
-
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
-
In the navigation pane, choose Instances.
-
Select an instance, and choose Actions, Instance State, Stop - Hibernate. If Stop - Hibernate is disabled, the instance is already hibernated or stopped, or it can't be hibernated. For more information, see Hibernation Prerequisites.
-
In the confirmation dialog box, choose Yes, Stop - Hibernate. It can take a few minutes for the instance to hibernate. The Instance State changes to Stopping while the instance is hibernating, and then Stopped when the instance has hibernated.
-
- AWS CLI
-
To hibernate an Amazon EBS-backed instance using the AWS CLI
Use the stop-instances command and specify the
--hibernateparameter.aws ec2 stop-instances --instance-idsi-1234567890abcdef0--hibernate
- Console
-
To view if hibernation was initiated on an instance using the console
-
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
-
In the navigation pane, choose Instances.
-
Select the instance and, in the details pane, inspect State transition reason message. The message Client.UserInitiatedHibernate: User initiated hibernate indicates that hibernation was initiated on the instance.
-
- AWS CLI
-
To view if hibernation was initiated on an instance using the AWS CLI
Use the describe-instances command and specify the
state-reason-codefilter to see the instances on which hibernation was initiated.aws ec2 describe-instances --filters "Name=state-reason-code,Values=Client.UserInitiatedHibernate"The following field in the output indicates that hibernation was initiated on the instance.
"StateReason": { "Code": "Client.UserInitiatedHibernate" }
Restarting a Hibernated Instance
Restart a hibernated instance by starting it in the same way that you would start a stopped instance.
- Console
-
To restart a hibernated instance using the console
-
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
-
In the navigation pane, choose Instances.
-
Select a hibernated instance, and choose Actions, Instance State, Start. It can take a few minutes for the instance to enter the
runningstate. During this time, the instance status checks show the instance in a failed state until the instance has restarted.
-
- AWS CLI
-
To restart a hibernated instance using the AWS CLI
Use the start-instances command.
aws ec2 start-instances --instance-idsi-1234567890abcdef0
Troubleshooting Hibernation
Use this information to help you diagnose and fix issues that you might encounter when hibernating an instance.
Can't hibernate immediately after launch
If you try to hibernate an instance too quickly after you've launched it, you will get an error.
You must wait for about two minutes after launch before hibernating.
Takes too long to transition from stopping to
stopped, and memory state not restored after start
If it takes a long time for your hibernating instance to transition from the
stopping state to stopped, and the memory state is not
restored after you start, this could indicate that hibernation was not properly
configured.
Check the instance system log and look for messages that are related to hibernation.
To
access the system log, connect
to the instance or use the get-console-output command. Find log lines from the
hibinit-agent. If the log lines indicate a failure or the log
lines are missing, there was most likely a failure configuring hibernation at
launch.
For example, the following message indicates that the instance root volume is not
large
enough: hibinit-agent: Insufficient disk space. Cannot create setup for
hibernation. Please allocate a larger root device.
If the last log line from the hibinit-agent is
hibinit-agent: Running: swapoff /swap, hibernation was successfully
configured.
If you do not see any logs from these processes, your AMI might not support hibernation. For information about supported AMIs, see Hibernation Prerequisites. If you used your own AMI, make sure that you followed the instructions for Configuring an Existing AMI to Support Hibernation.
Instance "stuck" in the stopping state
If you hibernated your instance and it appears "stuck" in the stopping
state, you can forcibly stop it. For more information, see Troubleshooting Stopping Your Instance.


