Storing a virtual machine swap file in a location other than the default in ESX/ESXi
search cancel

Storing a virtual machine swap file in a location other than the default in ESX/ESXi

book

Article ID: 308567

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This articles provides steps to change the default location of your virtual machines swap files.

Symptoms:

 



Environment

VMware ESX 4.0.x
VMware vSphere ESXi 6.0
VMware vSphere ESXi 6.7
VMware ESX 4.1.x
VMware vSphere ESXi 6.5
VMware ESXi 4.1.x Installable
VMware ESX Server 3.0.x
VMware vSphere ESXi 5.0
VMware ESXi 4.1.x Embedded
VMware ESX Server 3.5.x
VMware vSphere ESXi 5.1
VMware ESXi 4.0.x Installable
VMware ESXi 4.0.x Embedded

Resolution

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.html
Note: 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.html

Note: 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:
  1. Connect directly to your host or to your vCenter Server using the VMware Infrastructure/vSphere Client.
  2. Click the Configuration tab for the ESXi/ESX host.
  3. Click Virtual Machine Swapfile Location and click Edit.
  4. Specify the datastore where you want to store the virtual machine swap files.
  5. To complete the action the virtual machine will need to be powered off, then powered on.
  6. Ensure the swap file is located on the specified host datastore.
To change the swap file location for a single virtual machine:
  1. Power off the virtual machine.
  2. Unregister the virtual machine. Right-click the virtual machine in the Inventory and choose Remove from Inventory.
  3. Connect to the host:
     
  4. Change directory to the folder where the virtual machine resides:

    cd /vmfs/volumes/datastore_name/virtual_machine_folder/
     
  5. Edit the virtual machine's configuration file with a text editor.
  6. Add this line:

    sched.swap.dir = /vmfs/volumes/datastore_name/dir_name
     
  7. 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:
  1. Connect to vCenter Server or directly to your ESX host using the vSphere Client.
  2. Select either a virtual machine or a virtual machine template that you want to modify.
  3. Stop the virtual machine, if it is running.
  4. Connect to the ESX console using SSH or a service console connection.
  5. 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.
     
  6. Open the configuration file in a text editor and add this line:

    sched.swap.dir= "/vmfs/volumes/volume_name/dir_name"
     
  7. Delete this line:

    sched.swap.derivedName = xxx
     
  8. To complete the action the virtual machine will need to be powered off, then powered on.
  9. Ensure the swap file is located on the specified host datastore.
  10. Repeat for each existing virtual machine, as required.


Additional Information

Virtual machine swap file location affects vMotion compatibility in different ways, depending on the version of ESXi running on the virtual machine's host. You can configure ESX/ESXi 3.5 or later hosts to store virtual machine swap files along with the virtual machine configuration file or on a local swap file datastore specified for that host. The impact of the location of the virtual machine swap file on vMotion compatibility includes these:
  • For migrations between hosts running ESX/ESXi version 3.5 and later, vMotion and migrations of suspended and powered-off virtual machines are allowed.
  • During a migration with vMotion, if the swap file location specified on the destination host differs from the swap file location specified on the source host, the swap file is copied to the new location. This may result in slower migrations with vMotion. If the destination host cannot access the specified swap file location, it stores the swap file with the virtual machine configuration file.
For additional information about editing the configuration file of a virtual machine, see Tips for editing a .vmx file (1714).

For translated versions of this article, see:
Tech Support Mode for Emergency Support
How to register/add a VM to the Inventory in vCenter Server
Using Tech Support Mode in ESXi 4.1, ESXi 5.x, and ESXi 6.x
Connecting to an ESX host using an SSH client
Tips for editing a .vmx file
Migrating virtual machine swap (.vswp) files from one datastore to another
Como armazenar arquivo de permuta de uma máquina virtual em local diferente do padrão
Almacenamiento del archivo swap de una máquina virtual en una ubicación distinta a la predeterminada
ESX/ESXi のデフォルト以外の場所に仮想マシン スワップ ファイルを保存する
将虚拟机交换文件存储在除默认位置以外的位置