Install the guest environment

Linux Windows

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

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:

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:

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:

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

  1. Verify that your operating system versionis supported.
  2. 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%%.*}.gpgEOM
  3. Update package lists:

    sudo yum makecachesudo yum updateinfo
  4. Install the guest environment packages:

    sudo yum install -y google-compute-engine google-osconfig-agent
  5. Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.

  6. Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.

Version 9 or earlier

  1. Verify that your operating system versionis supported.
  2. 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.gpgEOM
  3. Update package lists:

    sudo yum makecachesudo yum updateinfo
  4. Install the guest environment packages:

    sudo yum install -y google-compute-engine google-osconfig-agent
  5. Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.

  6. 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

  1. Verify that your operating system versionis supported.
  2. 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.gpg
  3. Determine 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}-stablemainEOM
  4. Update package lists:

    sudoaptupdate
  5. Install the guest environment packages:

    sudoaptinstall-ygce-configs-trixiesudoaptinstall-ygoogle-compute-enginegoogle-osconfig-agent
  6. Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.

  7. Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.

Debian 12 and earlier

  1. Verify that your operating system versionis supported.
  2. Install the public repository GPG key:

    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
  3. 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}mainEOM
  4. Update package lists:

    sudoaptupdate
  5. Install the guest environment packages:

    sudoaptinstall-ygoogle-cloud-packages-archive-keyringsudoaptinstall-ygoogle-compute-enginegoogle-osconfig-agent
  6. Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.

  7. Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.

Ubuntu

  1. Verify that your operating system versionis supported.

  2. Enable the Universe repository. Canonical publishes packages for itsguest environment to theUniverse repository.

    sudo apt-add-repository universe
  3. Update package lists:

    sudo apt update
  4. Install the guest environment packages:

    sudo apt install -y google-compute-engine google-osconfig-agent
  5. Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.

  6. Connect to the instance using SSH to verify. For detailed instructions,seeconnect to the instance using SSH.

