KVM Virsh Console Access to Linux VM – CentOS 6

This document will show you how to get virsh console access to guest virtual machines.

The console command within virsh is an excellent feature to have working for your virtual environments. For example, it can be really handy to watch a machine boot without launching a GUI tool ie. virt-manager. I personally find virsh console access a quicker way to configure networking settings which may not be able to be achieved via SSH, other than using virt-manager.

[box type="info"] Just note that this document assumes CentOS 6 for all example code and references. Syntax, file locations and codes may vary based on your distribution.[/box]

Typically out of the box, when you install a new CentOS 6 virtual machine, the “virsh console” command will not work…

Step 1: Configure Serial Terminal

On your new CentOS 6 virtual machine, you’ll need to configure ttyS0. This serial interface is how “virsh console” gains access to your virtual machine.

Log into your virtual machine…

Create new ttyS0 config file

Copy/Paste the following config

Step 2: Allow login into ttyS0

By default CentOS will not allow a user to login via ttyS0 unless we modify securetty.

Add the following to the end of the file and save it.

Step 3: Start ttyS0

Make ttyS0 available, from your terminal execute the following command

Step 3: Test Virsh Console

From your KVM server, connect to the console of your virtual machine

Step 4: Configure Access to Boot Output

To watch your virtual machines boot/shutdown messages we need to make a couple of changes to your boot process.

Edit your grub config

Your kernel entry may look something like this

You’ll want to remove the “rhgb” option, this is the boot splash screen. The “quiet” entry hides a lot of boot messages, I remove so more detail is outputted.

Finally you’ll want to add “console=ttyS0″ to send the boot messages to your virsh console. Your kernel line may now look like this

[author] [author_image timthumb='on']http://mcdee.com.au/wp-content/uploads/2012/11/photo.jpg[/author_image] [author_info]Andrew McDonald is an IT Systems Admin and all round technology junkie. Absolutely a jack-of-all-trades and not one to shy away from a challenge.

[/author_info] [/author]