Hibernate your Linux instance
When you hibernate an instance, Amazon EC2 signals the operating system to perform hibernation (suspend-to-disk). Hibernation saves the contents from the instance memory (RAM) to your Amazon Elastic Block Store (Amazon EBS) root volume. Amazon EC2 persists the instance's EBS root volume and any attached EBS data volumes. When you start your instance:
-
The EBS root volume is restored to its previous state
-
The RAM contents are reloaded
-
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, you:
-
Launch it with hibernation enabled.
-
Bring it to a desired state.
-
Hibernate it, ready to be resumed to the same state as needed.
You're not charged for instance usage for a hibernated instance when it is in the
stopped
state. You are charged for instance usage while the instance is in
the stopping
state, when the contents of the RAM are transferred to the EBS
root volume. (This is different from when you stop an
instance without hibernating it.) You're not charged for data transfer. However,
you are charged for storage of any 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.
For information about using hibernation on Windows instances, see Hibernate Your Windows Instance in the Amazon EC2 User Guide for Windows Instances.
For information about hibernating Spot Instances, see Hibernate interrupted Spot 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
stopping
state. Amazon EC2 signals the operating system to perform hibernation (suspend-to-disk). The hibernation freezes all of the processes, saves the contents of the RAM to the EBS root volume, and then performs a regular shutdown. -
After the shutdown is complete, the instance moves to the
stopped
state. -
Any EBS volumes remain attached to the instance, and their data persists, including the saved contents of the RAM.
-
Any Amazon EC2 instance store volumes remain attached to the instance, but the data on the instance store volumes is lost.
-
In most cases, the instance is migrated to a new underlying host computer when it's started. This is also what happens when you stop and start an instance.
-
When you start the instance, the instance boots up and the operating system reads in the contents of the RAM from the EBS root volume, before unfreezing processes to resume its state.
-
The instance retains its private IPv4 addresses and any IPv6 addresses. When you start the instance, the instance continues to retain its private IPv4 addresses and any IPv6 addresses.
-
Amazon EC2 releases the public IPv4 address. When you start the instance, Amazon EC2 assigns a new public IPv4 address to the instance.
-
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 disassociated 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 starting 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:
-
Supported instance families
-
C3, C4, C5
-
I3
-
M3, M4, M5, M5a, M5ad
-
R3, R4, R5, R5a, R5ad
-
T2, T3, T3a
-
-
Instance RAM size - must be less than 150 GB.
-
Instance size - not supported for bare metal instances.
-
Supported AMIs (must be an HVM AMI that supports hibernation):
-
Amazon Linux 2 AMI released 2019.08.29 or later.
-
Amazon Linux AMI 2018.03 released 2018.11.16 or later.
-
Ubuntu 18.04 LTS - Bionic AMI released with serial number 20190722.1 or later.*
-
Ubuntu 16.04 LTS - Xenial AMI.* (Additional configuration is required.)
*We recommend disabling KASLR on instances with Ubuntu 18.04 LTS - Bionic and Ubuntu 16.04 LTS - Xenial. For more information, see Disable KASLR on an instance (Ubuntu only).
To configure your own AMI to support hibernation, see Configure an existing AMI to support hibernation.
Support for other versions of Ubuntu and other operating systems is coming soon.
For information about the supported AMIs for Windows, see Hibernation prerequisites in the Amazon EC2 User Guide for Windows Instances.
-
-
Root volume type - must be an EBS volume, not an instance store volume.
-
Supported EBS volume types - General Purpose SSD (
gp2
andgp3
) or Provisioned IOPS SSD (gp2
andgp3
). If you choose a Provisioned IOPS SSD volume type, to achieve optimum performance for hibernation, you must provision the EBS volume with the appropriate IOPS. For more information, see Amazon EBS volume types. -
EBS root volume size - 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.
-
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 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 EBS volume:
-
EBS "single-step" encryption: You can launch encrypted EBS-backed EC2 instances from an unencrypted AMI and also enable hibernation at the same time. For more information, see Use 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 Copy an AMI.
-
-
Enable hibernation at launch - You cannot enable hibernation on an existing instance (running or stopped). For more information, see Enable 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 Hibernate interrupted Spot Instances.
Limitations
-
When you hibernate an instance, the data on any instance store volumes is lost.
-
You can't hibernate an instance that has more than 150 GB of RAM.
-
If you create a snapshot or AMI from an instance that is hibernated or has hibernation enabled, you might not be able to connect to the instance.
-
You can't change the instance type or size of an instance with hibernation enabled.
-
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 might 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 start the hibernated instance, stop the instance, and start 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 start for hibernated instances so that we can perform a shutdown or a reboot to apply the necessary upgrades and security patches.
Configure 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 Update instance software on your Amazon Linux instance.
If you use one of the supported AMIs (except Ubuntu 16.04 LTS), or if 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. To configure Ubuntu 16.04 LTS to support hibernation, you need to install the linux-aws-hwe kernel package version 4.15.0-1058-aws or later and the ec2-hibinit-agent. For the configuration steps, choose the Ubuntu 16.04 - Xenial tab below.
Enable hibernation for an instance
To hibernate an instance, it must first be enabled for hibernation. To enable hibernation, you must do it while launching the instance.
You can't enable or disable hibernation for an instance after you launch it.
Disable KASLR on an instance (Ubuntu only)
To run hibernation on a newly launched instance with Ubuntu 16.04 LTS - Xenial or Ubuntu 18.04 LTS - Bionic released with serial 20190722.1 or later, we recommend disabling KASLR (Kernel Address Space Layout Randomization). On Ubuntu 16.04 LTS or 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 Connect to your Linux instance using SSH.
-
Open the
/etc/default/grub.d/50-cloudimg-settings.cfg
file in your editor of choice. Edit theGRUB_CMDLINE_LINUX_DEFAULT
line to append thenokaslr
option 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
nokaslr
has been added when running the following command.[ec2-user ~]$
cat /proc/cmdline
The output of the command should include the
nokaslr
option.
Hibernate an instance
You can hibernate an instance if the instance is enabled for hibernation and meets the hibernation prerequisites. If an instance cannot hibernate successfully, a normal shutdown occurs.
Start a hibernated instance
Start a hibernated instance by starting it in the same way that you would start a stopped instance.
Troubleshoot hibernation
Use this information to help 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 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 if 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 the 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 Configure 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
Troubleshoot stopping your
instance.