13 Jan 2020 - by 'Maurits van der Schee'
In a previous post I have installed KVM (on Ubuntu 18.04) from the CLI on my Dell R720xd. In this post I will show how to adjust the GRUB config to enable the serial console in KVM and how to access it on the KVM CLI. This is great for fixing SSH connectivity issues and to do easy LUKS password entry during boot. In this post we will also explore how to allow access to the grub menu from the serial console.
In order for the "
console" command of "
virsh" to work you need to modify the guest's grub config.
In the guest run the following command:
sudo nano /etc/default/grub
Look for the line:
and replace it with the following, or add this line if absent (on CentOS):
On CentOS remove "
rhgb quiet" from the line "
GRUB_CMDLINE_LINUX" to ensure messages are shown.
On Ubunutu this is only effective after running "
On CentOS you need to use the "
grub2-mkconfig" command to update the grub config:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
This should write the grub config to disk.
To test that it works, we reboot the machine using:
After rebooting the VM you can connect to the console using "
virsh" by running:
virsh console maurits-cloud
Make sure to disconnect any graphical client (virt-manager) if you see this error message:
error: operation failed: Active console session exists for this domain
Console access is very good for emergency SSH connectivity fixes and LUKS password entry.
You can also enable access to the grub menu using the console, but I feel this is not really necessary. The grub menu is already accessible from the VNC console. But if you do want this, then you should have the following entries in your "
/etc/default/grub" file (change or add them):
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
Again apply and reboot with:
You should now see the grub menu when you access the console using the "
virsh console" command after pressing the escape (Esc) key during the countdown.
In the next post I will walk you through setting up static IP addresses and hostnames for your KVM virtual machines. Hostnames allow you to connect to machines using their name instead of their (DHCP assigned) IP address. Static IP addresses are a requirement for doing port forwarding, a topic we will touch in another post in this blog series.