Home KVM How To Enable Virsh Console Access For KVM Guests

How To Enable Virsh Console Access For KVM Guests

By sk
Published: Updated: 87.6K 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
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 serial-getty@ttyS0.service
# systemctl start serial-getty@ttyS0.service
Enable virsh console access for KVM virtual machines
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
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.

You May Also Like

10 comments

Timi December 8, 2020 - 1:45 pm

How can I enable the console on the guest VM?
Still I have no console access?

Reply
sk December 8, 2020 - 8:25 pm

It is clearly mentioned in the article. 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 serial-getty@ttyS0.service
# systemctl start serial-getty@ttyS0.service

Reply
Anil January 7, 2022 - 11:26 am

Hi I am not able to launch Graphic console in remote viewer ..any solution for that …console is working now after above fix .

Reply
sk January 7, 2022 - 1:56 pm

Is console works or not? I couldn’t understand your question.

Reply
David May 6, 2022 - 1:54 am

I have same problem like TIMI above I cannot login the vm, how can I set the serial service.
I need to know the new created vm’s ip address then login.

Reply
sk May 6, 2022 - 11:49 am

Hi David,

Please log in to the guest machine and run the following commands to start serial console.

# systemctl enable serial-getty@ttyS0.service

# systemctl start serial-getty@ttyS0.service

Reply
David May 7, 2022 - 4:04 am

Hi SK,

my problem is : I dont know ip address of my new created guest VM, so I need to login it from the KVM host via virsh console command.

I think the serial service should be run in the guest VM, so how can I reach there without knowing its ip address?

BTW, I noticed you have another excellent article about how to gain the ip address of the guest VM, but I tried all your methods and none of them worked for me.

the article link: https://ostechnix.com/how-to-find-the-ip-address-of-a-kvm-virtual-machine/

Thanks,
David

Reply
sk May 7, 2022 - 11:05 am

Hi David, you still can access the VM without the IP address. You could try KVM graphical front-end called “Virt-manager”. Check this link for to know how to use Virt-manager – https://ostechnix.com/how-to-manage-kvm-virtual-machines-with-virt-manager/. IP address is required only when you want to access VM from a remote system. To access the VM from KVM host itself, you don’t need IP address at all.

Reply
David May 10, 2022 - 9:48 pm

Hi SK,

Virt-manager is my 1st try and it didnt work – a black ternimal without any output for more than 30 minutes, then I tried to use console command, but as said above, I dont know its ip so this cmd cannot be used.

BTW, the problem is I need to setup DHCP from KVM thus the VM can get an ip.

thank you for your kind replies.

Reply
sk May 11, 2022 - 11:20 am

Glad you found the root cause. Regards.

Reply

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. By using this site, we will assume that you're OK with it. Accept Read More