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.
Dusan has over 8 years experience in the Virtualization field. Currently working as Senior VMware plarform Architect at one of the biggest retail bank in Slovakia. He has background in closely related technologies including server operating systems, networking and storage. Used to be a member of VMware Center of Excellence at IBM, co-author of several Redpapers. His main scope of work consists from designing and performance optimization of business critical virtualized solutions on vSphere, including, but not limited to Oracle WebLogic, MSSQL and others. He holds several IT industry leading certifications like VCAP-DCD, VCAP-DCA, MCITP and the others. Honored with #vExpert2015-2018 awards by VMware for his contribution to the community. Opinions are my own!

About Dusan Tekeljak

Dusan has over 8 years experience in the Virtualization field. Currently working as Senior VMware plarform Architect at one of the biggest retail bank in Slovakia. He has background in closely related technologies including server operating systems, networking and storage. Used to be a member of VMware Center of Excellence at IBM, co-author of several Redpapers. His main scope of work consists from designing and performance optimization of business critical virtualized solutions on vSphere, including, but not limited to Oracle WebLogic, MSSQL and others. He holds several IT industry leading certifications like VCAP-DCD, VCAP-DCA, MCITP and the others. Honored with #vExpert2015-2018 awards by VMware for his contribution to the community. Opinions are my own!
Bookmark the permalink.

2 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?

Leave a Reply

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