3

When I added Debian 8 to my KVM management tool, I found that I could not access the console unless I added console=ttyS0 to the grub boot configuration. It wasn't great but it worked. I am in the process of adding Ubuntu 16.04 to the management tool, and this time when the guest is installed it has the same problem, but I can no longer see the grub menu options when I reboot the instance whilst connected to the console. Therefore, I cannot implement the workaround.

I managed to find the IP address of the guest instance by running arp -an on the hypervisor and connecting to the IPs on the KVM bridge until I found the right one. This allowed me to confirm that the guest was installed and running correctly. I would like to be able to connect to the console using sudo virsh console [guest ID] in case something goes wrong with the networking or if openssh suddenly decides to stop working. What do I need to do to be able to connect to the guest ubuntu 16.04 console from the hypervisor?

My gut feeling is that I should just need to tweak the configuration settings which are accessed by sudo virsh edit [guestID]. At the moment I have:

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

Extra Info

  • Ubuntu 14.04 KVM hypervisor using kernel 4.2.0-36-generic
  • Virsh 1.2.2
  • if you are allocating an IP to the VM by DHCP, see my find-vm-ip-by-name.sh script in unix.stackexchange.com/a/239170/7696. Even better would be to allocate a static IP by MAC address to the VM in the dhcpd (or dnsmasq) config, and then add a matching entry to your DNS (or /etc/hosts file). – cas Jun 8 '16 at 11:03
  • That's useful, but users will need to ensure that they install the openssh-server package during installation, otherwise that and my solution below will not be able to help them. – Programster Jun 8 '16 at 11:12
  • To me, it's an absolute given that a VM can, should, and WILL have sshd installed. Even if it only has a private address on a local bridge...it just never occurred to me that sshd wouldn't be installed. BTW, if there's no network or sshd, and no serial console, virt-manager can give access to the console. The VM may be configured for VNC access (use virsh dumpxml and search for graphics type='vnc' to check). – cas Jun 8 '16 at 11:25
  • BTW, if you're building ubuntu 16.04 VMs by preseed, add ssh packages to your preseed.cfg (e.g. with d-i pkgsel/include string ssh). Or if users are cloning an existing VM image, make sure it has ssh installed first. – cas Jun 8 '16 at 11:30
  • I've made sure that the default kickstart script that my tool uses will automatically install openssh-server, but I'm thinking about the users who decide to manually step through the installation. – Programster Jun 8 '16 at 15:05
7

Update 13th March 2017

For those already in the situation described above, you can fix your existing guest using the original answer below. However, for those of you who would rather never have to go through this pain again, you can just add the following so the %post section of your kickstart file:

%post --nochroot
(
    sed -i "s;quiet;quiet console=ttyS0;" /target/etc/default/grub
    sed -i "s;quiet;quiet console=ttyS0;g" /target/boot/grub/grub.cfg
) 1> /target/root/post_install.log 2>&1
%end

This will ensure that the necessary changes to grub are made as described below, so that new guests you deploy through using the kickstart file won't suffer from this problem.

Original Answer

For those who manage to connect via SSH after finding out the IP using arp -an on the host, you can perform the following steps (taken from the bottom of this page) once you are connected to the guest.

Edit the grub configuration file:

sudo vim /etc/default/grub

Add the text console=ttyS0 to the GRUB_CMDLINE_LINUX_DEFAULT parameter as shown below:

enter image description here

Then have the grub menu be rebuilt using your change by executing:

sudo update-grub

Now you should be able to connect to a working console with virsh console [guest ID].

This will keep working as future kernels are added to the system, but I would much rather have a solution that didn't require me to have SSH access to the guest in the first place.

7

Thanks @Programster solution works for me. Since I do not even have SSH access, I have to install and use virt-edit.

sudo apt install libguestfs-tools
sudo virt-edit -d myVM /boot/grub/grub.cfg

Replace all instances of quiet with quiet console=ttyS0 in the grub.cfg file and start my VM for console connect.

virsh start myVM && virsh console myVM

Do not forget to edit and update grub per @programster answer after login.

  • This just saved me a world of pain after upgrading to 18.04. It's just a shame that installing libguestfs-tools requires pulling down a lot of packages. – Programster May 3 '18 at 14:17
0

Fix the grub configuration in a post installation step as suggested in @Programster's excellent answer. Here is how to do it in some other situations.

When installing Ubuntu 16.04 using a Debconf preseed file, add this to your preseed file:

d-i preseed/late_command string ( \
    sed -i "s;quiet;quiet console=ttyS0;" /target/etc/default/grub;    \
    sed -i "s;quiet;quiet console=ttyS0;g" /target/boot/grub/grub.cfg \
) 1> /target/root/post_install.log 2>&1

When installing RHEL 7 or CentOS 7 using Kickstart, add this to your kickstart file:

%post --nochroot --log /mnt/sysimage/root/post.log
(
    sed -i "s;quiet;quiet console=ttyS0;"  /mnt/sysimage/etc/default/grub
    sed -i "s;quiet;quiet console=ttyS0;g" /mnt/sysimage/boot/grub2/grub.cfg
) > /mnt/sysimage/root/post_install.log 2>&1
%end
0

A simpler and easier method as per the redhat docs

grubby --update-kernel=ALL --args="console=ttyS0"
reboot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.