Serial console with Azure VMs - Troubleshooting and diagnosing

Do you have Virtual Machines in Azure? If so, you probably need to resolve a problem with them from time to time. This is sometimes difficult with VMs running in Azure, as some things, like the boot menu, aren't visible to you. Luckily, there is a very handy tool that you can use to troubleshoot your VM in Azure. It's called the Virtual Machine Serial Console.

Serial console lets you use a command line to operate your VM from the Azure Portal. The beauty of it is that it works independent from the state of the VM. So it works when you're booting up, shutting down and when you are running. And it even works if the VM doesn't have an internet connection as the serial console connects to the COM1 serial port. Let's explore how we can use the serial console with Azure VMs for troubleshooting and diagnostics.

Making it work

The serial console feature is available for Windows and Linux VM images. For most Windows images that are created in February 2018 or after that, it will work out-of-the-box. In case that it doesn't work, you need to make sure that you have all of the prerequisites in place and you can follow these steps.

(Serial console in the Azure portal)

Working with serial console

In my case, the serial console works out-of-the-box. This is because I run a VM with an image of Windows 10 and Visual Studios latest preview that was created after February 2018.

When you open the serial console, it shows you the SAC command prompt. From there, you can perform very helpfull operations on your VM, like restarting it and kill processes.

(Serial console SAC commands)

Serial console works with so-called 'channels'. From the SAC command prompt, you can start a channel for cmd.exe by typing CMD <enter>. This start the CMD channel. And by typing ch -? <enter>, you'll see all of the commands that you can use to manage the channel.

(Serial console channel management commands)

Now, you can use the shortcut <esc><tab> to switch to the CMD channel and back. Once you do, you switch to the CMD channel, which allows you to use the regular windows command prompt to do everything that you need to. You will need to log in with your VM administrator account to access the command prompt. Because of this, one of the prerequisites is that you have an administrative account with a password for the VM.

Once logged in, you can, for instance check the properties of the network card or manipulate the file system.

(Manipulate the file system in the CMD channel)

If you prefer to use PowerShell, you can even start a PowerShell prompt from the CMD channel. Just type powershell <enter>. Now, you can use PowerShell to do all sorts of thing. For instance, to check if RDP is enabled in your VM.

(Check if RDP is enabled using PowerShell)

Using serial console to get into the VM boot menu

One thing that I've always wanted to do with VMs in Azure that run some of my old images, is to access the boot menu. Sometimes, I just need the option to, for instance, start Windows in safe mode. Now, with serial console, I can. And it's pretty simple to set up.

  1. Switch to a cmd channel in the serial console. You can do that by using <esc><tab>. If you don't have a cmd channel yet, type CMD <enter> from the SAC command prompt
  2. Enter the following commands:
bcdedit /set {bootmgr} displaybootmenu yes \<enter>

bcdedit /set {bootmgr} timeout 20 \<enter>

bcdedit /set {bootmgr} bootems yes \<enter>
1
2
3
4
5

The timeout in the commands determines how long you can see the boot manager menu. That's it! Now, when you reboot the VM, you can access the boot menu from the serial console. You can test that by going to the SAC command prompt and typing in restart <enter>. This reboots the VM and shows you the standard windows boot menu. When you now press F8, the advanced boot options menu appears.

(Windows Advanced Boot Options menu in the serial console)

Conclusion

Serial console is a hidden gem that can help you a lot when you need to troubleshoot your Azure VM. Go and check it out.