Error: "Cannot remove datastore '<datastore-name>' because local swap is enabled on it. Correct the problem and retry the operation"
search cancel

Error: "Cannot remove datastore '<datastore-name>' because local swap is enabled on it. Correct the problem and retry the operation"

book

Article ID: 368771

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

  • After deleting a datastore, it keeps re-appearing in vCenter and ESXi.
  • Unable to remove inaccessible datastore
  • vCenter - /var/log/vmware/vpxd/vpxd.log
    YYYY-MM-DDTHH:MM:SS.###-04:00 error vpxd[1125272] [Originator@6876 sub=Default opID=lqe8ol1y-4779833-auto-2ug57-h5:70930374-d6] [VpxLRO] -- ERROR task-487284 -- 520050f9-8cfd-7ea2-7838-6db429f708e5(5281582f-cc9b-123c-9d77-e8c5af859616) -
    - datastoreSystem-93 -- vim.host.DatastoreSystem.removeDatastore: :vim.fault.ResourceInUse
    --> Result:
    --> (vim.fault.ResourceInUse) {
    -->    faultCause = (vmodl.MethodFault) null,
    -->    faultMessage = (vmodl.LocalizableMessage) [
    -->       (vmodl.LocalizableMessage) {
    -->          key = "com.vmware.vim.datastore.error.removeDatastoreFailed",
    -->          arg = (vmodl.KeyAnyValue) [
    -->             (vmodl.KeyAnyValue) {
    -->                key = "name",
    -->                value = ",<datastore-name>"
    -->             },
    -->             (vmodl.KeyAnyValue) {
    -->                key = "reason",
    -->                value = "localSwapEnabled"
    -->             }
    -->          ],
    -->          message = "Cannot remove datastore '<datastore-name>' because local swap is enabled on it. Correct the problem and retry the operation."
    -->       }
    -->    ],
    -->    type = <unset>,
    -->    name = "<datastore-name>"
    -->    msg = "Received SOAP response fault from [<<io_obj p:0x00007efcb00bd3d8, h:54, <UNIX ''>, <UNIX '/var/run/envoy-hgw/hgw-pipe'>>, /hgw/host-##/vpxa>]: removeDatastore
    --> Received SOAP response fault from [<<io_obj p:0x00000052286eaf48, h:64, <TCP '127.0.0.1 : 45913'>, <TCP '127.0.0.1 : 8307'>>, /sdk>]: removeDatastore
    --> The resource '<datastore-name>' is in use."
    --> }
    --> Args:
    -->
    --> Arg datastore:
    --> 'vim.Datastore:109d621d-bbfe-4104-ba5d-0068b70a6ee2:datastore-######'

Cause

This is caused by the datastore being in use for VM swap files.

Typically, ESXi hosts automatically use datastores for swap files for VMs. However, if the storage was forcibly removed - e.g. for NFS, if it was not put into maintenance mode, unmounted, then deleted to allow files to be moved - some VMs may still reference the stale datastore on the hosts.

Resolution

  1. Place the host in maintenance mode.
  2. Set the swap location to another datastore.
  3. Reboot the host.
  4. Attempt to delete datastore from the vCenter or ESXi UI.