Viewing serial port output

A virtual machine (VM) instance has four virtual serial ports. The instance'soperating system, BIOS, and other system-level entities often write output tothe serial ports, which makes serial port output useful for troubleshootingcrashes, failed boots, startup issues, or shutdown issues.

This page describes methods toview serial port output, including usingCloud Logging to retain serial port output even after an instance isstopped or deleted. If you need tosend commands to a serial port while aninstance is running, seeInteracting with the serial console.

Serial port output is accessible through the Google Cloud console, thegcloud CLI, and REST, but only while the VM instanceis running. Logs are limited to the most recent 1 MB of output per port.

If you enable serial port output logging, Cloud Loggingprovides the first50 gibibytes (GiB) per month of logging for free andretains logs for30 days.

Before you begin

Enabling and disabling serial port output logging

You can control whether your instances send serial port output toCloud Logging bysetting project- or instance-level metadata.You can also disable the feature for all of the users in your organizationbysetting an organization policy.

Note: Serial port output is useful for troubleshooting VM crashes, failed boots,and startup or shutdown issues. Disabling these logs might limit Google'sability to troubleshoot such issues.

Setting project and instance metadata

By default, serial port output logging to Cloud Logging is disabled. If serial port output logging to Cloud Logging is notconstrained for your organization,then you can enable or disable it for projects and for individual VMinstances by setting theserial-port-logging-enable metadata entry totrueorfalse.

If you set a project-wide metadata entry, all VM instances in the projectinherit that setting implicitly. If you set an instance metadata entry, themetadata entry is enabled for that VM only, regardless of the project setting.

You can set a metadata entry by using the Google Cloud console, thegcloud CLI, or the Compute Engine API. For more information, seeSetting custom metadata.

For example, the following gcloud CLI command enables serial portoutput logging to Cloud Logging for your project:

gcloud compute project-info add-metadata \    --metadata serial-port-logging-enable=true

Similarly, the following gcloud CLI command enables serial port output loggingto Cloud Logging for a specific instance instead:

gcloud compute instances add-metadataINSTANCE_NAME \    --metadata serial-port-logging-enable=true

To disable serial port output logging to Cloud Logging, setserial-port-logging-enable tofalse:

gcloud compute instances add-metadataINSTANCE_NAME \    --metadata serial-port-logging-enable=false

Exclusion filters

From within Cloud Logging, you cancreate an exclusion filter toremove specific serial port entries from the Logs Explorer. For example, witha project-wide metadata entry that is set toserial-port-logging-enable=true,you can disable serial port output logging for specific VM instances by usingan advanced filter:

logName = "projects/PROJECT_ID/logs/serialconsole.googleapis.com%2Fserial_port_1_output"resource.type = "gce_instance"resource.labels.instance_id != "INSTANCE_1_ID"resource.labels.instance_id != "INSTANCE_2_ID"

Setting an organization policy

You can disable serial port output logging to Cloud Logging for your entireorganization by setting anOrganization Policy, whichconstrains certain configurations of Google Cloud resources. Specifically,set the following boolean constraint:constraints/compute.disableSerialPortLogging. For more information, seeCreating and managing organization policies.

Disabling serial port logging by settingconstraints/compute.disableSerialPortLogging totrue is notretroactive. Existing VM instances with a metadata entry that enablesserial port logging to Cloud Logging continue to log to Cloud Loggingunless youreset the metadata forthose instances.

After setting this organization constraint totrue, you cannot set instance orproject metadata to enable serial port output logging to Cloud Logging forany instances within the organization.

Viewing serial port output

Console

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

    Go to the VM instances page

  2. Select the VM instance for which you want to view serial port output.

  3. UnderLogs, clickSerial port 1,2,3, or4.System-level entities typically use the first serial port (port 1), whichis also known as theserial console.

gcloud

Use thegcloud compute instances get-serial-port-output command.

gcloud compute instances get-serial-port-outputINSTANCE_NAME \  --portPORT \  --startSTART \  --zoneZONE

Replace the following:

  • INSTANCE_NAME: the name of the instance.
  • PORT: the number of the port (1,2,3, or4) for which you want to view output. System-level entities typicallyuse the first serial port (port 1), which is also known as the serialconsole. By default, the output of the first serial port is returned.
  • START: the byte index (zero-based) of the firstbyte you want returned. Use this flag if you want to continue getting theoutput from a previous request that was too long to return in one attempt.
  • ZONE: the zone of your instance.

REST

In the API, create aget request to theinstances.getSerialPortOutput method.

GET https://compute.googleapis.com/compute/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/serialPort

Cloud Logging

  1. Enable serial port logging to Cloud Logging.
  2. Go to theVM instances page.

    Go to the VM instances page

  3. Select the VM instance for which you want to view startup agent logs.

  4. UnderLogs, clickCloud Logging to view Cloud Logginglogs.

    Click Cloud Logging to view Cloud Logginglogs.

For more information, including information about filtering, seeUsing the Logs Explorer.

Handling non-UTF8 characters

Serial port output is escaped by using the open sourceAbseil C++ library'sCHexEscape() method,so non-UTF8 characters are encoded as hex strings. You can use the correspondingCUnescape() methodto get the exact output that was sent to the serial port.

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.