virsh: VM console does not show any output

<serial type='pty'>
  <target port='0'/>
</serial>
<console type='pty'>
  <target type='serial' port='0'/>
</console>

This is what I normally add to the VMs definition, using virsh edit Then console=ttyS0 appended in the VM's kernel line in grub.conf

Never failed me so far


Working example of using Debian jessie as host and guest operating system.

  1. create a VM using virt-install or virt-manager In any case you will get serial console statements added to VM.xml file

  2. in guest VM run the following

    systemctl enable [email protected]
    systemctl start [email protected]
    
  3. in guest VM in /etc/default/grub replace

    GRUB_CMDLINE_LINUX_DEFAULT="quiet"
    #GRUB_TERMINAL=console
    

    by

    GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0"
    GRUB_TERMINAL="serial console"
    
  4. in guest VM run the following

    guest# update-grub
    
  5. the VM console for running VM can be get by

    host# virsh console VM
    

    or start the VM with console attached

    host# virsh start VM --console
    

Sources:

  • 0pointer.de systemd for Administrators, Part XVI
  • keypressure.com Testing libvirt over TLS

I've found the most applicable answer here:

Suppose your virtual domain is myGuest, your preferred editor is vi, and your guest is installed with grub2 and uses systemd. If the last assumption is not true, you might have a look at Working with the Serial Console.

First, install libguestfs-tools on the host: sudo apt install libguestfs-tools. You will need this when working with headless guests.

Second, shut down your guest: virsh shutdown myGuest.

Next, mount the virtual disk: guestmount -d myGuest -i /mnt (or use any other existing directory as mountpoint). Now in /mnt you should be able to see the filesystem of the guest.

With grub2 and systemd, you only have to modify the grub configuration: vi /mnt/etc/default/grub, and modify like

GRUB_CMDLINE_LINUX='console=tty0 console=ttyS0,19200n8'
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=19200 --unit=0 --word=8 --parity=no --stop=1"

As you will have to run update-grub on the guest, for the first start you have to also modify /mnt/boot/grub/grub.cfg. Find the default boot menu item and append the console information to the linux entry to look similar to

linux   /boot/vmlinuz-4.4.0-75-generic root=UUID=76f3e237-d791-4e9d-8ad7-fe5c9165ae55 ro console=ttyS0,19200 earlyprint=serial,ttyS0,19200

Maybe you need root privileges to mount and edit the files.

Now restart the guest and start the virtual console:

virsh start myGuest && virsh console myGuest

You should see the kernel log and then a login prompt. After logging in, don't forget to run sudo update-grub.