Stale Distributed Virtual Switch (DVS) entries/remains on ESXi host might occur in below circumstances:
ESXi host 7.x
ESXi host 8.x
Steps to validate and remove stale DVS from ESXi host:
1. Check whether any uplinks are still associated with the DVS:
In below screenshot there are two uplinks (vmnic0 and vmni1) are associated with the DVS:
You can also check the associated uplinks with the DVS using below command.
Note down the DVPort ID associated with the respective Uplinks and "In Use" status:
# esxcfg-vswitch -l
2. Make sure that the DVS and its associated port groups are not in use by any of the VMs or ESXi host itself.
3. Put ESXi host into Maintenance Mode (Making sure that the all hosted VMs are either in powered-off state or migrated out of the ESXi host)
4. If DVS uplinks are part of DVS LAG, please refer this KB article for more details: Removing a NIC from a vDS LAG
5. Remove the DVS uplinks using below command:
# esxcfg-vswitch -Q vmnic# -V <DVPortID> <DVS_Name> (replace DVPortID with the actual ID number and then enter the name of the distributed switch at the end of the command)
e.g.
Confirm whether Uplinks are removed from DVS:
# esxcfg-vswitch -l
6. Once the uplinks will be removed , you can proceed deleting the DVS using below commands:
i. Backup the DVS DB : # cp /etc/vmware/dvsdata.db <Destination_Directory_on_ESXi_Host>
ii. Delete the DVS: # net-dvs -d <DVS Name>
iii. After DVS deletion, if you encounter any Error e.g. "Listing failed for DVSwitch: DvsPortset-X, Error: Unable to get ..." , delete stale DVS portsets using below command:
# vsish -e set /net/portsets/<DvsPortset-#>/destroy destroy
iv. Delete the VDS database file (/etc/vmware/dvsdata.db ), else DVS will be re-created upon the next reboot:
# rm -f /etc/vmware/dvsdata.db
7. Reboot the ESXi host and post reboot the DVS will be completely removed from ESXi host
Reference KB: