Suspend and resume a VM


This document describes how to suspend and resume a virtual machine (VM) instance. For information about how to stop and start an instance, see Stopping and starting an instance. For information about the instance lifecycle, see Instance Life Cycle documentation.

If you want to keep your VM instance around but do not want to be charged for it when it is not in use, you can suspend the VM. When you suspend a VM, Google preserves the VM in your project and moves the contents of the VM's memory to storage. While the VM is suspended, Google only charges for the storage used to preserve the VM's memory. Attributes like static IP addresses remain in place so that network functions work as expected when you resume the VM. After resuming, Google moves the VM's memory from storage back to the instance, and starts charging you for the now-running VM instance.

Suspending an instance is ideal for:

  • Development and test environments that are not being fully utilized during off periods, such as during evenings or weekends, for cost savings or faster initialization than creating new VM instances.
  • Applications that require a long period of initialization after the instance has finished booting, but before the application is ready to service its first request, such as virtual developer workstations or complex Java applications.

How suspension works

Suspending an instance sends an ACPI S3 suspend signal to the instance's operating system. Suspending an instance is analogous to closing the lid of your laptop, putting the instance into a SUSPENDED state.

Suspending an instance differs from stopping an instance in the following ways:

With the exception of local SSD data, all resources that are attached to the instance remain attached to the instance and will be charged, including persistent disks and static or reserved external IP addresses. All of these resources are charged according to the price sheet, even if an instance is suspended.

You cannot suspend an instance by using the standard processes that are built into the guest environment. Commands, such as the systemctl suspend command in Ubuntu 16.04 and later, are not available. You can only use the Google Cloud CLI or the Compute Engine API to suspend an instance.

If you don't care about restoring an instance's memory and device state when you resume the instance later, you can stop the instance instead, which does not incur additional storage charges.

Before you begin

Limitations

The following limitations apply for this feature:

  • You cannot suspend an instance that uses a GPU.
  • You can suspend an instance that has attached local SSD, but the local SSD contents must be discarded using a special flag for discarding local SSD data.
  • You cannot suspend an instance by using the standard processes that are built into the guest environment. Commands, such as the systemctl suspend command in Ubuntu 16.04 and later, are not available. The in-guest signal is ignored.
  • You can only suspend an instance for up to 60 days before the VM is automatically stopped.
  • You cannot suspend instances with more than 120 GB of memory.
  • You can suspend preemptible instances, but the preemptible instance might be terminated before it is successfully suspended.
  • You cannot suspend an E2 instance.
  • You cannot suspend a Confidential VM.

Local SSDs and preemptible VMs

Local SSD content is not preserved when an instance is suspended. By default, suspending an instance that has a local SSD returns an error. You can override this default behavior by specifying a flag to discard local SSD data, which lets the instance be suspended and resumed, but discards the contents of the local SSD in the process. In this scenario, Compute Engine resumes the instance with the same number of local SSD volumes attached, but the volumes will be empty and uninitialized.

You can suspend a preemptible VM but if preemption (not the advance warning that precedes the preemption) occurs before the suspend operation completes, the suspend exits and the instance is preempted.

OS compatibility

Most operating systems (OSes) offered on Compute Engine support the suspend and resume functionality, but there are a few OSes that do not. Review the OS details page for the full list.

Pricing

When you suspend an instance, you are charged for:

  • Instance memory (see Suspended VM instances).
  • Any persistent disk usage for the boot disk and any additional disks attached to the instance (see Persistent disk pricing).
  • Any static IPs attached to the instance.
  • Suspending VMs might save on your software licensing fees. For example, if you suspend Windows VMs, you do not incur Windows license fees. License fees for other images might have different terms and conditions and may result in charges even when suspended.

Suspend an instance

To suspend an instance, use the Cloud console , the gcloud CLI, or the API.

You cannot suspend an instance by using the standard processes that are built into the guest environment. You can use the Cloud console , the Google Cloud CLI, or the API to suspend an instance.

Suspend operation can fail if it's triggered too soon after the instance was started. The instance needs to be fully started (including processes like Guest Agent) for the suspend operation to succeed.

Console

  1. In the Cloud console, go to the VM instances page.

    Go to the VM instances page

  2. Select one or more instances to suspend.

  3. Click Suspend.

  4. When prompted, if you want to discard local SSD data, select Discard the SSD content. When your instance is resumed, any local SSD data on the instance will have been discarded.

gcloud

To suspend an instance in the Google Cloud CLI:

 gcloud compute instances suspend VM_NAME

After you make a request to suspend an instance, it can take some time for Compute Engine to preserve all the data necessary for the instance. During this time, you continue to be charged for the instance while it remains running.

A suspended instance is marked by SUSPENDED status. Check an instance's status by making a describe request:

