Reboot or reset a Compute Engine instance (original) (raw)

Linux Windows


This document explains how to reboot or reset a Compute Engine instance. To learn more about the effects of resetting an instance, as well as the differences between suspending, stopping, or resetting an instance, seeSuspend, stop, or reset Compute Engine instances.

Rebooting or resetting an instance can help ensure optimal performance and stability, or help resolve issues like a frozen, slow, or crashing guest operating system (OS). Based on the state of the guest OS of your instance, do one of the following:

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. After installing the Google Cloud CLI,initialize it 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. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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. To initialize the gcloud CLI, run the following command:
    gcloud init
  4. 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.
After installing the Google Cloud CLI,initialize it 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.
For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.

Required roles

To get the permissions that you need to reset or reboot a compute instance, ask your administrator to grant you theCompute 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 reset or reboot a compute instance. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to reset or reboot a compute instance:

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

Rebooting a compute instance allows the guest OS in the instance to finish running tasks before Compute Engine sends the ACPI shutdown signal. This helps to ensure a clean shutdown of the guest OS.

Rebooting an instance erases the memory used by the instance. If you're using RAM disks with your instances, and you need to preserve that data, thenback up the databefore rebooting the instance.

To reboot an instance, select one of the following options:

Linux

  1. If you haven't already, thenconnect to the instance.
  2. To reboot the instance, run the following command:
sudo reboot  

Windows

  1. If you haven't already, then connect to the instance using one of the following methods:
  2. To reboot the instance, run the following command:
shutdown /r /t 0  
  1. Optional: To monitor the process of shutting down and restarting the instance,enable the Windows Boot Manager menu.

Reset an instance

Resetting an instance erases all data in the memory of the instance, including any temporary files stored on RAM disks. This data is permanently lost and Compute Engine doesn't create backups before resetting the instance.

You can reset multiple 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

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Select the instances to reset.
  3. Click Reset, and then click Reset to confirm.

gcloud

To reset one or more running instances in a single zone, use thegcloud compute instances reset command:

gcloud compute instances reset INSTANCE_NAMES \
    --zone=ZONE

Replace the following:

Go

Java

Node.js

PHP

Python

REST

To reset a running instance, make a POST request to theinstances.reset method:

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

Replace the following:

What's next