Troubleshoot VM with Serial Console Access in Google Cloud

Sumit K
Google Cloud - Community
6 min readAug 30, 2023

Virtual Machines play a crucial role in running your applications and services, however, like any technology, VMs can encounter issues that require troubleshooting and maintenance. Serial console access is a way to connect to a virtual machine (VM) over a serial port. This can be useful for troubleshooting problems with the VM, such as when it is not booting or is hung. The serial console is a text-based interface that allows you to connect to a VM and interact with it directly. This can be useful for troubleshooting problems that prevent you from connecting to the VM using SSH or RDP.

When and why do we need it? Serial console access is useful in the following situations:

  • When the VM is not booting: You can use serial console access to see the boot messages and identify the problem.
  • When the VM is hung: You can use serial console access to see what the VM is doing and try to unfreeze it.
  • When you need to access the VM’s BIOS or UEFI: You can use serial console access to access the VM’s BIOS or UEFI, which can be useful for changing settings or troubleshooting problems.
  • Resolving issues with the VM’s operating system.

How do you SSH/RDP if your VM gets hung or the booting starts screen?

If your VM is hanging or stuck on the boot screen, you can use serial console access to SSH or RDP into the VM. To do this, you will need to:

  1. Go to the Compute Engine page in the Google Cloud console.
  2. Click the name of the VM.
  3. Click the Serial console tab.
  4. Click the Connect button.
  5. Select the SSH or RDP option.
  6. Follow the instructions to connect to the VM.

Once you are connected to the VM, you can troubleshoot the problem and take corrective action. Let’s take a look at the demo. It’s pretty simple to use.

Step1. Let’s deploy a VM with Serial Console enabled. you can enable the serial console from the UI console. there is an option to serial-port-enable access under the Metadata but this will be visible once your VM is created and then try to EDIT it Alternatively the second option is to simply grab this terraform code below and deploy it.

  • In the Google Cloud console, go to the VM instances page
  • Click the instance you want to enable access for.
  • Click Edit.
  • Under the Remote access section, toggle the Enable connecting to serial ports checkbox.
  • Save your changes. Refer the Snippet below.

Using Terraform: if you don’t want to use the UI console, you can simply use this Terraform code to deploy your VM with the serial console enabled.

resource "google_compute_instance" "vm" {
name = "my-vm"
machine_type = "n1-standard-1"
zone = "us-central1-a"

boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}

network_interface {
network = "default"
access_config {
enable_serial_console = true #Enable serial console access.
}
}
}

Step2. Connecting to a serial console with a login prompt

If you are trying to troubleshoot an issue with a VM that has booted completely or trying to troubleshoot an issue that occurs after the VM has booted past single-user mode, you might be prompted for login information when trying to access the serial console. By default, Google-supplied Linux system images are not configured to allow password-based logins for local users. However, Google-supplied Windows images are configured to allow password-based logins for local users.

By default, Google-supplied Linux system images are not configured to allow password-based logins for local users. However, Google-supplied Windows images are configured to allow password-based logins for local users.

You can use a startup script to set up a local password that enables you to connect to the serial console during or after VM creation. The following instructions describe how to set up a local password after VM creation.

In the Google Cloud console, go to the VM instances page.

  1. In the Google Cloud console, go to the VM instances page.
  2. Select the VM for which you want to add the local password.
  3. Click Edit.
  4. Navigate to the Metadata > Automation section.
  5. If the VM has an existing startup script, copy it and paste it somewhere safe.
  6. Add the following startup script:
#!/bin/bash
useradd USERNAME
echo USERNAME:PASSWORD | chpasswd
usermod -aG google-sudoers USERNAME



Replace the following:

USERNAME: the username that you want to add
PASSWORD: the password for the username. Avoid simple passwords, as some operating systems may requires minimal password length and complexity.

7. Click Save.

8 . To reboot the VM, click Reset.

9. Connect to the serial console. you can connect now or later in the step3.

10. Enter your login information when prompted.

11. Remove the startup script from the VM after the user has been created.

Step3. Let’s connect to your VM with Serial Console Access. Remember that we will use the local user that we have just created with the start-up script to access our VM. With this user, you can troubleshoot your VM and analyze the issues at the OS level.

Step 4: You can also view live booting of your operating system during troubleshooting. this console access helps in your finding while troubleshooting your VM.

Step5. Well, you can also connect to Serial Port1 to see the snapshot version of your VM console. As you can see recent commands that I performed have been captured on serial Port1. So you can take advantage of serial port1 while troubleshooting of your VM.

Conclusion: The serial console is a valuable tool for troubleshooting virtual machines (VMs). It can be used to access a VM’s console even if the VM is not accessible over the network. This can be helpful for troubleshooting boot issues, network problems, and other issues.

The best method for troubleshooting a VM will vary depending on the specific problem. However, the serial console, logging, performance monitoring, and optimization are all valuable tools that can be used to troubleshoot VMs.

Here are some additional tips for troubleshooting VMs:

  • Start with the basics: Make sure that the VM is properly configured and that all of the required dependencies are installed.
  • Use the search bar: The search bar can be a helpful tool for finding documentation and troubleshooting tips.
  • Ask for help: If you are stuck, don’t be afraid to ask for help from a more experienced administrator.

Additional Resource: Go check out the official documentation:
Troubleshooting using the serial console | Compute Engine Documentation | Google Cloud

Book a call for consulting/assistance: https://topmate.io/sumit_kumar40

--

--

Sumit K
Google Cloud - Community

Humanity is the quality that we lack so much in real life, An Abide leaner, Cloud Architect⛅️, Love DevOps,,GDE,Proud Hindu 🕉️