Stop or restart a Compute Engine instance (original) (raw)

Skip to main content

Stop or restart a Compute Engine instance

Linux Windows

You can manually stop a Compute Engine instance when you longer use it, or to modify its properties—for example, to change its machine type, or remove any attached and mounted disks. After the instance stops, you can either restart it to resume your workload, or delete the instance if you no longer need it.

This document explains how to manually stop or restart an instance. To automate stopping or restarting an instance, see the following:

Limitations

When you stop a compute instance, the following limitations apply:

Before you begin

Console

When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

gcloud

  1. Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
    gcloud init
    If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  2. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.
    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
    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.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.

Required roles

To get the permissions that you need to stop or restart a compute instance, ask your administrator to grant you theCompute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to stop or restart a compute instance. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to stop or restart a compute instance:

You might also be able to get these permissions with custom roles or other predefined roles.

When you stop a compute instance, or Compute Engine does so for a scheduled action, the instance retains its attached disks, configuration settings, IP addresses, MAC addresses, and instance metadata. If you also want to retain in-memory data and application state, thensuspend the instance.

Depending on whether the instance has Local SSD disks attached and how you want to handle any shutdown scripts, stop your instance by using one of the following methods:

Stop an instance without Local SSD disks

Depending on what you want to do when stopping an instance, use the following options:

To stop one or more instances, select one of the following options:

Console

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Select the running instances to stop.
  3. Click Stop. If there is no Stop option, then clickMore actions > Stop.
  4. In the dialog that appears, do the following:
    1. Optional: To stop the instances without gracefully shutting them down, or end an ongoing graceful shutdown, select theSkip graceful shutdown (if applicable) checkbox.
    2. To confirm, click Stop.

gcloud

To stop one or more instances in the same zone, use thegcloud compute instances stop command:

gcloud compute instances stop INSTANCE_NAMES \
    --zone=ZONE

Replace the following:

Optionally, if you've enabled graceful shutdown in one or more instances, then you can stop the instances without gracefully shutting them down, or manually end an ongoing graceful shutdown. To do so, use thegcloud beta compute instances stop commandwith the --no-graceful-shutdown flag:

gcloud beta compute instances stop INSTANCE_NAMES \
    --no-graceful-shutdown \
    --zone=ZONE

Go

Java

Node.js

PHP

Python

REST

To stop an instance, make a POST request to theinstances.stop method:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/stop

Replace the following:

Optionally, if you've enabled graceful shutdown in an instance, you can stop the instance without gracefully shutting it down, or manually end an ongoing graceful shutdown. To do so, make a POST request to theinstances.stop method. In the request URL, include the noGracefulShutdown=true query parameter:

POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/stop?noGracefulShutdown=true

Stop an instance with Local SSD disks

Depending on what you want to do when stopping a compute instance, use the following options:

To stop one or more instances that have Local SSD disks attached, select one of the following options:

Console

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Select the running instances to stop.
  3. Click Stop. If there is no Stop option, clickMore actions > Stop.
  4. In the dialog, do the following:
    1. Optional: To stop the instances without gracefully shut them down, or end an ongoing graceful shutdown, select theSkip graceful shutdown (if applicable) checkbox.
    2. To confirm, click Stop.

gcloud

When stopping one or more instances in the same zone that have Local SSD disks attached, specify whether to discard or preserve Local SSD data as follows:

gcloud compute instances stop INSTANCE_NAMES \  
    --discard-local-ssd=true \  
    --zone=ZONE  
gcloud beta compute instances stop INSTANCE_NAMES \  
    --discard-local-ssd=false \  
    --zone=ZONE  

Replace the following:

Optionally, if you've enabled graceful shutdown in one or more instances, you can stop the instances without gracefully shutting them down, or end an ongoing graceful shutdown. To do so, use thegcloud beta compute instances stop commandwith the --no-graceful-shutdown flag:

gcloud beta compute instances stop INSTANCE_NAMES \
    --discard-local-ssd=DISCARD_LOCAL_SSD \
    --no-graceful-shutdown \
    --zone=ZONE

Replace DISCARD_LOCAL_SSD with true to discard the data in the Local SSD disks, or false to preserve the data.

