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 ^]
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
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:
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.
10 comments
How can I enable the console on the guest VM?
Still I have no console access?
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
Hi I am not able to launch Graphic console in remote viewer ..any solution for that …console is working now after above fix .
Is console works or not? I couldn’t understand your question.
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.
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
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
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.
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.
Glad you found the root cause. Regards.