Install the guest environment Stay organized with collections Save and categorize content based on your preferences.
This page explains how to manually install the guest environmenton virtual machine (VM) instances. The guest environment is a collection ofscripts, daemons, and binaries thatinstances require to run on Compute Engine. For more information, seeGuest environment.
In most cases, if you use Google-provided public OS images,the guest environment is automatically included. For a fulllist of OS images that automatically include the guest environment,seeOperating system details.
If the guest environment is not installed or is outdated,install or update it. To identifythese scenarios, seeWhen to install or update the guest environment.
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.
When to install or update the guest environment
In most cases, you don't need to manually install or update the guestenvironment. Review the following sections to see when you might need to manuallyinstall or update.
Check installation requirements
Before you install the guest environment, use theValidate the guest environment procedure to checkif the guest environment runs on your instance. If the guest environmentis available on your instance but is outdated,update the guest environment.
You might need to install the guest environment in the followingsituations:
Your required Google-provided OS image does not have the guest environmentinstalled.
Youimport a customimage or a virtual disk to Compute Engine and chooseto prevent automatic installation of the guest environment.
When you import virtual disks or custom images, you can letCompute Engine install the guest environment for you.However, if you choose not to install the guest environment during theimport process, then you must manually install the guest environment.
Youmigrate VMs to Compute Engine using Migrate to Virtual Machines.
To install the guest environment, seeInstallation methods.
Check update requirements
You might need to update the guest environment in the following situations:
You have instances that use OS images earlier than
v20141218.You use an OS image that does not have theguest environment optimizations for Local SSD disks.
To update the guest environment, seeUpdate the guest environment.
Installation methods
You can install the guest environment in multiple ways. Choose one ofthe following options:
Import tool. The import tool is the recommended option. However, theimport tool installs the guest environment and also performs otherconfiguration updates on the image, such as configuring networks,configuring the bootloader, and installing Google Cloud CLI.For instructions, seeMake an image bootable.
The import tool supports a wide variety of operating systems and versions. Formore information, seeoperating system details page.
Manual installation. Choose one of the following:
- Connect to your instance using SSH or RDP andinstall the guest environment in-place
- Clone your boot disk andinstall the guest environment using a startup script
Supported operating systems
You can install or update the guest environment on VMs that use OSimage versions in the general availability (GA) lifecycle orextended support lifecycle stage.
To review a list of OS image versions and their lifecycle stage on Compute Engine,seeOperating system details.
Limitations
You can't manually install or use the import tool to install guest environmentsfor Fedora CoreOS and Container-optimized (COS) operating systems.For COS, Google recommends usingtheGoogle-provided public images,which include the guest environment as a core component.
Install the guest environment
To manually install the guest environment, select one of the following methods,depending on your ability to connect to the instance:
- If you can connect to the instance by using SSH or RDP,install the guest environment in-place.
- If you can't connect to the instance,install the guest environment by cloning its boot disk and using a startup script.
Install the guest environment in-place
Use this method to install the guest environment if you can connect to thetarget instance using SSH. If you can't connect to the instance to installthe guest environment, you can insteadinstall the guest environment by cloning its boot disk and using a startup script.
This procedure is useful for imported images if youcan connect using SSH password-based authentication. You can also use it toreinstall the guest environment if you have at least one user account with afunctional key-based SSH.
CentOS/RHEL/Rocky
Complete the steps for your CentOS/RHEL/Rocky version.
Version 10 and later
- Verify that your operating system versionis supported.
Determine your CentOS/RHEL/Rocky version. Then, create the sourcerepository file,
/etc/yum.repos.d/google-cloud.repo:eval $(grep VERSION_ID /etc/os-release)sudo tee /etc/yum.repos.d/google-cloud.repo<< EOM[google-compute-engine]name=Google Compute Enginebaseurl=https://packages.cloud.google.com/yum/repos/google-compute-engine-el${VERSION_ID%%.*}-x86_64-stableenabled=1gpgcheck=1repo_gpgcheck=0gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key-v${VERSION_ID%%.*}.gpgEOMUpdate package lists:
sudo yum makecachesudo yum updateinfo
Install the guest environment packages:
sudo yum install -y google-compute-engine google-osconfig-agent
Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.
Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.
Version 9 or earlier
- Verify that your operating system versionis supported.
Determine your CentOS/RHEL/Rocky version. Then, create the sourcerepository file,
/etc/yum.repos.d/google-cloud.repo:eval $(grep VERSION_ID /etc/os-release)sudo tee /etc/yum.repos.d/google-cloud.repo<< EOM[google-compute-engine]name=Google Compute Enginebaseurl=https://packages.cloud.google.com/yum/repos/google-compute-engine-el${VERSION_ID%%.*}-x86_64-stableenabled=1gpgcheck=1repo_gpgcheck=0gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpgEOMUpdate package lists:
sudo yum makecachesudo yum updateinfo
Install the guest environment packages:
sudo yum install -y google-compute-engine google-osconfig-agent
Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.
Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.
Debian
Complete the steps for your Debian version.
Debian 13 and later
- Verify that your operating system versionis supported.
Install the public repository GPG key to
/etc/apt/keyrings:sudo curl https://packages.cloud.google.com/apt/doc/apt-key.gpg -o /etc/apt/keyrings/google-keyring.gpgDetermine the Debian distro name. Then, create the source list file,
/etc/apt/sources.list.d/google-cloud.list:eval$(grepVERSION_CODENAME/etc/os-release)sudotee/etc/apt/sources.list.d/google-cloud.list <<EOMdeb[signed-by=/etc/apt/keyrings/google-keyring.gpg]http://packages.cloud.google.com/aptgoogle-compute-engine-${VERSION_CODENAME}-stablemainEOMUpdate package lists:
sudoaptupdateInstall the guest environment packages:
sudoaptinstall-ygce-configs-trixiesudoaptinstall-ygoogle-compute-enginegoogle-osconfig-agentRestart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.
Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.
Debian 12 and earlier
- Verify that your operating system versionis supported.
Install the public repository GPG key:
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -Determine the Debian distro name. Then, create the sourcelist file,
/etc/apt/sources.list.d/google-cloud.list:eval$(grepVERSION_CODENAME/etc/os-release)sudotee/etc/apt/sources.list.d/google-cloud.list <<EOMdebhttp://packages.cloud.google.com/aptgoogle-compute-engine-${VERSION_CODENAME}-stablemaindebhttp://packages.cloud.google.com/aptgoogle-cloud-packages-archive-keyring-${VERSION_CODENAME}mainEOMUpdate package lists:
sudoaptupdateInstall the guest environment packages:
sudoaptinstall-ygoogle-cloud-packages-archive-keyringsudoaptinstall-ygoogle-compute-enginegoogle-osconfig-agentRestart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.
Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.
Ubuntu
Verify that your operating system versionis supported.
Enable the Universe repository. Canonical publishes packages for itsguest environment to theUniverse repository.
sudo apt-add-repository universe
Update package lists:
sudo apt update
Install the guest environment packages:
sudo apt install -y google-compute-engine google-osconfig-agent
Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.
Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.
SLES
Verify that your operating system versionis supported.
Activate thePublic Cloud Module
product=$(sudo SUSEConnect --list-extensions | grep -o "sle-module-public-cloud.*")[[ -n "$product" ]] && sudo SUSEConnect -p "$product"
Update package lists:
sudo zypper refresh
Install the guest environment packages:
sudo zypper install -y google-guest-{agent,configs,oslogin} \google-osconfig-agentsudo systemctl enable /usr/lib/systemd/system/google-*Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.
Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.
Windows
Before you begin, verify that your operating system versionis supported.
To install theWindows guest environment, run the following commands in an elevated PowerShell version 3.0 or higher prompt. TheInvoke-WebRequest command requires PowerShell version 3.0 or higher.
Download and install
GooGet.[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;Invoke-WebRequest https://github.com/google/googet/releases/download/v2.18.3/googet.exe -OutFile $env:temp\googet.exe;& "$env:temp\googet.exe" -root C:\ProgramData\GooGet -noconfirm install -sources `https://packages.cloud.google.com/yuck/repos/google-compute-engine-stable googet;Remove-Item "$env:temp\googet.exe"
During installation,
GooGetadds content to the system environment. After installation completes, launch a new PowerShell console. Alternatively, provide the full path to thegooget.exefile (C:\ProgramData\GooGet\googet.exe).Open a new console and add the
google-compute-engine-stablerepository.googet addrepo google-compute-engine-stable https://packages.cloud.google.com/yuck/repos/google-compute-engine-stable
Install the core Windows guest environment packages.
googet -noconfirm install google-compute-engine-windows `google-compute-engine-sysprep google-compute-engine-metadata-scripts `google-compute-engine-vss google-osconfig-agent
Install the optional Windows guest environment package.
googet -noconfirm install google-compute-engine-auto-updater
Using the
googetcommand.To view available packages, run the
googet availablecommand.To view installed packages, run the
googet installedcommand.To update to the latest package version, run the
googet updatecommand.To view additional commands, run
googet help.
Clone boot disk and use startup script
Important: In this procedure, the termstartup script refers to using anrc.local script. This term doesn't refer to a startup script that isspecified in the instance metadata. Instance metadata startup scripts dependon the guest environment, so you can't use them to install the guest environment.If you can't connect to an instance to manually install the guest environment,install the guest environment using this procedure, which includes thefollowing steps that you can complete in the Google Cloud console orCloud Shell.
This method applies only to Linux distributions. For Windows,use one of the other twoinstallation methods.
Use theCloud Shell to run thisprocedure. To run this procedure if you are not using Cloud Shell, install thejq command-line JSON processor.This processor filters gcloud CLI output.Cloud Shell hasjq pre-installed.
CentOS/RHEL/Rocky
Complete the steps for your CentOS/RHEL/Rocky version.
Version 10 and later
Verify that your operating system versionis supported.
Create a new instance toserve as the rescue instance. Name this instancerescue.This rescue instance does not need to run the same Linux OS asthe problematic instance. This example uses Debian 9 on the rescueinstance.
Stop the problematic instance and create a copy of its boot disk.
Set a variable name for the problematic instance. This variablesimplifies referencing the instance in later steps.
export PROB_INSTANCE_NAME=VM_NAME
ReplaceVM_NAME with the name of the problematic instance.
Stop the problematic instance.
gcloud compute instances stop "$PROB_INSTANCE_NAME"
Get the name of the boot disk for the problem instance.
export PROB_INSTANCE_DISK="$(gcloud compute instances describe \"$PROB_INSTANCE_NAME" --format='json' | jq -r \'.disks[] | select(.boot == true) | .source')"
Create a snapshot of the boot disk.
export DISK_SNAPSHOT="${PROB_INSTANCE_NAME}-snapshot"gcloud compute disks snapshot "$PROB_INSTANCE_DISK" \ --snapshot-names "$DISK_SNAPSHOT"Create a new disk from the snapshot.
export NEW_DISK="${PROB_INSTANCE_NAME}-new-disk"gcloud compute disks create "$NEW_DISK" \ --source-snapshot="$DISK_SNAPSHOT"Delete the snapshot.
gcloud compute snapshots delete "$DISK_SNAPSHOT"
Attach the new disk to the rescue instance and mount the root volumefor the rescue instance.Since this procedure attaches only one additional disk, the deviceidentifier of the new disk is
/dev/sdb. CentOS/RHEL/Rocky Linux usesthe first volume on a disk as the root volume by default; therefore, the volumeidentifier should be/dev/sdb1. For custom configurations, uselsblktodetermine the volume identifier.gcloud compute instances attach-disk rescue --disk "$NEW_DISK"
Connect to the rescue instance using SSH.
gcloud compute ssh rescue
Run the following steps on the rescue instance.
Mount the root volume of the new disk.
export NEW_DISK_MOUNT_POINT="/tmp/sdb-root-vol"DEV="/dev/sdb1"sudo mkdir "$NEW_DISK_MOUNT_POINT"sudo mount -o nouuid "$DEV" "$NEW_DISK_MOUNT_POINT"
Create the
rc.localscript.cat<<'EOF' >/tmp/rc.local#!/bin/bashecho "== Installing Google guest environment for CentOS/RHEL/Rocky Linux =="sleep 30 # Wait for network.echo "Determining CentOS/RHEL/Rocky Linux version..."eval $(grep VERSION_ID /etc/os-release)if [[ -z $VERSION_ID ]]; then echo "ERROR: Could not determine version of CentOS/RHEL/Rocky Linux." exit 1fiecho "Updating repo file..."tee "/etc/yum.repos.d/google-cloud.repo"<< EOM[google-compute-engine]name=Google Compute Enginebaseurl=https://packages.cloud.google.com/yum/repos/google-compute-engine-el${VERSION_ID%%.*}-x86_64-stableenabled=1gpgcheck=1repo_gpgcheck=0gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key-v${VERSION_ID%%.*}.gpgEOMecho "Running yum makecache..."yum makecacheecho "Running yum updateinfo..."yum updateinfoecho "Running yum install google-compute-engine..."yum install -y google-compute-enginerpm -q google-compute-engineif [[ $? -ne 0 ]]; then echo "ERROR: Failed to install ${pkg}."fiecho "Removing this rc.local script."rm /etc/rc.d/rc.local# Move back any previous rc.local:if [[ -f "/etc/moved-rc.local" ]]; then echo "Restoring a previous rc.local script." mv "/etc/moved-rc.local" "/etc/rc.d/rc.local"fiecho "Restarting the instance..."rebootEOFBack up the existing
rc.localfile, move the temporaryrc.localscript into place on the mounted disk, then set its permission to beexecutable on boot. The temporary scriptreplaces the original script when it finishes booting. To do this,run the following command:if [ -f "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local" ]; then sudo mv "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local" \ "$NEW_DISK_MOUNT_POINT/etc/moved-rc.local"fisudo mv /tmp/rc.local "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local"sudo chmod 0755 "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local"sudo chown root:root "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local"
Un-mount the root volume of the new disk.
sudo umount "$NEW_DISK_MOUNT_POINT" && sudo rmdir \"$NEW_DISK_MOUNT_POINT"
Exit the SSH session to the rescue instance.
Detach the new disk from the rescue instance.
gcloud compute instances detach-disk rescue --disk "$NEW_DISK"
Create an instance toserve as the replacement. When you create the replacement instance,specify the new disk as the boot disk. You can create the replacementinstance using the Google Cloud console:
In the Google Cloud console, go to theVM instances page.
Click the problematic instance, then clickCreate similar.
Specify a name for the replacement instance. In theBoot disksection, clickChange, then clickExisting Disks. Selectthe new disk.
ClickCreate. The replacement instance automaticallystarts after it is created.
As the replacement instance boots up, the temporary
rc.localscriptruns and installs the guest environment.To watch the progress of this script, inspect the console logs for linesemitted by the temporaryrc.localscript. To view logs, run thefollowing command:gcloud compute instances get-serial-port-outputREPLACEMENT_VM_NAME
ReplaceREPLACEMENT_VM_NAME with the name you assignedthe replacement instance.
The replacement instance automatically reboots whenthe temporary
rc.localscript finishes. During the secondreboot, you caninspect the console log to makesure the guest environment loads.Verify that you canconnect to the instance using SSH.
After you verify that the replacement instance is functional, youcanstop ordelete the problematic instance.
Version 9 or earlier
Verify that your operating system versionis supported.
Create a new instance toserve as the rescue instance. Name this instancerescue.This rescue instance does not need to run the same Linux OS asthe problematic instance. This example uses Debian 9 on the rescueinstance.
Stop the problematic instance and create a copy of its boot disk.
Set a variable name for the problematic instance. This variablesimplifies referencing the instance in later steps.
export PROB_INSTANCE_NAME=VM_NAME
ReplaceVM_NAME with the name of the problematic instance.
Stop the problematic instance.
gcloud compute instances stop "$PROB_INSTANCE_NAME"
Get the name of the boot disk for the problem instance.
export PROB_INSTANCE_DISK="$(gcloud compute instances describe \"$PROB_INSTANCE_NAME" --format='json' | jq -r \'.disks[] | select(.boot == true) | .source')"
Create a snapshot of the boot disk.
export DISK_SNAPSHOT="${PROB_INSTANCE_NAME}-snapshot"gcloud compute disks snapshot "$PROB_INSTANCE_DISK" \ --snapshot-names "$DISK_SNAPSHOT"Create a new disk from the snapshot.
export NEW_DISK="${PROB_INSTANCE_NAME}-new-disk"gcloud compute disks create "$NEW_DISK" \ --source-snapshot="$DISK_SNAPSHOT"Delete the snapshot:
gcloud compute snapshots delete "$DISK_SNAPSHOT"
Attach the new disk to the rescue instance and mount the root volumefor the rescue instance.Since this procedure attaches only one additional disk, the deviceidentifier of the new disk is
/dev/sdb. CentOS/RHEL/Rocky Linux usesthe first volume on a disk as the root volume by default; therefore, the volumeidentifier should be/dev/sdb1. For custom configurations, uselsblktodetermine the volume identifier.gcloud compute instances attach-disk rescue --disk "$NEW_DISK"
Connect to the rescue instance using SSH.
gcloud compute ssh rescue
Run the following steps on the rescue instance.
Mount the root volume of the new disk.
export NEW_DISK_MOUNT_POINT="/tmp/sdb-root-vol"DEV="/dev/sdb1"sudo mkdir "$NEW_DISK_MOUNT_POINT"sudo mount -o nouuid "$DEV" "$NEW_DISK_MOUNT_POINT"
Create the
rc.localscript.cat<<'EOF' >/tmp/rc.local#!/bin/bashecho "== Installing Google guest environment for CentOS/RHEL/Rocky Linux =="sleep 30 # Wait for network.echo "Determining CentOS/RHEL/Rocky Linux version..."eval $(grep VERSION_ID /etc/os-release)if [[ -z $VERSION_ID ]]; then echo "ERROR: Could not determine version of CentOS/RHEL/Rocky Linux." exit 1fiecho "Updating repo file..."tee "/etc/yum.repos.d/google-cloud.repo"<< EOM[google-compute-engine]name=Google Compute Enginebaseurl=https://packages.cloud.google.com/yum/repos/google-compute-engine-el${VERSION_ID%%.*}-x86_64-stableenabled=1gpgcheck=1repo_gpgcheck=0gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpghttps://packages.cloud.google.com/yum/doc/rpm-package-key.gpgEOMecho "Running yum makecache..."yum makecacheecho "Running yum updateinfo..."yum updateinfoecho "Running yum install google-compute-engine..."yum install -y google-compute-enginerpm -q google-compute-engineif [[ $? -ne 0 ]]; then echo "ERROR: Failed to install ${pkg}."fiecho "Removing this rc.local script."rm /etc/rc.d/rc.local# Move back any previous rc.local:if [[ -f "/etc/moved-rc.local" ]]; then echo "Restoring a previous rc.local script." mv "/etc/moved-rc.local" "/etc/rc.d/rc.local"fiecho "Restarting the instance..."rebootEOFBack up the existing
rc.localfile, move the temporaryrc.localscript into place on the mounted disk, then set its permission to beexecutable on boot. The temporary scriptreplaces the original script when it finishes booting. To do this,run the following command:if [ -f "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local" ]; then sudo mv "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local" \ "$NEW_DISK_MOUNT_POINT/etc/moved-rc.local"fisudo mv /tmp/rc.local "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local"sudo chmod 0755 "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local"sudo chown root:root "$NEW_DISK_MOUNT_POINT/etc/rc.d/rc.local"
Un-mount the root volume of the new disk.
sudo umount "$NEW_DISK_MOUNT_POINT" && sudo rmdir \"$NEW_DISK_MOUNT_POINT"
Exit the SSH session to the rescue instance.
Detach the new disk from the rescue instance.
gcloud compute instances detach-disk rescue --disk "$NEW_DISK"
Create an instance toserve as the replacement. When you create the replacement instance,specify the new disk as the boot disk. You can create the replacementinstance using the Google Cloud console:
In the Google Cloud console, go to theVM instances page.
Click the problematic instance, then clickCreate similar.
Specify a name for the replacement instance. In theBoot disksection, clickChange, then clickExisting Disks. Selectthe new disk.
ClickCreate. The replacement instance automaticallystarts after it is created.
As the replacement instance boots up, the temporary
rc.localscriptruns and installs the guest environment.To watch the progress of this script, inspect the console logs for linesemitted by the temporaryrc.localscript. To view logs, run thefollowing command:gcloud compute instances get-serial-port-outputREPLACEMENT_VM_NAME
ReplaceREPLACEMENT_VM_NAME with the name you assignedthe replacement instance.
The replacement instance automatically reboots whenthe temporary
rc.localscript finishes. During the secondreboot, you caninspect the console log to makesure the guest environment loads.Verify that you canconnect to the instance using SSH.
After you verify that the replacement instance is functional, youcanstop ordelete the problematic instance.
Debian
Verify that your operating system versionis supported
Create a new instance toserve as the rescue instance. Name this instancerescue.This rescue instance does not need to run the same Linux OS asthe problematic instance. This example uses Debian 9 on the rescue instance.
Stop the problematic instance and create a copy of its boot disk.
Set a variable name for the problematic instance. This variablesimplifies referencing the instance in later steps.
export PROB_INSTANCE_NAME=VM_NAME
ReplaceVM_NAME with the name of the problematicinstance.
Stop the problematic instance.
gcloud compute instances stop "$PROB_INSTANCE_NAME"
Get the name of the boot disk for the problem instance.
export PROB_INSTANCE_DISK="$(gcloud compute instances describe \"$PROB_INSTANCE_NAME" --format='json' | jq -r \'.disks[] | select(.boot == true) | .source')"
Create a snapshot of the boot disk.
export DISK_SNAPSHOT="${PROB_INSTANCE_NAME}-snapshot"gcloud compute disks snapshot "$PROB_INSTANCE_DISK" \ --snapshot-names "$DISK_SNAPSHOT"Create a new disk from the snapshot.
export NEW_DISK="${PROB_INSTANCE_NAME}-new-disk"gcloud compute disks create "$NEW_DISK" \ --source-snapshot="$DISK_SNAPSHOT"Delete the snapshot:
gcloud compute snapshots delete "$DISK_SNAPSHOT"
Attach the new disk to the rescue instance and mount the root volumefor the rescue instance.Since this procedure attaches only one additional disk, the deviceidentifier of the new disk is
/dev/sdb. Debian uses thefirst volume on a disk as the root volume by default; therefore, the volumeidentifier should be/dev/sdb1. For custom configurations, uselsblktodetermine the volume identifier.gcloud compute instances attach-disk rescue --disk "$NEW_DISK"
Connect to the rescue instance using SSH.
gcloud compute ssh rescue
Run the following steps on the rescue instance.
Mount the root volume of the new disk.
export NEW_DISK_MOUNT_POINT="/tmp/sdb-root-vol"DEV="/dev/sdb1"sudo mkdir "$NEW_DISK_MOUNT_POINT"sudo mount "$DEV" "$NEW_DISK_MOUNT_POINT"
Create the
rc.localscript.cat<<'EOF' >/tmp/rc.local#!/bin/bashecho "== Installing Google guest environment for Debian =="export DEBIAN_FRONTEND=noninteractivesleep 30 # Wait for network.echo "Determining Debian version..."eval $(grep VERSION_CODENAME /etc/os-release)if [[ -z $VERSION_CODENAME ]]; then echo "ERROR: Could not determine Debian version." exit 1fiecho "Adding GPG key for Google cloud repo."curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -echo "Updating repo file..."tee "/etc/apt/sources.list.d/google-cloud.list"<< EOMdeb http://packages.cloud.google.com/apt google-compute-engine-${VERSION_CODENAME}-stable maindeb http://packages.cloud.google.com/apt google-cloud-packages-archive-keyring-${VERSION_CODENAME} mainEOMecho "Running apt update..."apt updateecho "Installing packages..."for pkg in google-cloud-packages-archive-keyring google-compute-engine; do echo "Running apt install ${pkg}..." apt install -y ${pkg} if [[ $? -ne 0 ]]; then echo "ERROR: Failed to install ${pkg}." fidoneecho "Removing this rc.local script."rm /etc/rc.local# Move back any previous rc.local:if [[ -f "/etc/moved-rc.local" ]]; then echo "Restoring a previous rc.local script." mv "/etc/moved-rc.local" "/etc/rc.local"fiecho "Restarting the instance..."rebootEOFBack up the existing
rc.localfile, move the temporaryrc.localscript into place on the mounted disk, then set its permission to beexecutable on boot. The temporary scriptreplaces the original script when it finishes booting. To do this,run the following command:if [[ -f "$NEW_DISK_MOUNT_POINT/etc/rc.local" ]]; then sudo mv "$NEW_DISK_MOUNT_POINT/etc/rc.local" \ "$NEW_DISK_MOUNT_POINT/etc/moved-rc.local"fisudo mv /tmp/rc.local "$NEW_DISK_MOUNT_POINT/etc/rc.local"sudo chmod 0755 "$NEW_DISK_MOUNT_POINT/etc/rc.local"sudo chown root:root "$NEW_DISK_MOUNT_POINT/etc/rc.local"
Un-mount the root volume of the new disk.
sudo umount "$NEW_DISK_MOUNT_POINT" && sudo rmdir "$NEW_DISK_MOUNT_POINT"
Exit the SSH session to the rescue instance.
Detach the new disk from the rescue instance.
gcloud compute instances detach-disk rescue --disk "$NEW_DISK"
Create a new instance toserve as the replacement. When you create the replacement instance,specify the new disk as the boot disk. You can create the replacementinstance using the Google Cloud console:
In the Google Cloud console, go to theVM instances page.
Click the problematic instance, then clickCreate similar.
Specify a name for the replacement instance. In theBoot disksection, clickChange, then clickExisting Disks. Selectthe new disk.
ClickCreate. The replacement instance automaticallystarts after it is created.
As the replacement instance boots up, the temporary
rc.localscriptruns and installs the guest environment.To watch the progress of this script, inspect the console logs for linesemitted by the temporaryrc.localscript. To view logs, run thefollowing command:gcloud compute instances get-serial-port-outputREPLACEMENT_VM_NAME
ReplaceREPLACEMENT_VM_NAME with the name you assigned thereplacement instance.
The replacement instance automatically reboots whenthe temporary
rc.localscript finishes. During the secondreboot, you caninspect the console log to makesure the guest environment loads.Verify that you canconnect to the instance using SSH.
After you verify that the replacement instance is functional, youcanstop ordelete the problematic instance.
Ubuntu
Verify that your operating system versionis supported
Create a new instance toserve as the rescue instance. Name this instancerescue.This rescue instance does not need to run the same Linux OS asthe problematic instance. This example uses Debian 9 on the rescue instance.
Stop the problematic instance and create a copy of its boot disk.
Set a variable name for the problematic instance. This variable simplifiesreferencing the instance in later steps.
export PROB_INSTANCE_NAME=VM_NAME
ReplaceVM_NAME with the name of the problematicinstance.
Stop the problematic instance.
gcloud compute instances stop "$PROB_INSTANCE_NAME"
Get the name of the boot disk for the problem instance.
export PROB_INSTANCE_DISK="$(gcloud compute instances describe \"$PROB_INSTANCE_NAME" --format='json' | jq -r \'.disks[] | select(.boot == true) | .source')"
Create a snapshot of the boot disk.
export DISK_SNAPSHOT="${PROB_INSTANCE_NAME}-snapshot"gcloud compute disks snapshot "$PROB_INSTANCE_DISK" \ --snapshot-names "$DISK_SNAPSHOT"Create a new disk from the snapshot.
export NEW_DISK="${PROB_INSTANCE_NAME}-new-disk"gcloud compute disks create "$NEW_DISK" \ --source-snapshot="$DISK_SNAPSHOT"Delete the snapshot:
gcloud compute snapshots delete "$DISK_SNAPSHOT"
Attach the new disk to the rescue instance and mount the root volumefor the rescue instance.Since this procedure attaches only one additional disk, the deviceidentifier of the new disk is
/dev/sdb. Ubuntu labels its root volume1 by default; therefore, the volume identifier should be*/dev/sdb*. Forcustom configurations, uselsblkto determine the volume identifier.gcloud compute instances attach-disk rescue --disk "$NEW_DISK"
Connect to the rescue instance using SSH.
gcloud compute ssh rescue
Run the following steps on the rescue instance.
Mount the root volume of the new disk.
export NEW_DISK_MOUNT_POINT="/tmp/sdb-root-vol"DEV="/dev/sdb1"sudo mkdir "$NEW_DISK_MOUNT_POINT"sudo mount "$DEV" "$NEW_DISK_MOUNT_POINT"
Create the
rc.localscript.cat<<'EOF' >/tmp/rc.local#!/bin/bashecho "== Installing a Linux guest environment for Ubuntu =="sleep 30 # Wait for network.echo "Running apt update..."apt updateecho "Installing packages..."echo "Running apt install google-compute-engine..."apt install -y google-compute-engineif [[ $? -ne 0 ]]; then echo "ERROR: Failed to install ${pkg}."fiecho "Removing this rc.local script."rm /etc/rc.local# Move back any previous rc.local:if [[ -f "/etc/moved-rc.local" ]]; then echo "Restoring a previous rc.local script." mv "/etc/moved-rc.local" "/etc/rc.local"fiecho "Restarting the instance..."rebootEOFBack up the existing
rc.localfile, move the temporaryrc.localscript into place on the mounted disk, then set its permission to beexecutable on boot. The temporaryscript replaces the original script when it finishes booting. Todo this, run the following command:if [[ -f "$NEW_DISK_MOUNT_POINT/etc/rc.local" ]]; then sudo mv "$NEW_DISK_MOUNT_POINT/etc/rc.local" \ "$NEW_DISK_MOUNT_POINT/etc/moved-rc.local"fisudo mv /tmp/rc.local "$NEW_DISK_MOUNT_POINT/etc/rc.local"sudo chmod 0755 "$NEW_DISK_MOUNT_POINT/etc/rc.local"sudo chown root:root "$NEW_DISK_MOUNT_POINT/etc/rc.local"
Un-mount the root volume of the new disk.
sudo umount "$NEW_DISK_MOUNT_POINT" && sudo rmdir "$NEW_DISK_MOUNT_POINT"
Exit the SSH session to the rescue instance.
Detach the new disk from the rescue instance.
gcloud compute instances detach-disk rescue --disk "$NEW_DISK"
Create a new instance toserve as the replacement. When you create the replacement instance,specify the new disk as the boot disk. You can create the replacementinstance using the Google Cloud console:
In the Google Cloud console, go to theVM instances page.
Click the problematic instance, then clickCreate similar.
Specify a name for the replacement instance. In theBoot disksection, clickChange, then clickExisting Disks. Selectthe new disk.
ClickCreate. The replacement instance automaticallystarts after it is created.
As the replacement instance boots up, the temporary
rc.localscriptruns and installs the guest environment.To watch the progress of this script, inspect the console logs for linesemitted by the temporaryrc.localscript. To view logs, run thefollowing command:gcloud compute instances get-serial-port-outputREPLACEMENT_VM_NAME
ReplaceREPLACEMENT_VM_NAME with the name you assignedthe replacement instance.
The replacement instance automatically reboots whenthe temporary
rc.localscript finishes. During the secondreboot, you caninspect the console log to makesure the guest environment loads.Verify that you canconnect to the instance using SSH.
After you verify that the replacement instance is functional, youcanstop ordeletethe problematic instance.
Update the guest environment
If you receive a message that the guest environment is outdated, update thepackages for your operating system as follows:
CentOS/RHEL/Rocky
To update CentOS, RHEL and Rocky Linux operating systems, run the followingcommands:
sudo yum makecachesudo yum install google-compute-engine google-compute-engine-oslogin \google-guest-agent google-osconfig-agent
Debian
To update Debian operating systems, run the following commands:
sudo apt updatesudo apt install google-compute-engine google-compute-engine-oslogin \google-guest-agent google-osconfig-agent
Ubuntu
To update Ubuntu operating systems, run the following commands:
sudo apt updatesudo apt install google-compute-engine google-compute-engine-oslogin \google-guest-agent google-osconfig-agent
SLES
To update SLES operating systems, run the following commands:
sudo zypper refreshsudo zypper install google-guest-{agent,configs,oslogin} \google-osconfig-agentWindows
To update Windows operating systems, run the following command:
googet update
Validate the guest environment
You can check if a guest environment is installed by inspectingsystem logs that are emitted to the console while an instance boots up, or by listingthe installed packages while connected to the instance.
View expected console logs for the guest environment
This table summarizes expected output for console logs emitted by instances withworking guest environments as they start up.
| Operating system | Service management | Expected output |
|---|---|---|
| CentOS/RHEL/Rocky Linux Debian Ubuntu SLES Container-Optimized OS 89 and newer | systemd | google_guest_agent: GCE Agent Started (version YYYYMMDD.NN)google_metadata_script_runner: Starting startup scripts (version YYYYMMDD.NN)OSConfigAgent Info: OSConfig Agent (version YYYYMMDD.NN) |
| Container-Optimized OS 85 and older | systemd | Started Google Compute Engine Accounts DaemonStarted Google Compute Engine Network DaemonStarted Google Compute Engine Clock Skew DaemonStarted Google Compute Engine Instance SetupStarted Google Compute Engine Startup ScriptsStarted Google Compute Engine Shutdown Scripts |
| Windows | GCEGuestAgent: GCE Agent Started (version YYYYMMDD.NN)GCEMetadataScripts: Starting startup scripts (version YYYYMMDD.NN)OSConfigAgent Info: OSConfig Agent (version YYYYMMDD.NN) |
To view console logs for an instance, follow these steps.
Console
In the Google Cloud console, go to theVM instances page.
- Select the instance you need to examine.
- Restartorreset the instance.
- UnderLogs, clickSerial port 1 (console).
- Search for the expected output in the table that precedes thesesteps.
gcloud
- Restartorreset the instance.
Use the
gcloud compute instances get-serial-port-outputsub-command toconnect using the Google Cloud CLI. For example:gcloud compute instances get-serial-port-outputVM_NAME
ReplaceVM_NAME with the name of the instance you needto examine.
Search for the expected output in the table that precedes thesesteps.
View loaded services by operating system version
This table summarizes the services that should be loaded on instances withworking guest environments. You must run the command to list services afterconnecting to the instance. Therefore, you can perform this check only if you haveaccess to the instance.
| Operating system | Command to list services | Expected output |
|---|---|---|
| CentOS/RHEL/Rocky Linux Debian | sudo systemctl list-unit-files \| grep google | grep enabled | google-disk-expand.service enabledgoogle-guest-agent.service enabledgoogle-osconfig-agent.service enabledgoogle-shutdown-scripts.service enabledgoogle-startup-scripts.service enabledgoogle-oslogin-cache.timer enabled |
| Ubuntu | sudo systemctl list-unit-files \| grep google | grep enabled | google-guest-agent.service enabledgoogle-osconfig-agent.service enabledgoogle-shutdown-scripts.service enabledgoogle-startup-scripts.service enabledgoogle-oslogin-cache.timer enabled |
| Container-Optimized OS | sudo systemctl list-unit-files \| grep google | var-lib-google.mount disabledgoogle-guest-agent.service disabledgoogle-osconfig-agent.service disabledgoogle-osconfig-init.service disabledgoogle-oslogin-cache.service staticgoogle-shutdown-scripts.service disabledgoogle-startup-scripts.service disabledvar-lib-google-remount.service staticgoogle-oslogin-cache.timer disabled |
| SLES 12+ | sudo systemctl list-unit-files \| grep google | grep enabled | google-guest-agent.service enabledgoogle-osconfig-agent.service enabledgoogle-shutdown-scripts.service enabledgoogle-startup-scripts.service enabledgoogle-oslogin-cache.timer enabled |
| Windows | Get-Service GCEAgentGet-ScheduledTask GCEStartup | Running GCEAgent GCEAgent\ GCEStartup Ready |
View installed packages by operating system version
This table summarizes the packages that should be installed on instances withworking guest environments. You must run the command to list installed packagesafter connecting to the instance. Therefore, you can perform this check only if youhave access to the instance.
Note: CoreOS and Container-Optimized OS don't have package managers.Instead, inspectinstance console logs orloaded services to determine the guestenvironment's status.For more information about these packages, seeGuest environment components.
| Operating system | Command to list packages | Expected output |
|---|---|---|
| CentOS/RHEL/Rocky Linux | rpm -qa --queryformat '%{NAME}\n' \| grep -iE 'google|gce' | The list of packages can vary. It might also include components like google-osconfig-agentgoogle-compute-engine-oslogingoogle-guest-agentgce-disk-expandgoogle-compute-enginegoogle-cloud-cligoogle-cloud-ops-agent |
| Debian | apt list --installed \| grep -i google | gce-disk-expandgoogle-cloud-packages-archive-keyringgoogle-cloud-sdkgoogle-compute-engine-oslogingoogle-compute-enginegoogle-guest-agentgoogle-osconfig-agent |
| Ubuntu | apt list --installed \| grep -i google | google-compute-engine-oslogingoogle-compute-enginegoogle-guest-agentgoogle-osconfig-agent |
| SUSE (SLES) | rpm -qa --queryformat '%{NAME}\n' \| grep -i google | google-guest-configsgoogle-osconfig-agentgoogle-guest-oslogingoogle-guest-agent |
| Windows | googet installed | certgengoogetgoogle-compute-engine-auto-updatergoogle-compute-engine-driver-ggagoogle-compute-engine-driver-netkvmgoogle-compute-engine-driver-pvpanicgoogle-compute-engine-driver-vioscsigoogle-compute-engine-metadata-scriptsgoogle-compute-engine-powershellgoogle-compute-engine-sysprepgoogle-compute-engine-vssgoogle-compute-engine-windowsgoogle-osconfig-agent |
What's next
- Read thetroubleshooting tips.
- Learn more about applyingmetadata.
- Learn aboutSSH keys.
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.