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: [<ffffffff81a4cfec>] 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.
For my templates I use: grubby --update-kernel=ALL --args="crashkernel=0@0 video=1024x768 console=ttyS0,115200n8 console=tty0 consoleblank=0"
HTH
-- Sent from the Delta quadrant using Borg technology!
Nux! www.nux.ro
----- Original Message -----
From: "Chris Adams" linux@cmadams.net To: centos@centos.org Sent: Wednesday, 8 October, 2014 17:06:03 Subject: [CentOS] CentOS 7 kernel console under KVM?
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: [<ffffffff81a4cfec>] 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. -- Chris Adams linux@cmadams.net _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On Wed, 8 Oct 2014, Nux! wrote:
For my templates I use: grubby --update-kernel=ALL --args="crashkernel=0@0 video=1024x768 console=ttyS0,115200n8 console=tty0 consoleblank=0"
In kickstart files for CentOS 7 VMs that run in what I still think of as runlevel 3, I use a somewhat simpler recipe:
bootloader --location=mbr --append="console=ttyS0"
On the VM, that translates into /etc/default/grub looking something like this:
GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL="serial console" GRUB_SERIAL_COMMAND="serial" GRUB_CMDLINE_LINUX="rd.lvm.lv=vg0/vmroot console=ttyS0 crashkernel=auto vconsole.font=latarcyrheb-sun16 vconsole.keymap=us" GRUB_DISABLE_RECOVERY="true"
When the VM boots, it's then easy to run "virsh console YOURVM" to attach to the serial console.
On Wed, 8 Oct 2014, Chris Adams wrote:
Is there a way to get GRUB2 and the kernel to run a "serial" console under KVM?
<snip>
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 --speed=115200 --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 linux@cmadams.net said:
Is there a way to get GRUB2 and the kernel to run a "serial" console under KVM?
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.
Chris Adams wrote:
Once upon a time, Chris Adams linux@cmadams.net said:
Is there a way to get GRUB2 and the kernel to run a "serial" console under KVM?
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.
Any idea if pts's are set up? Also, is this of any help http://wiki.libvirt.org/page/Unable_to_connect_to_console_of_a_running_domain?
mark
Once upon a time, m.roth@5-cent.us m.roth@5-cent.us said:
Any idea if pts's are set up? Also, is this of any help http://wiki.libvirt.org/page/Unable_to_connect_to_console_of_a_running_domain?
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:
<serial type='pty'> <target port='0'/> </serial> <console type='pty'> <target type='serial' port='0'/> </console>
And here's what you get when you say RHEL7:
<console type='pty'> <target type='virtio' port='0'/> </console>
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.