Delete VMware Distributed Virtual Switch The Resource Is In Use

0

Recently, in working with the home lab environment, moving hosts around, playing around with various networking, etc, I ran into an issue with a distributed virtual switch (DVS) I had configured. The problem started with a host that was forcibly removed from a test cluster. The distributed virtual switch existed on the host, however, was not synchronized with vCenter Server. This is address in the this highlighted VMware KB article. The normal synchronization fix did not work, so I was left with a distributed switch in a bad state on the host even though it was functioning in carrying traffic. In vCenter Server it did see the host had the switch configured but again was in an “out of sync” state. I decided to simply delete the distributed virtual switch from the host since all virtual machines had been evacuated from it. However, I ran into the error with the operation Delete VMware Distributed Virtual Switch The Resource Is In Use.

Delete VMware Distributed Virtual Switch The Resource Is In Use

As mentioned, below is the error that I saw in the vSphere web client when attempting to remove the distributed virtual switch from the ESXi host.

Delete-VMware-distributed-virtual-wwitch-the-resource-is-in-use Delete VMware Distributed Virtual Switch The Resource Is In Use

Delete VMware distributed virtual wwitch the resource is in use

Command line commands to help troubleshoot Distributed Virtual Switches

Since I was in a state of the GUI not helping me much with the distributed virtual switch being out of sync, the command line becomes your friend.  I couldn’t really see what was causing the issue with deleting the virtual switch as all virtual machines had been evacuated.  There were a couple of commands that allowed me to key in on the underlying issue and resolve it.

The command esxcli network vswitch dvs vmware list lists the distributed virtual switches, ports, vmkernel ports, in use status, etc.  Note in the screenshot below that we see a distributed virtual switch port with an In use: true.

Listing-VMware-distributed-virtual-switches-from-command-line Delete VMware Distributed Virtual Switch The Resource Is In Use

Listing VMware distributed virtual switches from command line

The above output shows us that there is an In use resource on the distributed virtual switch.  The client shows to be vmk1.  So we have a vmkernel port that is keeping us from deleting the distributed virtual switch from the host.

How can we delete the distributed virtual switch vmkernel port from the command line?

Using this command I was able to remove the vmkernel port.  In rerunning the command to list the DVS configuration in the environment, the port was no longer in use.  Could I now successfully delete the distributed virtual switch from the host?  Let’s see.  All good now!

Successfully-deleted-the-distributed-virtual-switch-from-an-ESXi-host Delete VMware Distributed Virtual Switch The Resource Is In Use

Successfully deleted the distributed virtual switch from an ESXi host

In this case, knowing how to interact with distributed virtual switches from the commandline is extremely helpful, especially in cases where the relationship or communication is broken with vCenter Server.  A great resource in configuring VMware distributed virtual switches from the command line is this KB article:  https://kb.vmware.com/s/article/1008127

Concluding Thoughts

VMware distributed virtual switches require more care when it comes to vCenter interaction with hosts than do Standard vSwitches.  Since everything is maintained at the vCenter level from a management perspective, the host must be in sync with the vCenter Server to properly administrate the ESXi host.  If not, you will encounter issues as I did when trying to Delete VMware Distributed Virtual Switch The Resource Is In Use.  However, by using the builtin command line utilities and commands, we can successfully troubleshoot many of the issues you can encounter with distributed virtual switches and successfully resolve issues that simply can’t be resolved using the GUI.