Author : mimartin
Topic Name : Using Swap Files
Publication Name : vSphere Resource Management
Product/Version : VMware vSphere/6.7
Question :
I cannot get ESXi 6.7u2 to honor moving virtual machine swap files. No matter what system setting I use, the swap files stay with the virtual machine. If I edit the virtual machine vmx file, ESXi overwrites my changes even after re-registering the VM. Is this a bug?
This fixed it for me:
https://kb.vmware.com/s/article/1006942#:~:text=Open%20the%20.vmx,close%20the%20file.
for anyone else using a stand-alone ESXi host... This is the first thing that half-worked with ESXi 7.0U3, BUT... I have only found a way to do it on a per-VM basis. I suspect the author of the question (PCPixel) got there in the end, too, but just didn't tell us. Lalegre spells it out in the troubleshooting - I've just bundled it all in one place. I have been unable to find a way (or find anyone else who has found a way) to configure the host itself to have the VMs put their swap files any place other than its own host directory.
I say half-worked, because when the below is completed, it only moves one of the two .vswp files created at power on in each VM's host directory. Half a loaf is better than none! Still trying to prevent ESXi 7.0U3 creating a file with a name like this in the VM's host directory:
/vmfs/volumes/datastore0/vmx-VMNAME-e89b7c4137b860d2a496191ccaf49bcc2f7727d2-1.vswp
Chip in if you have any experience with actually getting this (stand-alone esxi 7.0u3, no vCenter) working as one would expect.
Assumptions:
- you can ssh to the esxi host and that you know how to use vi
- you have a vmfs volume suitable for your needs mounted as [SWAP_DATASTORE_NAME]
- you are using the web-ui interface to the stand-alone esxi host
power-down the VM
This clickpath in the ESXI host's web UI (as of 2023-05-13):
virtual machines --> Rt Click [name of VM] to be modified --> edit settings
VM Options (button) --> Advanced --> scroll down
IN "Swap file location" --> Datastore specified by host (radio button)
Save (button)
Un-register the VM
in the esxi shell (logged on via ssh)
mkdir /vmfs/volumes/[SWAP_DATASTORE_NAME]/[VM_NAME]
Next, edit /vmfs/volumes/VMStorage_DATASTORE_NAME/[VM_HOST_DIR]/vmname.vmx
make sure this line is present (created by editing settings per above screen shot)
sched.swap.hostLocal = "enabled"
remove this line (comment it out):
#sched.swap.derivedName = "/vmfs/volumes/VMStorage_DATASTORE_NAME/VM_NAME/VM_NAME-a8d4e531.vswp"
add this line, making suitable substitutions:
sched.swap.dir = "/vmfs/volumes/[SWAP_DATASTORE_NAME]/[VM_NAME]/"
NB - this is the directory created above, no filename.
- this is a different variable than the one removed by comment, and must be manually typed into the .vmx file.
re-register the VM
-- have confirmed the same behaviour with esxi 6.