Skip to content

Instantly share code, notes, and snippets.

@tlhakhan
Created June 8, 2021 23:05
Show Gist options
  • Save tlhakhan/5c5cdc7c2bbb134e1985e00f992c4c97 to your computer and use it in GitHub Desktop.
Save tlhakhan/5c5cdc7c2bbb134e1985e00f992c4c97 to your computer and use it in GitHub Desktop.
Append to the /etc/rc.local.d/local.sh script to wait for vusb#s to initialize and then refresh the ESXi host networking to properly register uplinks to vSwitches.
#
# Description: Wait for 3 vusb interfaces to intialize and then refresh the ESXi host network settings.
# Original reference: https://flings.vmware.com/usb-network-native-driver-for-esxi#instructions
#
# Get status of 3 vusb interfaces to be "Up Up Up", see the use of 3 in head -n3 and xargs -n3.
vusb_status=$(esxcli network nic list | grep vusb | awk '{print $5}' | sort | head -n3 | xargs -n3)
# Loop until all 3 vusb interfaces are Up
# Waits a maximum of 20 * 10 seconds before falling through.
# If vusbs initialize sooner, then this loop exits faster.
count=0
while [[ $count -lt 20 && "${vusb_status}" != "Up Up Up" ]]
do
sleep 10
count=$(( $count + 1 ))
vusb_status=$(esxcli network nic list | grep vusb | awk '{print $5}' | sort | head -n3 | xargs -n3)
done
# A debug of variable $vusb_status stored in /var/log/vusb_status
echo "$vusb_status" > /var/log/vusb_status
# Refresh ESXi host networking
esxcfg-vswitch -R
vim-cmd internalsvc/refresh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment