This document describes how to suspend or resume a virtual machine (VM) instance.
If you want to keep your VM instance around but don't 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:
- Suspended instances preserve the guest OS memory, device state, and application state.
- Google charges for the storage necessary to save instance memory.
- You can only suspend an instance for up to 60 days. After 60 days, the instance
is automatically moved to the
TERMINATED
state.
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 REST 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
-
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.
-
Limitations
The following limitations apply for this feature:
- You cannot suspend an instance that uses a GPU.
- You cannot suspend a bare metal instance.
- 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 208 GB of memory.
- You can suspend preemptible instances, but the preemptible instance might be terminated before it is successfully suspended.
- You cannot suspend a Confidential VM.
- You cannot suspend a VM that has CSEK-protected disks attached.
Local SSDs
Normally, suspending a VM instance that uses Local SSD will discard all data on the Local SSD drives - the same behavior as stopping the instance.
See the Local SSD documentation for more details.
Preemptible VMs
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 the pricing for 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 Google Cloud console , the gcloud CLI, the API, or the Cloud Client Libraries.
You cannot suspend an instance by using the standard processes that are built into the guest environment. You can use the Google 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
In the Google Cloud console, go to the VM instances page.
Select one or more instances to suspend.
Click Suspend.
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 provide the --discard-local-ssd
flag:
gcloud compute instances suspend VM_NAME --discard-local-ssd
Using --discard-local-ssd
or --discard-local-ssd=True
will discard the contents of the Local SSD. Compute Engine --discard-local-ssd=False
is currently in Public Preview. Using this flag will save the contents of up to 32 Local SSD disks during Suspend. See the Local SSD documentation for more details.
Go
Java
Node.js
PHP
Python
REST
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 IDZONE
: the zone of the VMVM_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 more than 32
local SSD disks, you
must discard the local SSD data by providing the discardLocalSsd
query
parameter as follows:
https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/suspend?discardLocalSsd=true
For more information, see the Local SSD documentation.
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 Google Cloud console , the gcloud CLI, the API, or the Cloud Client Libraries.
Console
In the Google Cloud console, go to the VM instances page.
Select one or more instances to resume.
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
Go
Java
Node.js
PHP
Python
REST
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 requestZONE
: the zone of the VMVM_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 208 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.
Connect to your VM instance using ssh:
gcloud compute ssh VM_NAME
On the VM instance, create a directory under the
acpi
folder:sudo mkdir -p /etc/acpi/events/
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
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
Restart ACPID:
sudo systemctl restart acpid.service
Option B
Connect to your VM instance using ssh:
gcloud compute ssh VM_NAME
On the VM instance, install
dbus
:sudo apt-get install dbus
Restart
logind
:sudo systemctl restart systemd-logind.service
What's next
- Delete an instance if you no longer need it.
- Stop or restart an instance.
- Review the Instance lifecycle.
- Review Troubleshooting VM suspension if you run into issues suspending a VM.