Reboot or reset a Compute Engine instance Stay organized with collections Save and categorize content based on your preferences.
This document explains how to reboot or reset a Compute Engine instance. Tolearn more about the effects of resetting an instance, as well as thedifferences between suspending, stopping, or resetting an instance, seeSuspend, stop, or reset Compute Engine instances.
Rebooting or resetting an instance can help ensure optimal performance andstability, or help resolve issues like a frozen, slow, or crashing guestoperating system (OS). Based on the state of the guest OS of your instance, doone of the following:
Reboot the instance. If your guest OS is slow or frozen, then rebootinggives it enough time to finish running tasks before shutting down.
Reset the instance. Reset an instance only if the guest OS has crashedor is unresponsive, and you have no other options. Resetting an instancedoesn't allow the guest OS to cleanly shut down. This action can discardunsaved data and might corrupt the file systems of any disks.
Before you begin
- If you haven't already, set upauthentication. Authentication verifies your identity 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. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- 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.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
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.
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.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
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.
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.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
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.
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.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
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.
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.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
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.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.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, seeManage 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 theRequired 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 withcustom roles or otherpredefined roles.
Reboot an instance
Rebooting a compute instance allows the guest OS in the instance to finishrunning tasks before Compute Engine sends the ACPI shutdown signal. Thishelps to ensure a clean shutdown of the guest OS.
Rebooting an instance erases the memory used by the instance. If you're usingRAM 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
If you haven't already, thenconnect 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 thefollowing methods:
To reboot the instance, run the following command:
shutdown /r /t 0Optional: To monitor the process of shutting down and restarting theinstance,enable the Windows Boot Manager menu.
Reset an instance
Resetting an instance erases all data in the memory of the instance, includingany temporary files stored on RAM disks. This data is permanently lost andCompute Engine doesn't create backups before resetting the instance.
Warning: Only reset an instance as a last resort when the guest OS has crashedand is unresponsive. This action forces an abrupt shutdown of the guest OS,which can cause data loss and file system corruption. To restart an instancecleanly,reboot it instead.You can reset multiple instances simultaneously or individual instances. Formultiple instances, use the Google Cloud console or, for instances located in thesame zone, the Google Cloud CLI. For individual instances, select any of thefollowing options:
Console
In the Google Cloud console, go to theVM instances page.
Select the instances to reset.
ClickReset, and then clickReset to confirm.
gcloud
To reset one or more running instances in a single zone, use thegcloud compute instances reset command:
gcloud compute instances resetINSTANCE_NAMES \ --zone=ZONEReplace the following:
INSTANCE_NAMES: a whitespace-separated list of namesof instances—for example,instance-01 instance-02 instance-03.ZONE: the zone where the instances are located.
Go
import("context""fmt""io"compute"cloud.google.com/go/compute/apiv1"computepb"cloud.google.com/go/compute/apiv1/computepb")// resetInstance resets a running Google Compute Engine instance (with unencrypted disks).funcresetInstance(wio.Writer,projectID,zone,instanceNamestring)error{// projectID := "your_project_id"// zone := "europe-central2-b"// instanceName := "your_instance_name"ctx:=context.Background()instancesClient,err:=compute.NewInstancesRESTClient(ctx)iferr!=nil{returnfmt.Errorf("NewInstancesRESTClient: %w",err)}deferinstancesClient.Close()req:=&computepb.ResetInstanceRequest{Project:projectID,Zone:zone,Instance:instanceName,}op,err:=instancesClient.Reset(ctx,req)iferr!=nil{returnfmt.Errorf("unable to reset instance: %w",err)}iferr=op.Wait(ctx);err!=nil{returnfmt.Errorf("unable to wait for the operation: %w",err)}fmt.Fprintf(w,"Instance reset\n")returnnil}Java
importcom.google.api.gax.longrunning.OperationFuture;importcom.google.cloud.compute.v1.InstancesClient;importcom.google.cloud.compute.v1.Operation;importcom.google.cloud.compute.v1.Operation.Status;importcom.google.cloud.compute.v1.ResetInstanceRequest;importjava.io.IOException;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.TimeUnit;importjava.util.concurrent.TimeoutException;publicclassResetInstance{publicstaticvoidmain(String[]args)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// TODO(developer): Replace these variables before running the sample./* project: project ID or project number of the Cloud project your instance belongs to. zone: name of the zone your instance belongs to. instanceName: name of the instance your want to reset. */Stringproject="your-project-id";Stringzone="zone-name";StringinstanceName="instance-name";resetInstance(project,zone,instanceName);}// Resets a running Google Compute Engine instance (with unencrypted disks).publicstaticvoidresetInstance(Stringproject,Stringzone,StringinstanceName)throwsIOException,ExecutionException,InterruptedException,TimeoutException{/* Initialize client that will be used to send requests. This client only needs to be created once, and can be reused for multiple requests. After completing all of your requests, call the `instancesClient.close()` method on the client to safely clean up any remaining background resources. */try(InstancesClientinstancesClient=InstancesClient.create()){ResetInstanceRequestresetInstanceRequest=ResetInstanceRequest.newBuilder().setProject(project).setZone(zone).setInstance(instanceName).build();OperationFuture<Operation,Operation>operation=instancesClient.resetAsync(resetInstanceRequest);Operationresponse=operation.get(3,TimeUnit.MINUTES);if(response.getStatus()==Status.DONE){System.out.println("Instance reset successfully ! ");}}}}Node.js
/** * TODO(developer): Uncomment and replace these variables before running the sample. */// const projectId = 'YOUR_PROJECT_ID';// const zone = 'europe-central2-b'// const instanceName = 'YOUR_INSTANCE_NAME'constcompute=require('@google-cloud/compute');asyncfunctionresetInstance(){constinstancesClient=newcompute.InstancesClient();const[response]=awaitinstancesClient.reset({project:projectId,zone,instance:instanceName,});letoperation=response.latestResponse;constoperationsClient=newcompute.ZoneOperationsClient();// Wait for the operation to complete.while(operation.status!=='DONE'){[operation]=awaitoperationsClient.wait({operation:operation.name,project:projectId,zone:operation.zone.split('/').pop(),});}console.log('Instance reset.');}resetInstance();PHP
use Google\Cloud\Compute\V1\Client\InstancesClient;use Google\Cloud\Compute\V1\ResetInstanceRequest;/** * Reset a running Google Compute Engine instance (with unencrypted disks). * * @param string $projectId Project ID or project number of the Cloud project your instance belongs to. * @param string $zone Name of the zone your instance belongs to. * @param string $instanceName Name of the instance you want to reset. * * @throws \Google\ApiCore\ApiException if the remote call fails. * @throws \Google\ApiCore\ValidationException if local error occurs before remote call. */function reset_instance( string $projectId, string $zone, string $instanceName) { // Stop the Compute Engine instance using InstancesClient. $instancesClient = new InstancesClient(); $request = (new ResetInstanceRequest()) ->setInstance($instanceName) ->setProject($projectId) ->setZone($zone); $operation = $instancesClient->reset($request); // Wait for the operation to complete. $operation->pollUntilComplete(); if ($operation->operationSucceeded()) { printf('Instance %s reset successfully' . PHP_EOL, $instanceName); } else { $error = $operation->getError(); printf('Failed to reset instance: %s' . PHP_EOL, $error?->getMessage()); }}Python
from__future__importannotationsimportsysfromtypingimportAnyfromgoogle.api_core.extended_operationimportExtendedOperationfromgoogle.cloudimportcompute_v1defwait_for_extended_operation(operation:ExtendedOperation,verbose_name:str="operation",timeout:int=300)->Any:""" Waits for the extended (long-running) operation to complete. If the operation is successful, it will return its result. If the operation ends with an error, an exception will be raised. If there were any warnings during the execution of the operation they will be printed to sys.stderr. Args: operation: a long-running operation you want to wait on. verbose_name: (optional) a more verbose name of the operation, used only during error and warning reporting. timeout: how long (in seconds) to wait for operation to finish. If None, wait indefinitely. Returns: Whatever the operation.result() returns. Raises: This method will raise the exception received from `operation.exception()` or RuntimeError if there is no exception set, but there is an `error_code` set for the `operation`. In case of an operation taking longer than `timeout` seconds to complete, a `concurrent.futures.TimeoutError` will be raised. """result=operation.result(timeout=timeout)ifoperation.error_code:print(f"Error during{verbose_name}: [Code:{operation.error_code}]:{operation.error_message}",file=sys.stderr,flush=True,)print(f"Operation ID:{operation.name}",file=sys.stderr,flush=True)raiseoperation.exception()orRuntimeError(operation.error_message)ifoperation.warnings:print(f"Warnings during{verbose_name}:\n",file=sys.stderr,flush=True)forwarninginoperation.warnings:print(f" -{warning.code}:{warning.message}",file=sys.stderr,flush=True)returnresultdefreset_instance(project_id:str,zone:str,instance_name:str)->None:""" Resets a stopped Google Compute Engine instance (with unencrypted disks). Args: project_id: project ID or project number of the Cloud project your instance belongs to. zone: name of the zone your instance belongs to. instance_name: name of the instance your want to reset. """instance_client=compute_v1.InstancesClient()operation=instance_client.reset(project=project_id,zone=zone,instance=instance_name)wait_for_extended_operation(operation,"instance reset")REST
To reset a running instance, make aPOST request to theinstances.reset method:
POST https://compute.googleapis.com//compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/resetReplace the following:
INSTANCE_NAME: the name of the instance.PROJECT_ID: the ID of the project where the instanceis located.ZONE: the zone where the instance is located.
What's next
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.