Moving the swap file to an alternate datastore is a useful troubleshooting step if the virtual machine or guest operating system is experiencing failures, including STOP errors, read-only file systems, and severe performance degradation issues during periods of high I/O. However, identifying and resolving the underlying overcommit or storage performance issues is still recommended to ensure environment stability.
This can also be used to store the virtual machine swap files in an alternate non-replicated datastore when using LUN snapshot technologies to ensure that you are storing the swap files in a location that is not being replicated.
ESXi/ESX 3.5, 4.x, and ESXi 5.x
Note: For ESXi 6.0 please see:
https://docs.vmware.com/en/VMware-vSphere/6.0/com.vmware.vsphere.vm_admin.doc/GUID-D888BE08-187B-4FF2-9918-7EC27D0EC376.html Note: For ESXi 6.5 please see:
https://docs.vmware.com/en/VMware-vSphere/6.5/com.vmware.vsphere.vm_admin.doc/GUID-D888BE08-187B-4FF2-9918-7EC27D0EC376.htmlNote: For ESXi 6.7 please see:
https://docs.vmware.com/en/VMware-vSphere/6.7/com.vmware.vsphere.vm_admin.doc/GUID-D888BE08-187B-4FF2-9918-7EC27D0EC376.htmlNote: If your hosts are part of an HA Cluster, you must change the cluster settings for virtual machine swap file location prior to executing the steps below. For more information, see the
Change the Swap File Location section in the
Virtual Machine Admin Guide for your version.
To edit the virtual machine swap file location in ESXi/ESX 3.5, 4.x, and ESXi 5.x:
- Connect directly to your host or to your vCenter Server using the VMware Infrastructure/vSphere Client.
- Click the Configuration tab for the ESXi/ESX host.
- Click Virtual Machine Swapfile Location and click Edit.
- Specify the datastore where you want to store the virtual machine swap files.
- To complete the action the virtual machine will need to be powered off, then powered on.
- Ensure the swap file is located on the specified host datastore.
To change the swap file location for a single virtual machine:
- Power off the virtual machine.
- Unregister the virtual machine. Right-click the virtual machine in the Inventory and choose Remove from Inventory.
- Connect to the host:
- Change directory to the folder where the virtual machine resides:
cd /vmfs/volumes/datastore_name/virtual_machine_folder/
- Edit the virtual machine's configuration file with a text editor.
- Add this line:
sched.swap.dir = /vmfs/volumes/
datastore_name/dir_name
- Register the virtual machine again. For more information, see Registering or adding a virtual machine to the inventory on vCenter Server or on an ESXi/ESX host (1006160).
ESX 3.0
Add this line to your virtual machine's configuration (
.vmx
) file to store the swap on a VMFS-3 volume:
sched.swap.dir= "/vmfs/volumes/volume_name/dir_name"
Where
volume_name
is the name of a VMFS-3 volume.
To change the swap file location:
- Connect to vCenter Server or directly to your ESX host using the vSphere Client.
- Select either a virtual machine or a virtual machine template that you want to modify.
- Stop the virtual machine, if it is running.
- Connect to the ESX console using SSH or a service console connection.
- Change directory to the path of the
.vmx
file you want to edit.
Note: Use the vmware-cmd -l
command to find the path to the configuration file. For more information on the vmware-cmd
command, see the VMware Scripting API.
- Open the configuration file in a text editor and add this line:
sched.swap.dir= "/vmfs/volumes/volume_name/dir_name"
- Delete this line:
sched.swap.derivedName = xxx
- To complete the action the virtual machine will need to be powered off, then powered on.
- Ensure the swap file is located on the specified host datastore.
- Repeat for each existing virtual machine, as required.