CentOS 7 Kernel Console Under KVM?

Home » CentOS » CentOS 7 Kernel Console Under KVM?
CentOS 5 Comments

Is there a way to get GRUB2 and the kernel to run a “serial” console under KVM?

I’m running a Fedora 20 desktop, with libvirt-managed VMs. When I run a CentOS 6 VM, I can set both the boot loader and kernel up to use ttyS0
and get a console compatible with “virsh console”.

When I try the same with a CentOS 7 VM, it doesn’t work. If I set it to ttyS0, I just don’t get anything. I read that I should use hvc0
instead (no idea how to set the boot loader to use that); when I set that on the kernel command line, the kernel crashes during boot with:

kernel tried to execute NX-protected page – exploit attempt? (uid: 0)
BUG: unable to handle kernel paging request at ffffffff81a4cfec IP: [] vty_init+0x174/0x174
PGD 18d3067 PUD 18d4063 PMD 3d9e1063 PTE 8000000001a4c163

If I don’t do either, I can add a getty on hvc0 with “systemctl enable serial-getty@hvc0.service”, but that doesn’t get me the boot loader or kernel messages.

5 thoughts on - CentOS 7 Kernel Console Under KVM?

  • For my templates I use:
    grubby –update-kernel=ALL –args=”crashkernel=0@0 video24×768 console=ttyS0,115200n8 console=tty0 consoleblank=0″

    HTH

  • This worked for me. Add the following three lines to /etc/default/grub:

    GRUB_CMDLINE_LINUX=’console=tty0 console=ttyS0,115200n8′
    GRUB_TERMINAL=serial
    GRUB_SERIAL_COMMAND=”serial –speed5200 –unit=0 –word=8 –parity=no –stop=1″

    Then re-generate grub.cfg:

    grub2-mkconfig -o /boot/grub2/grub.cfg

    Taken from: https://fedoraproject.org/wiki/GRUB_2?rd=Grub2

    (near the bottom of the page)

  • Once upon a time, Chris Adams said:

    So, I guess the people who replied didn’t read – I tried ttyS0, and that didn’t work.

    I did figure out why that doesn’t work: when setting up a new VM with libvirt in F20, if you choose RHEL7 as the guest OS, it gets set up differently than RHEL6. One difference is that it sets up a virtio console, instead of a serial console.

    First, it doesn’t look like GRUB2 can talk to a virtio console.

    Second, I guess I’m hitting a kernel bug, because the kernel should be able to talk to a virtio console (i.e. hvc0). It certainly shouldn’t crash because I tried to use that. The device works after boot (I can run a getty on it), it seems only the kernel can’t talk to it directly as a console.

  • Once upon a time, m.roth@5-cent.us said:

    That’s the “old” way (the way virt-install defaults for RHEL6 and before). The “new and improved” way is a direct virtualized device.

    Here’s what virt-install would set for the old way:






    And here’s what you get when you say RHEL7:



    That works for setting up a hvc0 device in the guest. It appears that it is implemented through a kernel module, virtio_console. Now, from past experience, the kernel is supposed to be able to handle consoles that only show up when modules are loaded (e.g. USB serial), so that
    _should_ work. The kernel crash is a bug I guess; the virtio_console module appears to have some “issues” as well (not refcounted properly for example; I can unload the module while I’m logged in through a getty on hvc0, which then goes away).

    I need to try a Fedora guest and see what happens (have to wait on that, don’t have a Fedora tree at work to install from). Could be a general kernel bug, or could just be RHEL7’s kernel.

    Still, no matter what, virtio console leaves out the boot loader. Maybe I’ll file a bug against Fedora (or upstream) virt-manager that virtio console shouldn’t be used by default.