Chapter 20. Diagnosing virtual machine problems
When working with virtual machines (VMs), you may encounter problems with varying levels of severity. Some problems may have a quick and easy fix, while for others, you may have to capture VM-related data and logs to report or diagnose the problems.
The following sections provide detailed information about generating logs and diagnosing some common VM problems, as well as about reporting these problems.
20.1. Generating libvirt debug logs Copy linkLink copied to clipboard!
To diagnose virtual machine (VM) problems, it is helpful to generate and review libvirt debug logs. Attaching debug logs is also useful when asking for support to resolve VM-related problems.
20.1.1. Understanding libvirt debug logs Copy linkLink copied to clipboard!
Debug logs are text files that contain data about events that occur during virtual machine (VM) runtime. The logs provide information about fundamental server-side functionalities, such as host libraries and the libvirt daemon. The log files also contain the standard error output (stderr) of all running VMs.
Debug logging is not enabled by default and has to be enabled when libvirt starts.
-
To collect
libvirtdebug logs for your current session, see Enabling libvirt debug logs during runtime. -
To collect
libvirtdebug logs by default, see Enabling libvirt debug logs persistently.
Afterwards, you can attach the logs when requesting support with a VM problem. For details, see Attaching libvirt debug logs to support requests.
20.1.2. Enabling libvirt debug logs persistently Copy linkLink copied to clipboard!
You can configure libvirt debug logging to be automatically enabled whenever libvirt starts. By default, virtqemud is the main libvirt daemon in RHEL 10. To make persistent changes in the libvirt configuration, you must edit the virtqemud.conf file, located in the /etc/libvirt directory.
Procedure
-
Open the
virtqemud.conffile in an editor. Replace or set the filters according to your requirements.
Expand Table 20.1. Debugging filter values 1
logs all messages generated by
libvirt.2
logs all non-debugging information.
3
logs all warning and error messages. This is the default value.
4
logs only error messages.
Example 20.1. Sample daemon settings for logging filters
The following settings:
-
Log all error and warning messages from the
remote,util.json, andrpclayers -
Log only error messages from the
eventlayer. -
Save the filtered logs to
/var/log/libvirt/libvirt.log
log_filters="3:remote 4:event 3:util.json 3:rpc" log_outputs="1:file:/var/log/libvirt/libvirt.log"
log_filters="3:remote 4:event 3:util.json 3:rpc" log_outputs="1:file:/var/log/libvirt/libvirt.log"Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Log all error and warning messages from the
- Save and exit.
Restart the
libvirtdaemon.systemctl restart virtqemud.service
$ systemctl restart virtqemud.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow
20.1.3. Enabling libvirt debug logs during runtime Copy linkLink copied to clipboard!
You can modify the libvirt daemon’s runtime settings to enable debug logs and save them to an output file.
This is useful when restarting the libvirt daemon is not possible because restarting fixes the problem, or because there is another process, such as migration or backup, running at the same time. Modifying runtime settings is also useful if you want to try a command without editing the configuration files or restarting the daemon.
Prerequisites
-
Make sure the
libvirt-adminpackage is installed.
Procedure
Optional: Back up the active set of log filters.
virt-admin -c virtqemud:///system daemon-log-filters >> virt-filters-backup
# virt-admin -c virtqemud:///system daemon-log-filters >> virt-filters-backupCopy to Clipboard Copied! Toggle word wrap Toggle overflow This makes it possible to restore the active set of filter after generating the logs. If you do not restore the filters, the messages continue to be logged, which may affect system performance.
Use the
virt-adminutility to enable debugging and set the filters according to your requirements.Expand Table 20.2. Debugging filter values 1
logs all messages generated by libvirt.
2
logs all non-debugging information.
3
logs all warning and error messages. This is the default value.
4
logs only error messages.
Example 20.2. Sample virt-admin setting for logging filters
The following command:
-
Logs all error and warning messages from the
remote,util.json, andrpclayers -
Logs only error messages from the
eventlayer.
virt-admin -c virtqemud:///system daemon-log-filters "3:remote 4:event 3:util.json 3:rpc"
# virt-admin -c virtqemud:///system daemon-log-filters "3:remote 4:event 3:util.json 3:rpc"Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Logs all error and warning messages from the
Use the
virt-adminutility to save the logs to a specific file or directory.For example, the following command saves the log output to the
libvirt.logfile in the/var/log/libvirt/directory.virt-admin -c virtqemud:///system daemon-log-outputs "1:file:/var/log/libvirt/libvirt.log"
# virt-admin -c virtqemud:///system daemon-log-outputs "1:file:/var/log/libvirt/libvirt.log"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: You can also remove the filters to generate a log file that contains all VM-related information. However, it is not recommended since this file may contain a large amount of redundant information produced by libvirt’s modules.
Use the
virt-adminutility to specify an empty set of filters.virt-admin -c virtqemud:///system daemon-log-filters
# virt-admin -c virtqemud:///system daemon-log-filters Logging filters:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Optional: Restore the filters to their original state by using the backup file that you created previously.
virt-admin -c virtqemud:///system daemon-log-filters "<original-filters>"
# virt-admin -c virtqemud:///system daemon-log-filters "<original-filters>"Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this command, replace
<original-filters>with the content ofvirt-filters-backup.Note that if you do not restore the filters, the messages continue to be logged, which may affect system performance.
20.1.4. Attaching libvirt debug logs to support requests Copy linkLink copied to clipboard!
You may have to request additional support to diagnose and resolve virtual machine (VM) problems. Attaching the debug logs to the support request is highly recommended to ensure that the support team has access to all the information they need to provide a quick resolution of the VM-related problem.
Procedure
- To report a problem and request support, open a support case.
Based on the encountered problems, attach the following logs along with your report:
-
For problems with the
libvirtservice, attach the/var/log/libvirt/libvirt.logfile from the host. For problems with a specific VM, attach its respective log file.
For example, for the testguest1 VM, attach the
testguest1.logfile, which can be found at/var/log/libvirt/qemu/testguest1.log.
-
For problems with the
20.2. Dumping a virtual machine core Copy linkLink copied to clipboard!
To analyze why a virtual machine (VM) crashed or malfunctioned, you can dump the VM core to a file on disk for later analysis and diagnostics.
20.2.1. How virtual machine core dumping works Copy linkLink copied to clipboard!
A virtual machine (VM) requires numerous running processes to work accurately and efficiently. In some cases, a running VM may terminate unexpectedly or malfunction while you are using it. Restarting the VM may cause the data to be reset or lost, which makes it difficult to diagnose the exact problem that caused the VM to crash.
In such cases, you can use the virsh dump utility to save (or dump) the core of a VM to a file before you reboot the VM. The core dump file contains a raw physical memory image of the VM which contains detailed information about the VM. This information can be used to diagnose VM problems, either manually, or by using a tool such as the crash utility.
20.2.2. Creating a virtual machine core dump file Copy linkLink copied to clipboard!
A virtual machine (VM) core dump contains detailed information about the state of a VM at any given time. This information, which is similar to a snapshot of the VM, can help you detect problems if a VM malfunctions or shuts down suddenly.
Prerequisites
- Make sure you have sufficient disk space to save the file. Note that the space occupied by the VM depends on the amount of RAM allocated to the VM.
Procedure
Use the
virsh dumputility.For example, the following command dumps the
test-guest1VM’s cores, its memory and the CPU common register file tosample-core.filein the/core/filedirectory.virsh dump test-guest1 /core/file/sample-core.file --memory-only
# virsh dump test-guest1 /core/file/sample-core.file --memory-only Domain 'test-guest1' dumped to /core/file/sample-core.fileCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The crash utility no longer supports the default file format of the virsh dump command. To analyze a core dump file by using crash, you must create the file with the --memory-only option.
Additionally, you must use the --memory-only option when creating a core dump file to attach to a Red Hat Support Case.
Troubleshooting
If the virsh dump command fails with a System is deadlocked on memory error, ensure you are assigning sufficient memory for the core dump file. To do so, use the following crashkernel option value. Alternatively, do not use crashkernel at all, which assigns core dump memory automatically.
crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M
crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M
20.3. Backtracing virtual machine processes Copy linkLink copied to clipboard!
When a process related to a virtual machine (VM) malfunctions, you can use the gstack command along with the process identifier (PID) to generate an execution stack trace of the malfunctioning process. If the process is a part of a thread group then all the threads are traced as well.
Prerequisites
Ensure that the
GDBpackage is installed.For details about installing
GDBand the available components, see Installing the GNU Debugger.Make sure you know the PID of the processes that you want to backtrace.
You can find the PID by using the
pgrepcommand followed by the name of the process. For example:pgrep libvirt
# pgrep libvirt 22014 22025Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Use the
gstackutility followed by the PID of the process you wish to backtrace.For example, the following command backtraces the
libvirtprocess with the PID 22014.Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information on using
gstack, see thegstackman page on your system.
20.4. Additional resources for reporting virtual machine problems and providing logs Copy linkLink copied to clipboard!
To request additional help and support, you can:
Raise a service request by using the redhat-support-tool command line option, the Red Hat Portal UI, or several methods of FTP.
- To report problems and request support, see Open a Support Case.
Upload the SOS Report and the log files when you submit a service request.
This ensures that the Red Hat support engineer has all the necessary diagnostic information for reference.
- For more information about SOS reports, see the Red Hat Knowledgebase solution What is an SOS Report and how to create one in Red Hat Enterprise Linux?
- For information about attaching log files, see the Red Hat Knowledgebase solution How to provide files to Red Hat Support?