Execute ESXCLI commands during ESXi startup

Share this:

You may face the situation where you need to run custom commands/scripts while ESXi boot. Although it is not so common situation, as most of the settings done in ESXi are persistent during the reboot, there are some cases.

For this purpose there is a file called /etc/rc.local.d/local.sh and you can read more about modifying it in KB2043564.

If you wonder my reason for this, was to increase QLogic network card receive ring size. All of this because of Packet Receive Errors, reported by ESXi, more precisely because of Receive FIFO errors.

By the way, you can figure out more details about Packet Receive Errors by looking at output of the following command:

esxcli network nic stats get -n vmnic0

To configure rx ring size in the ESXi 6.0  and older, you had to use ethtool which is not persistent during the reboot, with command:

ethtool -G vmnic0 rx 4078

So to have your changes persistent across the reboots you have to modify your local.sh, which for 4 NIC server would look like this:

#!/bin/sh

# local configuration options

# Note: modify at your own risk! If you do/use anything in this
# script that is not part of a stable API (relying on files to be in
# specific places, specific tools, specific output, etc) there is a
# possibility you will end up with a broken system after patching or
# upgrading. Changes are not supported unless under direction of
# VMware support.

ethtool -G vmnic0 rx 4078
ethtool -G vmnic1 rx 4078
ethtool -G vmnic2 rx 4078
ethtool -G vmnic3 rx 4078

exit 0

In the ESXi 6.5 and later you cannot use ethtool anymore, but you can configure ring size by using ESXCLI with command:

esxcli network nic ring current set -n vmnic0 -r 4078

You would assume, you just need to replace the commands in the local.sh, however there is an issue.

ESXCLI commands do not work with /etc/rc.local.d/local.sh

I have contacted VMware support and they advised me to use LOCALCLI instead of ESXCLI

Apparently to have esxcli commands working, you have to have hostd running. However this is not the case during local.sh execution, localcli bypass hostd.

Therefore to have /etc/rc.local.d/local.sh working with ESXCLI commands you have to use localcli instead. The same syntax applies.

So the working script looks like this:

#!/bin/sh

# local configuration options

# Note: modify at your own risk! If you do/use anything in this
# script that is not part of a stable API (relying on files to be in
# specific places, specific tools, specific output, etc) there is a
# possibility you will end up with a broken system after patching or
# upgrading. Changes are not supported unless under direction of
# VMware support.

# Note: This script will not be run when UEFI secure boot is enabled.
localcli network nic ring current set -n vmnic0 -r 4078
localcli network nic ring current set -n vmnic1 -r 4078
localcli network nic ring current set -n vmnic2 -r 4078
localcli network nic ring current set -n vmnic3 -r 4078

exit 0

 

 

The following two tabs change content below.
With over 12 years of experience in the Virtualization field, currently working as a Senior Consultant for Evoila, contracted to VMware PSO, helping customers with Telco Cloud Platform bundle. Previous roles include VMware Architect for Public Cloud services at Etisalat and Senior Architect for the VMware platform at the largest retail bank in Slovakia. Background in closely related technologies includes server operating systems, networking, and storage. A former member of the VMware Center of Excellence at IBM and co-author of several Redpapers. The main scope of work involves designing and optimizing the performance of business-critical virtualized solutions on vSphere, including, but not limited to, Oracle WebLogic, MSSQL, and others. Holding several industry-leading IT certifications such as VCAP-DCD, VCAP-DCA, VCAP-NV, and MCITP. Honored with #vExpert2015-2019 awards by VMware for contributions to the community. Opinions are my own!

About Dusan Tekeljak

With over 12 years of experience in the Virtualization field, currently working as a Senior Consultant for Evoila, contracted to VMware PSO, helping customers with Telco Cloud Platform bundle. Previous roles include VMware Architect for Public Cloud services at Etisalat and Senior Architect for the VMware platform at the largest retail bank in Slovakia. Background in closely related technologies includes server operating systems, networking, and storage. A former member of the VMware Center of Excellence at IBM and co-author of several Redpapers. The main scope of work involves designing and optimizing the performance of business-critical virtualized solutions on vSphere, including, but not limited to, Oracle WebLogic, MSSQL, and others. Holding several industry-leading IT certifications such as VCAP-DCD, VCAP-DCA, VCAP-NV, and MCITP. Honored with #vExpert2015-2019 awards by VMware for contributions to the community. Opinions are my own!
Bookmark the permalink.

3 Comments

  1. This approach will not work when Secure UEFI is enabled. Is there some other way to achieve this?

  2. Hi Dusan,

    Have you test the feature in the ESX8.0?

  3. ring size setting using esxcli is now persistent, for NSX EDP you need to use nsxdp-cli. if you are asking about local.sh, then this will not work with Secure Boot and no other supported method out there.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.