This document explains how to suspend or resume Compute Engine instances. To learn more about suspending, stopping, or resetting instances, see Suspend, stop, or reset Compute Engine instances.
If you want to keep your Compute Engine instance around, but you don't want to incur charges for it when the instance isn't in use, then you can suspend the instance. Suspending an instance preserves the instance and migrates the contents of the instance's memory to storage. After resuming the instance, Compute Engine migrates the instance's memory from storage back to the instance, and the instance starts running again.
Suspending a Compute Engine instance is useful for the following:
Development and test environments that are not being fully used during off periods, such as during evenings or weekends, and that you want to maintain for costs saving or faster initialization than creating new 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.
Before you begin
-
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
Go
To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Java
To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Node.js
To use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
PHP
To use the PHP samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Python
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Required roles
To get the permissions that you need to suspend or resume a compute instance,
ask your administrator to grant you the
Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1
) IAM role on the instance.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to suspend or resume a compute instance. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to suspend or resume a compute instance:
-
To suspend an instance:
compute.instances.suspend
-
To resume an instance:
compute.instances.resume
You might also be able to get these permissions with custom roles or other predefined roles.
Limitations
When suspending a compute instance, the following limitations apply:
You can only suspend an instance if the guest OS supports it. For more information, see Operating system details.
You can only suspend an instance that uses Debian 8 or 9 as guest OS if you configure the OS before suspending the VM.
You can only suspend an instance for up to 60 days before Compute Engine automatically transitions its state to
TERMINATED
.You can suspend Spot VMs or preemptible instances—however, if Compute Engine preempts the instance before the suspend operation completes, Compute Engine ends the suspend operation and preempts the instances.
You can't suspend instances with GPUs attached.
You can't suspend bare metal instances.
You can't suspend Confidential VMs.
You can't suspend instances by using the standard processes that are built into their guest environment. Commands such as
systemctl suspend
in Ubuntu 16.04 or later, aren't supported. If called, then Compute Engine ignores the in-guest signal.You can't suspend instances with more than 208 GB of memory.
You can't suspend instances that have CSEK-protected disks attached.
Enable suspend operations in Debian 8 or 9
If a compute instance is running Debian 8 and 9 as its guest OS, then, before suspending the instance, you must enable suspend and resume operations by doing one of the following:
Recommended: Configure the ACPID
Configure the ACPID
To enable the suspend and resume operation in Debian 8 or 9, you can configure the Advanced Configuration and Power Interface events Daemon (ACPID) to handle the sleep button event. After enabling the deep sleep button event, you can add a shell script for handling the sleep event as described in this section.
To configure the ACPID to support suspend and resume operations, do the following:
If you haven't already, then connect to your Linux instance.
Create the
events
folder in theacpi
folder:sudo mkdir -p /etc/acpi/events/
Configure the 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
Create the sleep event handling script:
cat <<EOF | sudo tee /etc/acpi/sleepbtn-acpi-support.sh #!/bin/sh echo mem > /sys/power/state EOF
Set up the permissions for the script:
sudo chmod 755 /etc/acpi/sleepbtn-acpi-support.sh
To make the changes effective, restart the ACPID:
sudo systemctl restart acpid.service
Install D-Bus
To enable the suspend and resume operation in Debian 8 or 9, you can install D-Bus.
To install D-Bus in your compute instance's guest OS when the OS is using Debian 8 or 9, do the following:
If you haven't already, then connect to your Linux instance.
Install D-Bus:
sudo apt-get install dbus
To make the changes effective, restart
logind
:sudo systemctl restart systemd-logind.service
Suspend an instance
If the guest OS of your compute instance is using Debian 8 or 9, then, before suspending the instance, you must configure the guest OS to support suspend and resume operations as described in this document.
To suspend an instance, use of the following methods based on whether the instance has Local SSD disks attached:
If your instance doesn't have any Local SSD disks attached, then see Suspend an instance without Local SSD disks.
If your instance has any Local SSD disks attached, and you want to either discard or preserve (Preview) the disks' Local SSD data, then see Suspend an instance with Local SSD disks.
Suspend an instance without Local SSD disks
You can suspend multiple compute instances simultaneously or individual instances. For multiple instances, use the Google Cloud console or, for instances located in the same zone, the Google Cloud CLI. For individual instances, select any of the following options:
Console
In the Google Cloud console, go to the VM instances page.
Select one or more instances to suspend.
Click
Suspend, and then click Suspend to confirm.
gcloud
To suspend one or more instances in a single zone, use the
gcloud compute instances suspend
command:
gcloud compute instances suspend INSTANCE_NAMES \
--zone=ZONE
Replace the following:
INSTANCE_NAMES
: a whitespace-separated list of names of instances—for example,instance-01 instance-02 instance-03
.ZONE
: the zone where the instances are located.
Go
Java
Node.js
PHP
Python
REST
To suspend an instance, make a POST
request to the
instances.suspend
method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/suspend
Replace the following:
PROJECT_ID
: the ID of the project where the instance is located.ZONE
: the zone where the instance is located.INSTANCE_NAME
: the name of the instance.
Suspend an instance with Local SSD disks
Based on how many compute instances you want to suspend simultaneously and whether you need to preserve the data of their attached Local SSD disks, do the following:
To preserve the data of the Local SSD disks attached to an instance, suspend the instance using the gcloud CLI or REST API.
To suspend multiple instances simultaneously, use the Google Cloud console or, for instances located in the same zone, the gcloud CLI.
To suspend one or more instances that have Local SSD disks attached, select one of the following options:
Console
In the Google Cloud console, go to the VM instances page.
Select one or more instances to suspend.
Click
Suspend, and then click Suspend to confirm.
gcloud
When suspending one or more instances in a single zone that have Local SSD disks attached, specify whether to discard or preserve Local SSD data as follows:
To discard Local SSD data, use the
gcloud compute instances suspend
command with the--discard-local-ssd=true
flag:gcloud compute instances suspend INSTANCE_NAMES \ --discard-local-ssd=true \ --zone=ZONE
To preserve Local SSD data, use the
gcloud beta compute instances suspend
command with the--discard-local-ssd=false
flag:gcloud beta compute instances suspend INSTANCE_NAMES \ --discard-local-ssd=false \ --zone=ZONE
Replace the following:
INSTANCE_NAMES
: a whitespace-separated list of names of instances—for example,instance-01 instance-02 instance-03
.ZONE
: the zone where the instances are located.
REST
When suspending an instance that has Local SSD disks attached, specify whether to discard or preserve Local SSD data as follows:
To discard Local SSD data, make a
POST
request to theinstances.suspend
method. In the request URL, include thediscardLocalSsd
query parameter set totrue
:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/suspend?discardLocalSsd=true
To preserve Local SSD data, make a
POST
request to thebeta.instances.suspend
method. In the request URL, include thediscardLocalSsd
query parameter set tofalse
:POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/suspend?discardLocalSsd=false
Replace the following:
PROJECT_ID
: the ID of the project where the instance is located.ZONE
: the zone where the instance is located.INSTANCE_NAME
: the name of the instance.
Resume a suspended instance
Before resuming a suspended compute instance, consider the following:
You can resume an instance only if there is sufficient capacity in the zone where the instance is located. This isn't usually a problem. If you have troubles resuming an instance, then try again later.
If you attached Local SSD disks to the instance and chose to preserve Local SSD data when suspending it, then you might need to remount the Local SSD disks after resuming it. For more information, see how to remount non-boot disks on Linux instances or Windows instances.
You can resume multiple instances simultaneously or individual instances. For multiple instances, use the Google Cloud console or, for instances located in the same zone, the gcloud CLI. For individual instances, select any of the following options:
Console
In the Google Cloud console, go to the VM instances page.
Select one or more suspended instances to resume.
Click
Start / Resume, and then click Start.
gcloud
To resume one or more suspended instances in a single zone, use the
gcloud compute instances resume
command:
gcloud compute instances resume INSTANCE_NAMES \
--zone=ZONE
Replace the following:
INSTANCE_NAMES
: a whitespace-separated list of names of instances—for example,instance-01 instance-02 instance-03
.ZONE
: the zone where the suspended instances are located.
Go
Java
Node.js
PHP
Python
REST
To resume a suspended instance, make a POST
request to the
instances.resume
method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/resume
Replace the following:
INSTANCE_NAME
: the name of the suspend instance to resume.PROJECT_ID
: the ID of the project where the suspended instance is located.ZONE
: the zone where the suspended instance is located.