1

I have an EC2 instance (Amazon Linux AMI 2018.03) which I can hibernate from outside it — using the console, or AWS CLI.

Is there any way to hibernate it by running a command inside it? Some Linux distros support systemctl hibernate but this one doesn't even have systemctl.

For those who tend to answer along the lines "you don't need this, do that instead" I confirm that I know what I am doing and I do need hibernation, not stop/snapshot/restore etc.

Update:

Calling AWS CLI from inside the VM is not desirable because it calls an API external to the VM (which then apparently calls something back inside the VM) — credentials/IAM roles need to be maintained etc. What is it that EC2 calls inside the VM to get it suspend all processes, save RAM to disk and shutdown?

1
  • Virtual machines are not very different to bare metal solutions, just the disk driver and ACPI drivers might be a little different. If you don't want to use the AWS tools provided then look for generic solutions on how to make linux hibernate. Sep 5, 2022 at 13:56

1 Answer 1

1

You're probably using Amazon Linux AMI anyways because it comes with all the AWS tools preinstalled. So, use the standard clients to tell the AWS controller to make a snapshot of the VM for later restoring, and turn it off. That's in the end what hibernation does.

Note: hibernation is not really a great idea for a VM on AWS in many cases. Many instance types will still be billed in shut down mode. Make a snapshot/image, save it, and delete the VM to avoid that problem. Generally, a common strategy for cloud VMs is that your VMs are actually throwaway items, and there'd be no situation where you'd want to hibernate them. You store the data you need to resume service on some volume, which will be used by any freshly booted copy of your VM, right away. That way, you actually get reliability.

13
  • 1
    "make a snapshot of the VM for later restoring" — do you mean disk/volume snapshot? If so then sorry, this does not answer the question at all. I do have a valid use-case for hibernation (as opposed to shutdown/delete/restore).
    – Greendrake
    Sep 5, 2022 at 7:25
  • @Greendrake but hibernation is literally just storing the RAM contents to disk, turning off, and restoring on boot. That's what it does! Sep 5, 2022 at 7:31
  • I know! And that is exactly what I need. Do I necessarily need to tell why?
    – Greendrake
    Sep 5, 2022 at 7:31
  • @Greendrake with "snapshot" I mean this: aws.amazon.com/about-aws/whats-new/2018/11/… Sep 5, 2022 at 7:31
  • 1
    I think AWS loves their REST APIs so much, this might be the directest way… not sure though, but I don't think there's an easier way. What I dislike is the dissemination of management secrets into a VM, indeed. Sep 5, 2022 at 7:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .