Hibernation allows you to pause an EC2 instance, saving its memory (RAM) to persistent storage (an EBS volume), and then resume it later, picking up exactly where you left off without the typical boot-up process.

Let’s see this in action. Imagine you have a critical application running on an EC2 instance. It’s configured with a specific in-memory state that’s expensive to regenerate. Instead of stopping and starting the instance, which would clear its RAM, you can hibernate it.

Here’s a hypothetical aws ec2 stop-instances command with the hibernate option:

aws ec2 stop-instances \
    --instance-ids i-0123456789abcdef0 \
    --hibernate \
    --region us-east-1

After this command executes successfully, the instance state will change from running to stopped. The contents of its RAM are written to a snapshot of the root EBS volume. When you later start this instance again using aws ec2 start-instances --instance-ids i-0123456789abcdef0 --region us-east-1, it will resume with its RAM state intact. The instance boot process is bypassed, and applications will be available much faster than a traditional start.

The core problem hibernation solves is the time and resource cost associated with cold starts for applications that maintain significant in-memory state. Think of in-memory databases, caching layers, or complex scientific simulations where re-establishing the in-memory state after a reboot is time-consuming and potentially disruptive. By enabling hibernation, you can stop these instances, conserve costs (you only pay for EBS storage when stopped), and then resume them with their previous in-memory state, drastically reducing recovery time.

Internally, when you hibernate an instance, AWS takes a snapshot of the instance’s RAM and saves it to the root EBS volume’s snapshot. This snapshot is encrypted and stored. When the instance is started, the RAM contents are restored from this snapshot, and the operating system boots directly into the state it was in before hibernation. This differs from a regular stop/start, where the RAM is cleared, and the OS goes through a full boot sequence.

The key levers you control are:

  • Instance Type Support: Not all instance types support hibernation. You need to use instance types that support it (e.g., M4, M5, R4, R5, T3, C4, C5, I3, G3, etc. – check AWS documentation for the most current list).
  • Root EBS Volume Type: The root EBS volume must be encrypted. Unencrypted volumes do not support hibernation.
  • RAM Size Limits: There are limits on the amount of RAM an instance can have to support hibernation. For Linux instances, the maximum RAM size is typically 150 GiB. For Windows, it’s generally 16 GiB. Again, consult AWS documentation for specifics.
  • Disable Boot (for specific scenarios): You can configure hibernation to be the default behavior when an instance is stopped. This is done by setting the HibernateConfig attribute for the instance.

When you enable hibernation for an instance that supports it and has an encrypted root EBS volume, the StopInstances API call gains an additional --hibernate flag. If this flag is present, AWS performs the RAM-to-EBS snapshot operation. If the instance has a large amount of RAM, this operation can take a significant amount of time, during which the instance remains in a stopping state. Once the hibernation snapshot is complete, the instance transitions to stopped. Upon StartInstances, the RAM is restored, and the instance transitions to running.

The hibernate metadata, which includes the state of the CPU registers and other critical system information, is stored alongside the RAM snapshot. This allows the operating system to resume execution precisely from the point it was interrupted, rather than starting from a clean slate. The root EBS volume itself is not modified during the hibernation process; its contents are simply used to create the RAM snapshot.

A common misconception is that hibernating an instance is as fast as a regular stop. While resuming is much faster than a cold start, the hibernation process itself (writing RAM to EBS) can take several minutes, especially for instances with large amounts of RAM. You’ll see the instance state transition through stopping for an extended period before reaching stopped.

The next challenge you’ll likely encounter is managing the lifecycle of hibernated instances, particularly when dealing with automated scaling or scheduled shutdowns, ensuring you have a strategy for when and how to resume them.

Want structured learning?

Take the full Ec2 course →