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.
Enable the console in GRUB
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:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
and replace it with the following, or add this line if absent (on CentOS):
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"
On CentOS remove «rhgb quiet
» from the line «GRUB_CMDLINE_LINUX
» to ensure messages are shown.
On Ubunutu this is only effective after running «update-grub
» using:
sudo update-grub
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.
Connect to the console
To test that it works, we reboot the machine using:
sudo reboot
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.
Grub menu via the console
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_TIMEOUT=10
GRUB_TIMEOUT_STYLE=countdown
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"
Again apply and reboot with:
sudo update-grub
sudo reboot
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.
Next: Assigning a static IP address in KVM
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.
Click here to read the next article (on static ip addresses in KVM).
PS: Liked this article? Please share it
on Facebook,
Twitter
or LinkedIn.
virsh console YOUR_MACHINE
Connect the virtual serial console for the guest
Syntax:
virsh console YOUR_VM_NAME [devname] [--safe] [--force]
- Man page: https://www.libvirt.org/manpages/virsh.html#console
Contents
- 1 Connection examples
- 2 Enable serial console
- 3 Configure KVM server
- 4 Quit console
- 5 Kill old console
- 6 Related
- 7 See also
Connection examples[edit]
Connecting using VM name:
virsh console MACHINE_NAME Connected to domain MACHINE_NAME Escape character is ^] error: operation failed: Active console session exists for this domain
Connecting using VM id. You can obtain it with virsh list
virsh console 3
Error when no argument is provided:
virsh console error: command 'console' requires <domain> option
Enable serial console[edit]
You need to enable serial console in your VM machine.[1]
1) Enable serial console on VM_MACHINE:
sudo systemctl enable --now serial-getty@ttyS0.service
2) Connect to VM:
virsh console MACHINE
Configure KVM server[edit]
virsh edit VM_NAME
<serial type='pty'> <source path='/dev/pts/0'/> <target type='isa-serial' port='0'> <model name='isa-serial'/> </target> <alias name='serial0'/> </serial> <console type='pty' tty='/dev/pts/0'> <source path='/dev/pts/0'/> <target type='serial' port='0'/> <alias name='serial0'/> </console>
Ref: https://ravada.readthedocs.io/en/latest/docs/config_console.html
Quit console[edit]
Use CTRL + 5
to exit the console.[2]
Kill old console[edit]
ps -ef | grep console kill -9 {PID}
[edit]
virsh ttyconsole
virsh list
virsh start
virsh --connect
virsh domdisplay VM_NAME
virsh vncdisplay VM_NAME
/var/log/libvirt/qemu/
virsh edit
- Console
- virt-manager
See also[edit]
- Conneting:
virsh [ console | ttyconsole | domdisplay | vncdisplay
],virsh --connect
,virt-manager
,virt-viewer
, VNC virsh
: Storage information, Connecting, Operations, Memory, Snapshots, Networking, CPU, release notes,virsh nodedev-list
Description of problem: I performed a default install of Fedora-20-Beta-TC1 tree using the DVD ISO and virt-manager wizard. System boots fine using the graphical console. As per the test case: https://fedoraproject.org/wiki/QA:Testcase_Virt_Serial_Console The serial console doesn't work at all: In VM details I can see a serial device has already been added. Trying View -> Text Consoles -> Serial 1 doens't give me a login prompt (GUI shows login prompt at the same time). Trying virsh console $guest yields: # virsh console fedora20-2 Connected to domain fedora20-2 Escape character is ^] error: operation failed: Active console session exists for this domain ^^^ No matter if I have switched in virt-manager back to the GUI or text console or if I close entirely the VM window which shows this guest system. Version-Release number of selected component (if applicable): libvirt-client-1.1.3-2.fc20.x86_64 virt-manager-0.10.0-4.git79196cdf.fc20.noarch How reproducible: always Steps to Reproduce: 1. See test case above. 2. 3. Actual results: Expected results: Additional info: This could be 2 different issues, I don't know yet.
Duping this to your qemu-ga bug, since they are likely the same root issue *** This bug has been marked as a duplicate of bug 1016613 ***
I have some additional information regarding the guest serial console: If I manually add the Console Device via "Add Hardware" option (Device Type: Pseudo TTY (pty), Type: virtio), I get a working console in virt-manager, e.g. I can see the login prompt an log in. However, executing 'virsh console fedora20' still doesn't work. I get the following output: Connected to domain fedora20 Escape character is ^] and I can't proceed, e.g. typing something in doesn't produce anything. |