ESX/ESXi で rc.local または sh.local ファイルを変更して、起動中にコマンドを実行する
search cancel

ESX/ESXi で rc.local または sh.local ファイルを変更して、起動中にコマンドを実行する

book

Article ID: 319883

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

この記事には、rc.local または local.sh ファイルを変更して起動プロセス中に ESX/ESXi でコマンドを実行する方法が記載されています。このプロセスは、使用している ESX/ESXi のバージョンによって異なります。

Symptoms:
免責事項:これは英文の記事「Modifying the rc.local or local.sh file in ESX/ESXi to execute commands while booting (2043564)」の日本語訳です。記事はベストエフォートで翻訳を進めているため、ローカライズ化コンテンツは最新情報ではない可能性があります。最新情報は英語版の記事で参照してください。

Resolution

ESX/ESXi の起動処理中にコマンドを実行するには、rc.local または local.sh 構成ファイルを変更します。

:VMware では、これらのファイルを変更しないことをお勧めしています。これらのファイルは、特殊な使用状況シナリオ下か、VMware テクニカル サポートによる指示があった場合にのみ変更するようにしてください。ほとんどの ESX/ESXi 構成オプションおよびドライバ パラメータは再起動しても維持され、他の方法を使用して設定します。詳細については、Configuring advanced options for ESX/ESXi (1038578) および Configuring advanced driver module parameters in ESX/ESXi (1017588) を参照してください。

ESXi 5.1/5.5/6.x

ESXi 5.1 の起動処理中にコマンドを実行するには、/etc/rc.local.d/ ディレクトリにある local.sh ファイルを変更します。
 
local.sh ファイルを変更するには:
  1. Vi エディタを使用して local.sh ファイルを開きます。詳細については、「Editing configuration files in VMware ESXi and ESX (1017022)」を参照してください。
  2. 実行するコマンドを exit 0 行の上に追加します。例:

    #!/bin/sh

    #!/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.

    ethtool --pause vmnic0 autoneg off
    exit 0
この例では、フロー制御の自動ネゴシエーションを無効にするための ethtool コマンドを exit 0 行の上に追加しています。

  • exit 0 行の後に追加されたコマンドは、実行されません。
  • 追加のコマンドは、exit 0 の前に追加できます。
  • コマンドは一覧表示された順に実行されます。
  • 通常、local.sh ファイルの権限を変更する必要はありません。ESXi 5.1 では、デフォルトで、ルート ユーザーがこのファイルに対する読み取りおよび書き込みの権限を持っています。
  • UEFI セキュアブートが有効である場合は、スクリプトは実行されません。

ESXi 4.x/5.0

:このセクションの情報は ESXi のみに適用され、ESX には適用されません。
 
ESXi 4.x および 5.0 の起動処理中にコマンドを実行するには、/etc/ ディレクトリにある rc.local ファイルを変更します。
 
rc.local ファイルを変更するには:
  1. Vi エディタを使用して rc.local ファイルを開きます。詳細については、「Editing configuration files in VMware ESXi and ESX (1017022)」を参照してください。
  2. 実行するコマンドをファイルの最後に追加します。例:

    #!/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

    この例では、フロー制御の自動ネゴシエーションを無効にするための ethtool コマンドを、ファイルの最後に新しい行として追加しています。

  3. 追加のコマンドは、ファイル内に個別の行として追加します。
  4. コマンドは、リストに記載されている順序で実行されます。
  5. 行の先頭に # 文字を付けると、コマンドが無効になります。
  6. 通常、/etc/rc.local ファイルの権限を変更する必要はありません。ESXi 4.x および 5.0 では、デフォルトで、ルート ユーザーがこのファイルに対する読み取りおよび書き込みの権限を持っています。

ESX 3.x/4.x

ESX 3.x/4.x の起動処理中にコマンドを実行するには、/etc/rc.d/ ディレクトリにある rc.local ファイルを変更します。
 
rc.local ファイルを変更するには:
  1. Vi エディタを使用して rc.local ファイルを開きます。詳細については、「Editing configuration files in VMware ESXi and ESX (1017022)」を参照してください。
  2. 実行するコマンドをファイルの最後に追加します。例:

    #!/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


    この例では、フロー制御の自動ネゴシエーションを無効にするための ethtool コマンドを、ファイルの最後に新しい行として追加しています。

  • 追加のコマンドは、ファイル内に個別の行として追加します。
  • コマンドは、リストに記載されている順序で実行されます。
  • 行の先頭に # 文字を付けると、コマンドが無効になります。
  • 通常、/etc/rc.d/rc.local ファイルの権限を変更する必要はありません。ESX では、デフォルトで、ルート ユーザーがこのファイルに対する読み取りおよび書き込みの権限を持っています。このファイルの操作中に権限エラーが発生する場合は、実行可能ファイルにして、次のコマンドを使用して権限を修正します。

    # chmod 755 rc.local


Additional Information