SLES

  1. Verify that your operating system versionis supported.

  2. Activate thePublic Cloud Module

    product=$(sudo SUSEConnect --list-extensions | grep -o "sle-module-public-cloud.*")[[ -n "$product" ]] && sudo SUSEConnect -p "$product"
  3. Update package lists:

    sudo zypper refresh
  4. Install the guest environment packages:

    sudo zypper install -y google-guest-{agent,configs,oslogin} \google-osconfig-agentsudo systemctl enable /usr/lib/systemd/system/google-*
  5. Restart the instance.Then,inspect its console log to ensure the guestenvironment loads as it starts back up.

  6. 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.

  1. Download and installGooGet.

    [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,GooGet adds content to the system environment. After installation completes, launch a new PowerShell console. Alternatively, provide the full path to thegooget.exe file (C:\ProgramData\GooGet\googet.exe).

  2. Open a new console and add thegoogle-compute-engine-stable repository.

    googet addrepo google-compute-engine-stable https://packages.cloud.google.com/yuck/repos/google-compute-engine-stable
  3. 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
  4. Install the optional Windows guest environment package.

    googet -noconfirm install google-compute-engine-auto-updater

    Using thegooget command.

    To view available packages, run thegooget available command.

    To view installed packages, run thegooget installed command.

    To update to the latest package version, run thegooget update command.

    To view additional commands, rungooget 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

  1. Verify that your operating system versionis supported.

  2. 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.

  3. Stop the problematic instance and create a copy of its boot disk.

    1. 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.

    2. Stop the problematic instance.

      gcloud compute instances stop "$PROB_INSTANCE_NAME"
    3. 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')"
    4. 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"
    5. 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"
    6. Delete the snapshot.

      gcloud compute snapshots delete "$DISK_SNAPSHOT"
  4. 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, uselsblk todetermine the volume identifier.

    gcloud compute instances attach-disk rescue --disk "$NEW_DISK"
  5. Connect to the rescue instance using SSH.

    gcloud compute ssh rescue
  6. Run the following steps on the rescue instance.

    1. 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"
    2. Create therc.local script.

      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..."rebootEOF
    3. Back up the existingrc.local file, 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"
    4. Un-mount the root volume of the new disk.

      sudo umount "$NEW_DISK_MOUNT_POINT" && sudo rmdir \"$NEW_DISK_MOUNT_POINT"
    5. Exit the SSH session to the rescue instance.

  7. Detach the new disk from the rescue instance.

    gcloud compute instances detach-disk rescue --disk "$NEW_DISK"
  8. 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:

    1. In the Google Cloud console, go to theVM instances page.

      Go to VM instances

    2. Click the problematic instance, then clickCreate similar.

    3. Specify a name for the replacement instance. In theBoot disksection, clickChange, then clickExisting Disks. Selectthe new disk.

    4. ClickCreate. The replacement instance automaticallystarts after it is created.

    As the replacement instance boots up, the temporaryrc.local scriptruns and installs the guest environment.To watch the progress of this script, inspect the console logs for linesemitted by the temporaryrc.local script. 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 temporaryrc.local script finishes. During the secondreboot, you caninspect the console log to makesure the guest environment loads.

  9. 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

  1. Verify that your operating system versionis supported.

  2. 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.

  3. Stop the problematic instance and create a copy of its boot disk.

    1. 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.

    2. Stop the problematic instance.

      gcloud compute instances stop "$PROB_INSTANCE_NAME"
    3. 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')"
    4. 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"
    5. 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"
    6. Delete the snapshot:

      gcloud compute snapshots delete "$DISK_SNAPSHOT"
  4. 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, uselsblk todetermine the volume identifier.

    gcloud compute instances attach-disk rescue --disk "$NEW_DISK"
  5. Connect to the rescue instance using SSH.

    gcloud compute ssh rescue
  6. Run the following steps on the rescue instance.

    1. 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"
    2. Create therc.local script.

      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..."rebootEOF
    3. Back up the existingrc.local file, 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"
    4. Un-mount the root volume of the new disk.

      sudo umount "$NEW_DISK_MOUNT_POINT" && sudo rmdir \"$NEW_DISK_MOUNT_POINT"
    5. Exit the SSH session to the rescue instance.

  7. Detach the new disk from the rescue instance.

    gcloud compute instances detach-disk rescue --disk "$NEW_DISK"
  8. 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:

    1. In the Google Cloud console, go to theVM instances page.

      Go to VM instances

    2. Click the problematic instance, then clickCreate similar.

    3. Specify a name for the replacement instance. In theBoot disksection, clickChange, then clickExisting Disks. Selectthe new disk.

    4. ClickCreate. The replacement instance automaticallystarts after it is created.

    As the replacement instance boots up, the temporaryrc.local scriptruns and installs the guest environment.To watch the progress of this script, inspect the console logs for linesemitted by the temporaryrc.local script. 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 temporaryrc.local script finishes. During the secondreboot, you caninspect the console log to makesure the guest environment loads.

  9. Verify that you canconnect to the instance using SSH.

    After you verify that the replacement instance is functional, youcanstop ordelete the problematic instance.

Debian

  1. Verify that your operating system versionis supported

  2. 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.

  3. Stop the problematic instance and create a copy of its boot disk.

    1. 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.

    2. Stop the problematic instance.

      gcloud compute instances stop "$PROB_INSTANCE_NAME"
    3. 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')"
    4. 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"
    5. 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"
    6. Delete the snapshot:

      gcloud compute snapshots delete "$DISK_SNAPSHOT"
  4. 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, uselsblk todetermine the volume identifier.

    gcloud compute instances attach-disk rescue --disk "$NEW_DISK"
  5. Connect to the rescue instance using SSH.

    gcloud compute ssh rescue
  6. Run the following steps on the rescue instance.

    1. 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"
    2. Create therc.local script.

      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..."rebootEOF
    3. Back up the existingrc.local file, 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"
    4. Un-mount the root volume of the new disk.

      sudo umount "$NEW_DISK_MOUNT_POINT" && sudo rmdir "$NEW_DISK_MOUNT_POINT"
    5. Exit the SSH session to the rescue instance.

  7. Detach the new disk from the rescue instance.

    gcloud compute instances detach-disk rescue --disk "$NEW_DISK"
  8. 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:

    1. In the Google Cloud console, go to theVM instances page.

      Go to VM instances

    2. Click the problematic instance, then clickCreate similar.

    3. Specify a name for the replacement instance. In theBoot disksection, clickChange, then clickExisting Disks. Selectthe new disk.

    4. ClickCreate. The replacement instance automaticallystarts after it is created.

    As the replacement instance boots up, the temporaryrc.local scriptruns and installs the guest environment.To watch the progress of this script, inspect the console logs for linesemitted by the temporaryrc.local script. 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 temporaryrc.local script finishes. During the secondreboot, you caninspect the console log to makesure the guest environment loads.

  9. Verify that you canconnect to the instance using SSH.

    After you verify that the replacement instance is functional, youcanstop ordelete the problematic instance.

Ubuntu

  1. Verify that your operating system versionis supported

  2. 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.

  3. Stop the problematic instance and create a copy of its boot disk.

    1. 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.

    2. Stop the problematic instance.

      gcloud compute instances stop "$PROB_INSTANCE_NAME"
    3. 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')"
    4. 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"
    5. 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"
    6. Delete the snapshot:

      gcloud compute snapshots delete "$DISK_SNAPSHOT"
  4. 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, uselsblk to determine the volume identifier.

    gcloud compute instances attach-disk rescue --disk "$NEW_DISK"
  5. Connect to the rescue instance using SSH.

    gcloud compute ssh rescue
  6. Run the following steps on the rescue instance.

    1. 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"
    2. Create therc.local script.

      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..."rebootEOF
    3. Back up the existingrc.local file, 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"
    4. Un-mount the root volume of the new disk.

      sudo umount "$NEW_DISK_MOUNT_POINT" && sudo rmdir "$NEW_DISK_MOUNT_POINT"
    5. Exit the SSH session to the rescue instance.

  7. Detach the new disk from the rescue instance.

    gcloud compute instances detach-disk rescue --disk "$NEW_DISK"
  8. 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:

    1. In the Google Cloud console, go to theVM instances page.

      Go to VM instances

    2. Click the problematic instance, then clickCreate similar.

    3. Specify a name for the replacement instance. In theBoot disksection, clickChange, then clickExisting Disks. Selectthe new disk.

    4. ClickCreate. The replacement instance automaticallystarts after it is created.

    As the replacement instance boots up, the temporaryrc.local scriptruns and installs the guest environment.To watch the progress of this script, inspect the console logs for linesemitted by the temporaryrc.local script. 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 temporaryrc.local script finishes. During the secondreboot, you caninspect the console log to makesure the guest environment loads.

  9. 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-agent

Windows

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 systemService managementExpected 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 oldersystemd
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

  1. In the Google Cloud console, go to theVM instances page.

    Go to VM instances

    1. Select the instance you need to examine.
    2. Restartorreset the instance.
    3. UnderLogs, clickSerial port 1 (console).
    4. Search for the expected output in the table that precedes thesesteps.

gcloud

  1. Restartorreset the instance.
  2. Use thegcloud compute instances get-serial-port-output sub-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.

  3. 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 systemCommand to list servicesExpected 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 systemCommand to list packagesExpected 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 likegoogle-cloud-cli-anthoscli. RHEL images can have version-specific packages (for example,google-rhui-client-rhel8) or SAP-specific variants.

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

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.