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