// Module included in the following assemblies:
//
// virt/support/virt-collecting-virt-data.adoc

:_mod-docs-content-type: PROCEDURE
[id="virt-generating-a-vm-memory-dump_{context}"]
= Generating a VM memory dump

[role="_abstract"]
When a virtual machine (VM) terminates unexpectedly, you can use the `virtctl memory-dump` to generate a memory dump command to output a VM memory dump and save it on a persistent volume claim (PVC). Afterwards, you can analyze the memory dump to diagnose and troubleshoot issues on the VM.

// You can specify an existing PVC or use the `--create-claim` flag to create a new PVC.

.Procedure

. Optional: You have an existing PVC on which you want to save the memory dump.
** The PVC volume mode must be `FileSystem`.
** The PVC must be large enough to contain the memory dump.
+
The formula for calculating the PVC size is `(VMMemorySize + 100Mi) * (1 + FileSystemOverhead)`, where `100Mi` is the memory dump overhead, and `FileSystemOverhead` is defined in the `HCO` object.

. Create a memory dump of the required VM:

** If you have an existing PVC selected on which you want to save the memory dump:
+
[source,terminal]
----
$ virtctl memory-dump get <vm_name> --claim-name=<pvc_name>
----

** If you want to create a new PVC for the memory dump:
+
[source,terminal]
----
$ virtctl memory-dump get <vm_name> --claim-name=<new_pvc_name> --create-claim
----

. Download the memory dump:
+
[source,terminal]
----
$ virtctl memory-dump download <vm_name> --output=<output_file>
----

. Attach the memory dump to a Red Hat Support case.
+
Alternatively, you can inspect the memory dump, for example by using the volatility3 tool.

. Optional: Remove the memory dump:
+
[source,terminal]
----
$ virtctl memory-dump remove <vm_name>
----
