{"id":760,"date":"2014-10-29T08:20:02","date_gmt":"2014-10-29T15:20:02","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=760"},"modified":"2014-10-30T09:40:27","modified_gmt":"2014-10-30T16:40:27","slug":"kvm-virsh-console-on-centos-7","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/kvm-virsh-console-on-centos-7\/","title":{"rendered":"KVM virsh console on CentOS 7"},"content":{"rendered":"

Several articles on using the console feature of KVM guests exists already. This is just a quick note on a test I did using specifically Centos 7 which is using systemd now.<\/p>\n

Console allows you to A) see bootup messages and B) login on the console of the guest without SSH.<\/p>\n

As far as I can tell you only need to do two things. Add console=ttyS0 to the kernel being booted and in the guest XML switch virtio to serial for the console. Keep in mind this is if you are using the RHEL 7 type when creating the VM. If you were using a RHEL 6 type when creating the guest the console probably still were configured to use serial.<\/p>\n

This KVM hypervisor is on Fedora 20 and using libvirt version 1.1.3.6.<\/p>\n

To send messages from the kernel to the serial console add console=ttyS0:<\/span><\/p>\n

\r\n# grep console=ttyS0 \/boot\/grub2\/grub.cfg\r\n        linux16 \/vmlinuz-3.10.0-123.el7.x86_64 root=UUID=ba0f2424-e66e-4862-90ff-7dccb63339c2 ro rd.lvm.lv=centos\/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos\/root crashkernel=auto  vconsole.keymap=us LANG=en_US.UTF-8 console=ttyS0\r\n\r\n# grep ttyS0 \/etc\/securetty\r\nttyS0\r\n<\/pre>\n

Change guest console type to serial:<\/span><\/p>\n

\r\n<console type='pty' tty='\/dev\/pts\/6'>\r\n      <source path='\/dev\/pts\/6'\/>\r\n      <target type='serial' port='0'\/>\r\n      <alias name='serial0'\/>\r\n    <\/console>\r\n\r\n# virsh console centos7\r\nConnected to domain centos7\r\nCentOS Linux 7 (Core)\r\nKernel 3.10.0-123.el7.x86_64 on an x86_64\r\n\r\nlocalhost login: \r\n\r\n<\/pre>\n

Above should do it but if you want to see even the grub2 menu options you can try the following:<\/p>\n

\r\n# grep serial \/etc\/default\/grub \r\nGRUB_TERMINAL=serial\r\nGRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1"\r\n\r\n# grep LINUX_DEFAULT \/etc\/default\/grub \r\nGRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0"\r\n\r\n# grub2-mkconfig -o \/boot\/grub2\/grub.cfg\r\n<\/pre>\n

Of course if you are setting grub DEFAULT options you don't need to set anything for the kernel entries in \/boot\/grub2\/grub.cfg like I did in step 1. <\/p>\n

Note that when connecting to the console you might need to move your up or down arrows to see the actual menu entries. The terminal and curses might look a little flaky but it is there. I also set the grub TIMEOUT a little longer to wait at the menu entries.<\/p>\n","protected":false},"excerpt":{"rendered":"

Several articles on using the console feature of KVM guests exists already. This is just a quick note on a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-760","post","type-post","status-publish","format-standard","hentry","category-kvm"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=760"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/760\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}