If an ESXi host was connected to a Distributed Virtual Switch (DVS) and you were not able to properly remove it from the vCenter inventory, which cleans up the VDS as part of the removal, then you will be left with a stale VDS configuration.
Of course, the ideal workflow is to clean this up within vCenter Server but if you some how lost access or the vCenter Server was deleted and you might be wondering how to manually clean this up?
Step 0 - Ensure that no VMs or VMKernel interfaces are using the DVS and Distributed Portgroups (DVPG) resources. Re-create the vSphere Standard Switch (VSS) and the respective portgroups and reconfigure your VMs and VMKernel interfaces before continuing. If you need assistance, please search online as there are many resources that outlines these steps and this will no be covered in this article.
Note: In theory, after Step 0 you could technically jump to Step 5 and just delete the VDS database but I prefer to clean up resources prior to that step but this also works if you are in a pinch.
Step 1 - Run the following command to list current VDS and associated uplink ports that are configured. In the example below, I have a VDS named foo with a single uplink vmnic1 which is consuming port 9. Your environment may be configured differently, so please make a note of these values as you will need it in the next steps.
esxcfg-vswitch -l
Step 2 - Remove the uplink from VDS by running the following command and specifying the uplink, uplink port and VDS name.
esxcfg-vswitch --del-dvp-uplink=vmnic1 --dvp=9 foo
Step 3 - Delete VDS by runnning the following command and specifying VDS name.
net-dvs -d foo
Once the VDS has been deleted, what I have found (at least with the cswitch in ESXi 7.0 Update 3), is that a tangling DvsPortset-N is left when you run the following command:
esxcfg-vswitch -l
Step 4 - Depending on the number of DvsPortset-N, you will need to run this additional command and replace the N with value observed from previous step.
vsish -e set /net/portsets/DvsPortset-0/destroy destroy
Note: If this command returns busy, it means there were still workloads or VMkernel interfaces using VDS that was not cleaned up as part of Step 0. You can ignore and move to next step
Step 5 - Next, we delete the VDS database file which is needed or else VDS will be re-created upon the next reboot.
rm -f /etc/vmware/dvsdata.db
Step 6 - Finally, reboot the ESXi host and the VDS should now be completely removed.
Michael says
Thanks for the great post. It was really helpful.
Andy Machado says
As of VCenter 8.0u3, it appears that once you've removed all uplinks to an unused DSwitch, Vcenter cleans up all associated unused Dswitches and port groups.
Essentially, we only needed to remove the uplinks from the DSwitch and use the VCenter GUI to add the removed uplinks to the new VCenter DSwitch.
HISSOUROU M says
Thank you !
Enrique L. says
Thank you.
Very helpful info.
Got me out of a jam!
Mark Edwards says
Hey William. I hit this issue today on my homelab, running ESXi 8.0.2 however the path to /net/portsets doesn't exist on this build.
Running find . -type d | grep -i "portsets" from root returns no hits, so where does it store this data on this version?
I worked around it by removing dvsdata.db and rebooting, this cleared it from the UI, but not sure if its left anything behind on the host! Just thought i'd pass this on for reference. Keep up the great work 🙂