Viewing Serial Port Output

A virtual machine instance has four virtual serial ports. The instance's operating system, BIOS, and other system-level entities often write output to the serial ports, which makes them useful for troubleshooting crashes, failed boots, startup issues, or shutdown issues.

This page describes methods to view serial port output, including using Stackdriver logging to retain serial port output even after an instance is stopped or deleted. If you need to send commands to a serial port while an instance is running, see Interacting with the Serial Console.

Serial port output is accessible through the GCP Console, gcloud tool, and API, only when the VM instance is running, and logs are limited to the most recent 1 MB of output per port.

If you enable serial port output logging to Stackdriver, logs are retained for 30 days by default and Stackdriver provides the first 50 GB per month of logging for free. See Stackdriver pricing for details.

Before you begin

Enabling and disabling serial port logging to Stackdriver

To enable this feature, set the serial-port-logging-enable metadata attribute to true. When this key-value metadata is set at the project level, serial port output logging to Stackdriver is enabled for all instances in the project. When it is set at the VM instance level it is enabled for that VM only, regardless of the project setting.

You can set custom metadata through the Google Cloud Platform Console, the gcloud tool, or the API. See Setting custom metadata for all the details.

For example, you can use the following gcloud command to enable serial port output logging to Stackdriver for an existing instance.

gcloud compute instances add-metadata [INSTANCE_NAME] \
    --metadata serial-port-logging-enable=true

To disable serial port output logging to Stackdriver, set serial-port-logging-enable to false.

gcloud compute instances add-metadata [INSTANCE_NAME] \
    --metadata serial-port-logging-enable=false

Alternatively, from within Stackdriver, you can create an exclusion filter to remove specific serial port entries from the Logs Viewer. For example, with serial-port-logging-enable=true at the project level, you can disable serial port outuput logging for specific VM instances with an advanced filter like the following one.

logName = "projects/google.com:serial-output-logging-demo/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]"

Viewing serial port output

Console

  1. Go to the VM instances page.

    Go to the VM instances page

  2. Select the VM instance for which you want to view serial port output.
  3. Under Logs, click Serial port 1, 2, 3, or 4. System-level entities typically use the first serial port (port 1), which is also known as the serial console.

gcloud

Use the gcloud instances get-serial-port-output command.

gcloud compute instances get-serial-port-output [INSTANCE_NAME] \
  --port [PORT] \
  --start [START] \
  --zone [ZONE]

where:

  • [INSTANCE_NAME] is the name of the instance.
  • [PORT] is number of the port (1, 2, 3, or 4) for which you want to view output. System-level entities typically use the first serial port (port 1), which is also known as the serial console. By default, the output of the first serial port is returned.
  • [START] specifies the byte index (zero-based) of the first byte you want returned. Use this flag if you want to continue getting the output from a previous request that was too long to return in one attempt.

API

In the API, create a get request to the instances.getSerialPortOutput method.

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

Stackdriver

  1. Enable serial port logging to Stackdriver
  2. Go to the VM instances page.

    Go to the VM instances page

  3. Select the VM instance for which you want to view startup agent logs.
  4. Under Logs, click Stackdriver Logging to view Stackdriver logs.

  5. Expand the All logs dropdown menu and select the serial port output that you want to see. System-level entities typically use the first serial port (port 1), which is also known as the serial console. If a port does not appear in the dropdown menu, it has no available output.

  6. See the Stackdriver documentation on Viewing logs for more details, including basic and advance filtering.

Handling non-UTF8 characters

Serial port output is escaped using the open source Abseil C++ library's CHexEscape() method, so non-UTF8 characters are encoded as hex strings. You can use the corresponding CUnescape() method to get the exact output that was emitted to the serial port.

Was this page helpful? Let us know how we did:

Send feedback about...

Compute Engine Documentation