gcloud compute instances describe VM_NAME

To suspend an instance with local SSD data, you must discard the local SSD data by providing the beta --discard-local-ssd flag:

gcloud beta compute instances suspend VM_NAME --discard-local-ssd

API

In the API, make a request using the instances.suspend method:

https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/suspend

Replace the following:

  • PROJECT_ID: the project ID
  • ZONE: the zone of the VM
  • VM_NAME: the instance that you want to suspend

After you make a request to suspend an instance, it can take some time for Compute Engine to preserve all the data necessary for the instance. During this time, you are charged for the instance while it remains running.

Compute Engine marks suspended instance with the SUSPENDED status. Check an instance's status by making a GET request:

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME

The instance's status is visible in the status field. For example:

...
"zone": "https://content.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a",
"status": "SUSPENDED",
"name": "example-vm",
...

To suspend an instance with local SSD data, you must discard the local SSD data by providing the discardLocalSsd query parameter, which is currently in beta:

https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/suspend?discardLocalSsd=true

Resume a suspended instance

You can only resume an instance if there is sufficient capacity in the zone where the VM resides. In the majority of cases, this is not an issue but if you do experience capacity issues, retry your resume request again at a later time.

To resume a suspended instance, use the Cloud console , the gcloud CLI, or the API.

Console

  1. In the Google Cloud console, go to the VM instances page.

    Go to the VM instances page

  2. Select one or more instances to resume.

  3. Click Start/Resume.

gcloud

To resume an instance in the Google Cloud CLI:

 gcloud compute instances resume VM_NAME

After you make a request to resume an instance, it can take some time for Compute Engine to restore all the data necessary for the instance. During this time, you are charged for the instance while it is resuming.

An instance is resumed when it is marked as RUNNING. Check an instance's status by making a describe request:

gcloud compute instances describe VM_NAME

API

Make a request to the instances.resume method:

https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/resume

Replace the following:

  • PROJECT_ID: the project ID for this request
  • ZONE: the zone of the VM
  • VM_NAME: the instance to resume

After you make a request to resume an instance, it can take some time for Compute Engine to restore all the data necessary for the instance. During this time, you are charged for the instance while it is resuming

Compute Engine marks the instance with the RUNNING status once the resume is complete. Check an instance's status by making a GET request:

GET https://compute.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instances/example-instance

The instance's status is visible in the status field. For example:

...
"zone": "https://content.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a",
"status": "RUNNING",
"name": "example-instance",
...

Suspend process

When you make a suspend request, you send an ACPI suspend signal to the VM instance. If the VM does not respond to the ACPI S3 suspend signal within a couple of minutes, Compute Engine cancels the suspend attempt and returns the VM to a RUNNING state.

The following table describes the effect of suspending a VM instance on its associated resources:

Resource Support
Memory Only VMs with less than or equal to 120 GB of memory can be suspended
Local SSD Local SSD data is discarded
Persistent disk Persistent HDD and SSD disks are retained
IP addresses Ephemeral IPs are released during suspension, but static IPs remain attached to the VM instances. If you would like to retain your ephemeral IP, promote it.
VM configuration (such as machine type, metadata, labels, etc. All VM configurations, other than ephemeral IP addresses, are preserved and restored when the instance resumes.

Configuring a Debian VM to support suspend and resume

VMs running Debian 8 and 9 can suspend and resume, but they must be configured beforehand. To configure your Debian instance, complete one of the following sets of instructions, option A or option B. We recommend configuring the ACPID if possible (option A).

Option A

This option configures the ACPID to handle the sleep button event and adds a shell script for handling the sleep event.

  1. Connect to your VM instance using ssh:

    gcloud compute ssh VM_NAME
    
  2. On the VM instance, create a directory under the acpi folder:

    sudo mkdir -p /etc/acpi/events/
    
  3. Configure ACPID to handle the sleep button event:

    cat <<EOF | sudo tee /etc/acpi/events/sleepbtn-acpi-support
    event=button[ /]sleep
    action=/etc/acpi/sleepbtn-acpi-support.sh
    EOF
    
  4. Create the sleep event handling script:

    cat <<EOF | sudo tee /etc/acpi/sleepbtn-acpi-support.sh
    #!/bin/sh
    echo mem > /sys/power/state
    EOF
    
  5. Set up the permissions for the script:

    sudo chmod 755 /etc/acpi/sleepbtn-acpi-support.sh
    
  6. Restart ACPID:

    sudo systemctl restart acpid.service
    

Option B

  1. Connect to your VM instance using ssh:

    gcloud compute ssh VM_NAME
    
  2. On the VM instance, install dbus:

    sudo apt-get install dbus
    
  3. Restart logind:

    sudo systemctl restart systemd-logind.service
    

What's next