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]

  16 comments

  1. Srinivas   •  

    Excellent — thanks!

  2. Eugene   •  

    Hey Andrew,

    Thanks for quick manual. But It doesn’t work, actually, with your manual guest system will not permit to root login. You made a mistake in Step 2, correct definition would be ttyS0 not ttys0. With your definition I got:

    login: pam_securetty(login:auth): access denied: tty ‘ttyS0′ is not secure !

    So I defined ttyS0 in securetty :)

    Thanks again)

  3. Jason   •  

    Hi Andrew!

    Great article, precise and very helpful.

    Do you know if there is a way to duplicate the console to both VGA + Serial console. (IE. I want to use the VNC viewer for a KVM guest and be able to use ‘virsh console ‘ to use the console on a host.

  4. Lazaro   •  

    How to close the Virsh Console?? I logged out from the linux, but it returns to login, How can I return to the virsh console?

  5. David   •  

    I made step by step in my Centos 6.5 vm but it shows me the same thing.

    [root@bigavatar ~]# virsh console blueeye-apps
    Connected to domain blueeye-apps
    Escape character is ^]

    What could i doing bad ? Please help me.
    Sorry for my English, i only speak spanish.

    • Sergey   •  

      On the VM:
      cat /var/log/dmesg | grep ‘console \['

      If you see something like this:
      console [tty0] enabled
      console [hvc0] enabled

      then replace ttyS0 everywhere above with hvc0

      Enjoy!

  6. Pingback: Creating a Virtualized Hadoop Lab | TECHtonka

  7. Nick   •  

    A small correction: the line that you add to /etc/securetty should be “ttyS0″ and not “ttys0″ (note the capital S)

    Many thanks for this mini-how-to!

  8. Pingback: How To Install Adempiere On Centos | Dragonh4

  9. Pingback: Virsh How To | Uomino4

  10. Tony den Haan   •  

    Nice, but doesn’t persist through reboot on centos 6.8. Some upstart magic needed?

  11. Tony den Haan   •  

    Ok, i found out it does work when i also set console in grub.conf :)

  12. StephenOpesk   •  

    Конвекторы очень легко устанавливать — их навешивают на вмонтированные в стену кронштейны и включают в розетку Хайтек как ультрасовременный стиль в интерьере или фото для принятия верного стилевого решения. Если помещение сделать шире, то оно будет быстро выхолаживаться, а на освещение и обогрев потребуется большое количество электроэнергии.

  13. Jefferyjut   •  

    Stress can have an unbelievable impact on health. It can come from a variety of sources and have a diversity of manifestations. The tips that are outlined below will aid in the identification of the factors that cause stress and in the steps that we can take to reduce its impacts or eliminate them entirely.

    viagra a vendre canada

  14. Pingback: kvm初体验之四:从Host登录Guest的五种方式-操作系统相关

Leave a Reply to Sergey Cancel reply

Your email address will not be published. Required fields are marked *


1 × = two

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">