Search the VMware Knowledge Base (KB)
View by Article ID

Modifying the rc.local or local.sh file in ESX/ESXi to execute commands while booting (2043564)

  • 4 Ratings
Language Editions

Purpose

This article provides information on how to modify the rc.local or local.sh files to execute commands in ESX/ESXi during the boot process. This process differs depending on the version of ESX/ESXi used.

Resolution

To execute a command during the ESX/ESXi boot process, either the rc.local or local.sh configuration file is modified.

Note: VMware recommends you to not modify these files. Ensure to modify these files only under special use case scenarios or if directed by VMware Technical Support. Most ESX/ESXi configuration options and driver parameters persist across reboots and are set using other methods. For more information, see Configuring advanced options for ESX/ESXi (1038578) and Configuring advanced driver module parameters in ESX/ESXi (1017588).

ESXi 5.1/5.5/6.x

To execute a command during the ESXi 5.1 boot process, modify the local.sh file located at the /etc/rc.local.d/ directory.
 
To modify the local.sh file:
  1. Open the local.sh file using the vi editor. For more information, see Editing configuration files in VMware ESXi and ESX (1017022).
  2. Add the command to be executed above the line exit 0. For example:

    #!/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 --pause vmnic0 autoneg off
    exit 0
In this example, the ethtool command to disable flow control, auto-negotiation is added above the exit 0 line.

Notes:
  • Commands added after the exit 0 line are not executed.
  • You can add additional commands before exit 0.
  • The commands are executed in the order listed.
  • Usually, it is not necessary to modify the permissions of the local.sh file. In ESXi 5.1, by default, the root user has read and write permissions on this file.

ESXi 4.x/5.0

Note: The information in this section applies only to ESXi, and not to ESX.
 
To execute a command during the ESXi 4.x and 5.0 boot process, modify the rc.local file located at the /etc/ directory.
 
To modify the rc.local file:
  1. Open the rc.local file using the vi editor. For more information, see Editing configuration files in VMware ESXi and ESX (1017022).
  2. Add the commands to be executed at the end of the file. For example:

    #!/bin/sh

    export PATH=/sbin:/bin

    log() {
       echo "${1}"
       /bin/busybox logger init "${1}"
    }

    # execute all service retgistered in ${rcdir} ($1 or /etc/rc.local.d)
    if [ -d "${1:-/etc/rc.local.d}" ] ; then
       for filename in $(find "${1:-/etc/rc.local.d}" | /bin/busybox sort) ; do
          if [ -f "${filename}" ] && [ -x "${filename}" ]; then
             log "running ${filename}"
             "${filename}"
          fi
       done
    fi

    # disables flow control auto-negotiation for vmnic0

    ethtool --pause vmnic0 autoneg off


    In this example, the ethtool command to disable flow control, auto-negotiation is added at the end of the file, on a new line.

    Notes:
    • Additional commands are added on separate lines within the file.
    • The commands are executed in the order listed.
    • Commands are disabled using the # characters at the beginning of the line.
    • Usually, it is not necessary to modify the permissions of the /etc/rc.local file. In ESXi 4.x and 5.0, by default, the root user has read and write permissions on this file.

ESX 3.x/4.x

To execute a command during the ESX 3.x/4.x boot process, modify the rc.local file located at the /etc/rc.d/ directory.
 
To modify the rc.local file:
  1. Open the rc.local file using the vi editor. For more information, see Editing configuration files in VMware ESXi and ESX (1017022).
  2. Add the commands to be executed at the end of the file. For example:

    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.

    touch /var/lock/subsys/local

    # Disable flow control auto-negotiation for vmnic0

    ethtool --pause vmnic0 autoneg off

    In this example, the ethtool command to disable flow control, auto-negotiation is added at the end of the file, on a new line.

    Notes:
  • Additional commands are added on separate lines within the file.
  • The commands are executed in the order listed.
  • Commands are disabled using the # characters at the beginning of the line.
  • Usually, it is not necessary to modify the permissions of the /etc/rc.d/rc.local file. In ESX, by default, the root user has read and write permissions on this file. If you receive a permissions error when working with this file, make the file executable and correct the permissions using this command:

    # chmod 755 rc.local

See Also

Request a Product Feature

To request a new product feature or to provide feedback on a VMware product, please visit the Request a Product Feature page.

Feedback

  • 4 Ratings

Did this article help you?
This article resolved my issue.
This article did not resolve my issue.
This article helped but additional information was required to resolve my issue.

What can we do to improve this information? (4000 or fewer characters)




Please enter the Captcha code before clicking Submit.
  • 4 Ratings
Actions
KB: