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, see Suspend, 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:
Reboot the instance. If your guest OS is slow or frozen, then rebooting gives it enough time to finish running tasks before shutting down.
Reset the instance. Reset an instance only if the guest OS has crashed or is unresponsive, and you have no other options. Resetting an instance doesn't allow the guest OS to cleanly shut down. This action can discard unsaved data and might corrupt the file systems of any disks.
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.
-
Required roles
To get the permissions that you need to reset or reboot a compute instance,
ask your administrator to grant you the
Compute 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:
-
To reset an instance:
compute.instances.reset
-
To reboot an instance from within its guest OS:
compute.instances.setMetadata
You might also be able to get these permissions with custom roles or other predefined roles.
Reboot an instance
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, then back up the data before rebooting the instance.
To reboot an instance, select one of the following options:
Linux
If you haven't already, then connect to the instance.
To reboot the instance, run the following command:
sudo reboot
Windows
If you haven't already, then connect to the instance using one of the following methods:
To reboot the instance, run the following command:
shutdown /r /t 0
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
In the Google Cloud console, go to the VM instances page.
Select the instances to reset.
Click Reset, and then click Reset to confirm.
gcloud
To reset one or more running instances in a single zone, use the
gcloud compute instances reset
command:
gcloud compute instances reset INSTANCE_NAMES \
--zone=ZONE
Replace the following:
INSTANCE_NAMES
: a whitespace-separated list of names of instances—for example,instance-01 instance-02 instance-03
.ZONE
: the zone where the instances are located.
Go
Java
Node.js
PHP
Python
REST
To reset a running instance, make a POST
request to the
instances.reset
method:
POST https://compute.googleapis.com//compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/reset
Replace the following:
INSTANCE_NAME
: the name of the instance.PROJECT_ID
: the ID of the project where the instance is located.ZONE
: the zone where the instance is located.