How To
Summary
The serial console is sometimes the unique method left you have handy to gain access to a shell attached to a terminal emulation program ready to be used to troubleshoot a system having issues.
It has proved to be an effective tool to assist you in tracking and spotting boot time events preventing the OS to boot and to gain access to the installed OS when the usual connectivity media via standard network interfaces are buggy or the network subsystem is broken. This is specially important in headless systems where not even a locally attached terminal is available.
Configuring a serial console has always been a tricky issue, and with the advent of the pervasive virtual data centers, doing it for isolated and standalone KVM guests injects an additional step of complexity.
We will cover in this article how to do it for a kvm guest running an instance of SLES 15 OS system and show you a way to use it for boot time troubleshooting purposes.
Objective
Environment
Steps
[root@casld002 ~]# virsh -c qemu:///system dumpxml sles-15.1-efi-srv01 | grep -A 2 -E '\<console '
[root@casld002 ~]#
sles-151-efi-srv01:~ # dmesg | grep -E 'tty'
[ 0.004000] console [tty0] enabled
sles-151-efi-srv01:~ #
If your guest is in a situation like the one depicted above then you have to edit its xml configuration and add the needed serial device controllers.
Note: In fact you can use the --config option of the virsh attach-device command, but the kernel won't detect the new devices until you reboot the guest.
[root@casld002 ~]# cat /root/serial.xml
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
[root@casld002 ~]#
[root@casld002 ~]# virsh -c qemu:///system attach-device sles-15.1-efi-srv01 --file /root/serial.xml --config
Device attached successfully
[root@casld002 ~]#
[root@casld002 ~]# virsh -c qemu:///system dumpxml sles-15.1-efi-srv01 | grep -A 2 -E '\<console '
<console type='pty'>
<target type='serial' port='0'/>
</console>
[root@casld002 ~]#
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
And that is all concerning our guest being able to support serial consoles.
Now we are ready to boot the guest and check again if the kernel manages to detect the serial devices and map the needed ports.
[root@casld002 ~]# virsh -c qemu:///system start sles-15.1-efi-srv01
Domain sles-15.1-efi-srv01 started
[root@casld002 ~]#
sles-151-efi-srv01:~ # dmesg | grep -E 'tty'
[ 0.004000] console [tty0] enabled
[ 3.562166] 00:03: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
sles-151-efi-srv01:~ #
If you look carefully the definition of the the hardware system while the guest is running you will see now that the guest has been assigned a serial port and a device file for a software terminal to attach to:
[root@casld002 ~]# virsh -c qemu:///system list
Id Name State
----------------------------------------
1 ubuntu-16.4-dns01 running
2 fedora-gw running
3 centOS-7.2-iscsitarget running
4 ubunser-14.4-ldap1srv running
5 ubunser-14.4-nfssrv running
8 srv01-sles12sp3 running
11 sles-15.1-efi-srv01 running
[root@casld002 ~]#
[root@casld002 ~]# virsh -c qemu:///system dumpxml 11 | grep -A 11 -E '<serial'
<serial type='pty'>
<source path='/dev/pts/7'/>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/7'>
<source path='/dev/pts/7'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
[root@casld002 ~]#
sles-151-efi-srv01:~ # setserial -g /dev/ttyS[0123]
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: unknown, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3
sles-151-efi-srv01:~ #
sles-151-efi-srv01:~ # ls -l /dev/ttyS0
crw-rw---- 1 root dialout 4, 64 Jun 4 19:00 /dev/ttyS0
sles-151-efi-srv01:~ #
Note: Consider getting a backup of the files before modifying them.
a) Add/modify the following variables in /etc/default/grub configuration file:
GRUB_CMDLINE_LINUX_DEFAULT="splash=silent resume=/dev/disk/by-path/pci-0000:04:00.0-part4 mitigations=auto quiet"
GRUB_CMDLINE_LINUX_DEFAULT="splash=silent resume=/dev/disk/by-path/pci-0000:04:00.0-part4 mitigations=auto quiet console=tty0 console=ttyS0,115200n8"
GRUB_TERMINAL="gfxterm"
GRUB_TERMINAL="gfxterm console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
# grub2-mkconfig -o /boot/grub2/grub.cfg
sles-151-efi-srv01:~ # diff /boot/grub2/grub.cfg.20200608 /boot/grub2/grub.cfg
76a77
> serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
96c97,98
< terminal_output gfxterm
---
> terminal_input gfxterm console serial
> terminal_output gfxterm console serial
148c150
< linuxefi /boot/vmlinuz-4.12.14-197.7-default root=UUID=923d921d-0b7d-4cde-863f-c180d07ba58c ${extra_cmdline} splash=silent resume=/dev/disk/by-path/pci-0000:04:00.0-part4 mitigations=auto quiet
---
> linuxefi /boot/vmlinuz-4.12.14-197.7-default root=UUID=923d921d-0b7d-4cde-863f-c180d07ba58c ${extra_cmdline} resume=/dev/disk/by-path/pci-0000:04:00.0-part4 mitigations=auto console=tty0 console=ttyS0,115200n8
165c167
< linuxefi /boot/vmlinuz-4.12.14-197.7-default root=UUID=923d921d-0b7d-4cde-863f-c180d07ba58c ${extra_cmdline} splash=silent resume=/dev/disk/by-path/pci-0000:04:00.0-part4 mitigations=auto quiet
---
> linuxefi /boot/vmlinuz-4.12.14-197.7-default root=UUID=923d921d-0b7d-4cde-863f-c180d07ba58c ${extra_cmdline} resume=/dev/disk/by-path/pci-0000:04:00.0-part4 mitigations=auto console=tty0 console=ttyS0,115200n8
197c199
< linuxefi /boot/vmlinuz-4.12.14-195-default root=UUID=923d921d-0b7d-4cde-863f-c180d07ba58c ${extra_cmdline} splash=silent resume=/dev/disk/by-path/pci-0000:04:00.0-part4 mitigations=auto quiet
---
> linuxefi /boot/vmlinuz-4.12.14-195-default root=UUID=923d921d-0b7d-4cde-863f-c180d07ba58c ${extra_cmdline} resume=/dev/disk/by-path/pci-0000:04:00.0-part4 mitigations=auto console=tty0 console=ttyS0,115200n8
sles-151-efi-srv01:~ #
[root@casld002 ~]# virsh -c qemu:///system list
Id Name State
----------------------------------------
2 fedora-gw running
3 centOS-7.2-iscsitarget running
4 ubuntu-16.4-dns01 running
5 ubunser-14.4-nfssrv running
8 ubunser-14.4-ldap1srv running
10 srv01-opensuse151 running
11 sles-15.1-efi-srv01 running
[root@casld002 ~]#
[root@casld002 ~]# virsh -c qemu:///system ttyconsole sles-15.1-efi-srv01
/dev/pts/7
[root@casld002 ~]#
[root@casld002 ~]# virsh -c qemu:///system console sles-15.1-efi-srv01
Connected to domain sles-15.1-efi-srv01
Escape character is ^]
sles-151-efi-srv01 login: jesus
Password:
Last login: Mon Jun 8 14:41:18 from 192.168.100.1
jesus@sles-151-efi-srv01:~>
[root@casld002 ~]# screen /dev/pts/7 115200
[ OK ] Started Load AppArmor profiles.
[ TIME ] Timed out waiting for device dev-di…ackages\x2dx86_64\x2dBuild.device.
[DEPEND] Dependency failed for /media/sles15sp1-pack.
[DEPEND] Dependency failed for Local File Systems.
[DEPEND] Dependency failed for Early Kernel Boot Messages.
Starting Restore /run/initramfs on shutdown...
[ OK ] Reached target User and Group Name Lookups.
[ OK ] Reached target Timers.
[ OK ] Closed Syslog Socket.
[ OK ] Reached target Network (Pre).
[ OK ] Reached target Host and Network Name Lookups.
[ OK ] Reached target System Time Synchronized.
[ OK ] Reached target Remote File Systems.
[ OK ] Reached target Login Prompts.
[ OK ] Reached target Network.
[ OK ] Reached target Network is Online.
[ OK ] Reached target Sockets.
[ OK ] Reached target Paths.
Starting Tell Plymouth To Write Out Runtime Data...
Starting Create Volatile Files and Directories...
[ OK ] Started Emergency Shell.
[ OK ] Reached target Emergency Mode.
[ OK ] Started Restore /run/initramfs on shutdown.
[ OK ] Started Create Volatile Files and Directories.
Starting Security Auditing Service...
[ OK ] Started Tell Plymouth To Write Out Runtime Data.
[ OK ] Started Security Auditing Service.
Starting Update UTMP about System Boot/Shutdown...
[ OK ] Started Update UTMP about System Boot/Shutdown.
Starting Update UTMP about System Runlevel Changes...
[ OK ] Started Update UTMP about System Runlevel Changes.
You are in emergency mode. After logging in, type "journalctl -xb" to view
system logs, "systemctl reboot" to reboot, "systemctl default" or ^D to boot
into default mode.
Give root password for maintenance
(or press Control-D to continue):
[root@casld002 ~]# virsh -c qemu:///system console sles-15.1-efi-srv01 | tee -a /tmp/sles-151-srv01.console.out
[root@casld002 ~]# ls -lrt /tmp/sles-151-srv01.console.*
-rw-r--r--. 1 root root 268010 Jun 8 18:55 /tmp/sles-151-srv01.console.20200608-18411591634467.out
[root@casld002 ~]#
Additional Information
Document Location
Worldwide
Was this topic helpful?
Document Information
Modified date:
01 April 2021
UID
ibm16218944