This page describes how to stop and start a virtual machine (VM) instance. Note that Compute Engine uses
STOP
and TERMINATE
interchangeably. To
suspend and resume a VM, read
Suspending and resuming a VM.
For more information about stopping and suspending a VM, see
VM instance life cycle.
In most cases, you can stop a VM temporarily if you no longer need it and start it again later. For exceptions, see Restrictions. A stopped VM retains its persistent disks, its internal IPs, and its MAC addresses. However, the VM shuts down the guest OS and loses its application state. If you need to retain the guest OS and application state, suspend the VM instead. Essentially, a stopped VM resets to its power-on state and no data is saved. Stop a VM if you want to change the machine type, add or remove attached disks, change the minimum CPU platform, add or remove GPUs, or apply machine type recommendations.
Stopping a VM causes Compute Engine to send the
ACPI shutdown
signal to the VM. Modern guest operating systems (OS) are configured to perform
a clean shutdown before powering off in response to the power off signal.
Compute Engine waits a short time for the guest OS to finish shutting
down and then transitions the VM to the TERMINATED
state.
Before you begin
- If you want to use the command-line examples in this guide, do the following:
- Install or update to the latest version of the Google Cloud CLI.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
Restrictions
Normally, shutting down a VM instance that uses Local SSD will discard all data on the Local SSD drives. See the Local SSD documentation for more details.
Billing
VMs in the TERMINATED
state are not charged for per-second
usage and do not count toward your regional CPU quota. However, any resources
attached to the VM, such as persistent disks
and external IP addresses,
are charged until they are deleted. To stop being charged for attached
resources, you can reconfigure a stopped VM to detach those resources,
and then delete the resources.
You can choose to stop VMs that you're not using, saving you from being charged for VMs that aren't active. When you are ready, you can start the VMs again, with the same VM properties, metadata, and resources.
Stop a VM
To stop a VM, use the Google Cloud console, the gcloud CLI, or the Compute Engine API.
Console
In the Google Cloud console, go to the VM instances page.
Select one or more VMs that you want to stop.
Click Stop.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
To stop a VM, use the
gcloud compute instances stop
command and specify one or more VMs that you want to stop:gcloud compute instances stop VM_NAME
For VMs with Local SSD use the
--discard-local-ssd
flag.gcloud compute instances stop VM_NAME --discard-local-ssd
Replace
VM_NAME
with the name of the VM you want to stop.
API
To stop a VM, construct a POST
request using the instances.stop
method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/stop
Replace the following:
PROJECT_ID
: the project your VM is inZONE
: the zone where your VM is locatedVM_NAME
: the name of the VM you want to stop
Go
Java
Node.js
PHP
Python
A TERMINATED
VM still exists with its configuration settings and
instance metadata, but it loses its in-memory data and virtual machine state. Any
resources that are attached to the terminated VM remain
attached until you manually detach those resources or delete the VM.
When a VM is in the TERMINATED
state, you can
start the VM
or delete it. If you don't plan to
start the VM, delete it.
Stop a VM through the OS
You can optionally stop a VM from within the guest OS by using the
sudo shutdown -h now
or sudo poweroff
command. Use these commands to stop a
VM that uses local SSDs. Run one of these commands while you are logged into the
VM:
sudo shutdown -h now
sudo poweroff
Start a stopped VM that doesn't have an encrypted disk
To start a stopped VM, use the
instances().start
method.
This method boots up a stopped VM that is in the TERMINATED
state.
The start
method starts a VM in a TERMINATED
state, whereas methods such
as reset()
and sudo reboot
work only with VMs that are currently running.
Almost all VMs, including preemptible VMs,
can be started, if the VM is in a TERMINATED
state.
Console
In the Google Cloud console, go to the VM instances page.
Select one or more VMs that you want to start.
Click Start/Resume.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
To start a VM, use the
gcloud compute instances start
command and specify one or more VMs that you want to start:gcloud compute instances start VM_NAME
Replace
VM_NAME
with the name of the VM you want to start.
API
To start a VM, construct a POST
request using the instances.start
method:
POST https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/start
Replace the following:
PROJECT_ID
: the project your VM is inZONE
: the zone where your VM is locatedVM_NAME
: the name of the VM you want to start
Go
Java
Node.js
PHP
Python
Start a VM that has encrypted disks
If the VM you want to start uses customer-supplied encryption keys, you must provide those keys when trying to start the VM.
Console
In the Google Cloud console, go to the VM instances page.
Select the VM that you want to start.
Click Start/Resume. A window opens where you can specify encryption keys for the devices that are attached to this VM.
Specify encryption keys for each of the encrypted disks that are attached to this VM.
Click Start to start the VM.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
To start a VM that uses encryption keys, use the
gcloud compute instances start
command with the flag. If you are using an RSA-wrapped key, use the--csek-key-file
gcloud beta
command.gcloud compute instances start VM_NAME \ --csek-key-file ENCRYPTION_KEY_FILE
Replace the following:
VM_NAME
: the name of the VM you want to startENCRYPTION_KEY_FILE
: the relative path to the JSON file that contains the encryption key. This key is used to encrypt persistent disks that are attached to the VM. For more information, see the Encryption key file format.
API
To start a VM that has encryption keys, construct a POST
request using the
instances.startWithEncryptionKey
method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/startWithEncryptionKey { "disks": [ { "source": "DISK_URL", "diskEncryptionKey": { "ENCRYPTION_TYPE": "ENCRYPTION_KEY" } } ] }
Replace the following:
PROJECT_ID
: the project your VM is inZONE
: the zone where your VM is locatedVM_NAME
: the name of the VM you want to startDISK_URL
: the resource URL corresponding to the full resource name of the attached disk that is encrypted with a customer-supplied encryption keyENCRYPTION_TYPE
: the type of disk encryption that you are using:rawKey
,kmsKeyName
, orrsaEncryptedKey
. When usingrsaEncryptedKey
, you must use the beta API instead of the v1 API.ENCRYPTION_KEY
: the encryption key that you use to encrypt persistent disks that are attached to the VM. Keys of typerawKey
orrsaEncryptedKey
must be base64-encoded. Prepare a key of typersaEncryptedKey
by following the instructions in RSA key wrapping.
Go
Java
Node.js
PHP
Python
Reset a VM
Performing a reset on your VM is similar to doing a hard reset
on your computer, where you might press a reset button or press and hold
the power button. Resetting a VM forcibly wipes the memory contents of
the machine and resets the VM to its initial state. The VM
does not perform a clean shutdown of the guest OS. Throughout this process,
the VM remains in the RUNNING
state.
To reset a running VM, use the Google Cloud console, the gcloud CLI, or the Compute Engine API.
Console
In the Google Cloud console, go to the VM instances page.
Select one or more VMs that you want to reset.
Click Reset.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
To reset a running VM, use the
gcloud compute instances reset
command and specify one or more VMs that you want to reset:gcloud compute instances reset VM_NAME
Replace
VM_NAME
with the name of the VM you want to reset.
API
To reset a VM, construct a POST
request using the instances.reset
method:
POST https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/reset
Replace the following:
PROJECT_ID
: the project your VM is inZONE
: the zone where your VM is locatedVM_NAME
: the name of the VM you want to reset