Home FAQ How To Enable Virsh Console Access For KVM Guests
How To Enable Virsh Console Access For KVM Guests In Linux

How To Enable Virsh Console Access For KVM Guests

By sk
2078 Views

After creating the KVM guests, I can be able to access them via SSH, VNC client, Virt-viewer, Virt-manager and Cockpit web console etc. But I couldn't access them using "virsh console" command. For those wondering, the "virsh console" command is used to connect to the guest machine's console from the host system. After looking into the KVM documentation, I found that we should enable serial console in the KVM guest system in order to enable virsh console access for KVM guests.

I have a CentOS 8 virtual machine running in my Ubuntu 20.04 system.

$ virsh list
 Id   Name      State
-------------------------
 1    centos8   running

I tried to access the console of CentOS 8 VM using the following command:

$ virsh console centos8

I got this this output:

Connected to domain centos8
Escape character is ^]

Access console of a KVM guest using virsh command in Linux

It says that I am connected to centos8 VM, but I don't see the VM's console. I can't get past this screen. It kept showing this blank screen until I manually exit it by pressing CTRL+] key. If you've ever been in this situation, just enable serial console service as described below.

Enable Virsh Console Access For KVM Guests

Like I already mentioned, you have to add a serial console in your guest machine in order to access its virsh console from the host system.

To do so, log in to your guest machine via SSH or Virt-manager or Cockpit and run the following commands to enable and start a serial console:

# systemctl enable [email protected]
# systemctl start [email protected]

Enable virsh console access for KVM virtual machines

Please note that the above commands should be run in KVM guest system (virtual machine), not in the KVM host.

That's it. We have enabled the serial console interface in the guest.

You can verify it by looking into the VM's configuration XML file:

$ virsh edit centos8

If serial console is enabled, you will see the following lines:

    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>

Close the XML file and exit from the guest machine.

Now start the virsh console of the guest system from the host using command:

$ virsh console centos8

You will be greeted with this message:

Connected to domain centos8
Escape character is ^]

Press ENTER again and type your user name and password to connect to the guest machine:

virsh console of the KVM virtual machine

You are now inside the guest machine's console. Start using it. You can switch back to the host console at any time by pressing "CTRL+]" keys.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More