REST

When stopping an instance that has Local SSD disks attached, specify whether to discard or preserve Local SSD data as follows:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/stop?discardLocalSsd=true  
POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/stop?discardLocalSsd=false  

Replace the following:

Optionally, if you've enabled graceful shutdown in an instance, then you can stop the instance without gracefully shutting it down, or manually end an ongoing graceful shutdown. To do so, make a POST request to theinstances.stop method. In the request URL, include the noGracefulShutdown=true query parameter:

POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/stop?discardLocalSsd=DISCARD_LOCAL_SSD&noGracefulShutdown=true

Replace DISCARD_LOCAL_SSD with true to discard the data in the Local SSD disks, or false to preserve the data.

Stop an instance from the guest OS

If a compute instance has Local SSD disks attached, then shutting down the guest OS automatically discards the Local SSD data. To preserve this data, manually copy the data to a persistent storage option before stopping the instance.

To stop an instance from the guest OS, select one of the following options:

Linux

  1. If you haven't already, thenconnect to the instance.
  2. To stop the instance, select one of the following methods:
    • For a clean shutdown that allows the instance to run shutdown scripts before shutting down the guest OS, run the following command:
    sudo shutdown -h now  
    • Otherwise, to force a shutdown, run the following command:
    sudo poweroff  

Windows

  1. If you haven't already, then connect to the instance using one of the following methods:
  2. To stop the instance, select one of the following methods:
    • To cleanly stop the instance and let the instance to run shutdown scripts before shutting down the guest OS, run the following command:
    shutdown /s  
    • To force a shutdown, run the following command:
    shutdown /f  

Restart an instance

You can restart a compute instance that has been fully stopped, which is when the instance state is TERMINATED.

If you chose to preserve the data of your Local SSD disks when stopping the instance, then you might need to remount the Local SSD disks after restarting it. For more information about how to mount Local SSD disks, seeFormat and mounting a Local SSD device.

To restart an instance, use one of the following methods based on whether the instance has disks that were encrypted withcustomer-supplied encryption keys (CSEK):

Restart an instance that doesn't have CSEK-encrypted disks

To restart multiple instances simultaneously across different zones, use the Google Cloud console. For instances located within the same zone, you can use the gcloud CLI. Otherwise, for other restart scenarios, select one of the following options:

Console

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Select one or more instances.
  3. Click Start / Resume.

gcloud

To restart one or more instances in the same zone, use thegcloud compute instances start command:

gcloud compute instances start INSTANCE_NAMES \
    --zone=ZONE

Replace the following:

Go

Java

Node.js

PHP

Python

REST

To restart an instance, make a POST request to theinstances.start method:

 POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/start

Replace the following:

Restart an instance with CSEK-encrypted disks

When you restart a stopped compute instance that has attached disks that were encrypted usingcustomer-supplied encryption keys, you must supply the encryption key information.

To restart multiple instances simultaneously across different zones, use the Google Cloud console. For instances located within the same zone, you can use the gcloud CLI. Otherwise, for other restart scenarios, select one of the following options:

Console

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Select the instances to restart.
  3. Click Start / Resume.
  4. Specify encryption keys for each of the encrypted disks that are attached to the instances, and then click Start.

gcloud

To restart one or more instances that use encrypted disks in the same zone, use thegcloud compute instances start commandwith the --csek-key-file flag. If you're using an RSA-wrapped key, then use thegcloud beta compute instances start commandwith the --csek-key-file flag instead:

gcloud compute instances start INSTANCE_NAMES \
    --csek-key-file=ENCRYPTION_KEY_FILE \
    --zone=ZONE

Replace the following:

Go

Java

Node.js

PHP

Python

REST

To restart an instance that uses encrypted disks, make a POST request to theinstances.startWithEncryptionKey method:

POST  https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/startWithEncryptionKey

{
  "disks": [
    {
      "source": "DISK_URL",
      "diskEncryptionKey": {
        "ENCRYPTION_TYPE": "ENCRYPTION_KEY"
      }
    }
  ]
}

Replace the following:

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-06-18 UTC.