There maybe certain use cases where you need to execute a command or series of commands during the boot up of an ESX(i) host and historically administrators have added commands to the /etc/rc.local which is one of the last scripts to be executed in the boot up process. However, with ESXi 5.1, the location of the file has changed from /etc/rc.local to /etc/rc.local.d/local.sh.
VMware also provides a KB2043564 that describes the locations for the various version of ESX(i):
- In ESX 3.x/4.x - You would add the command(s) to /etc/rc.d/rc.local
- In ESXi 4.x/5.0 - You would add the command(s) to /etc/rc.local
- In ESXi 5.1 - It has changed to /etc/rc.local.d/local.sh
Disclaimer: As mentioned in the VMware KB, though this is supported, it is still not recommended that you edit these files unless directed by VMware support or under special scenarios.
A question that came up recently was about automatically loading the "multiextent" VMkernel module (which is required if you wish to use the 2gbsparse VMDK format, you can find more details in this blog article here) during the boot up of an ESXi 5.1 host as this had to be done manually, even if you had enabled the module. To do so, you just need to edit the /etc/rc.local.d/local.sh and add the following command above the "exit 0".
localcli system module load -m multiextent
Note: The reason I used localcli versus ESXCLI is that hostd may not be completely ready and hence the command may fail during the boot up process. One can also loop and wait for ESXCLI to be ready, but this is another way of performing the operation.
Jason Logan says
I edited the /etc/rc.local.d/local.sh, I then did a cat on the file and it looked good. It did NOT last after a reboot. The file went back to default.
What file should I append the cron addition to to make it stick after a reboot?
William Lam says
The file is automatically backed up by ESXi every 1hr, but if you reboot before then it may not have ran. You can manually back it up by running /sbin/auto-backup.sh
Ronald Buder says
As I asked already on Twitter a few days ago, any idea as to why this has been changed? Will anything of the likes of /etc/rc.local.d/*.sh be treated as local start up scripts? Is it just someone's personal preference?
I just checked Linux FHS, its not mentioned there as far as I can tell.
Cheers Ronald (@Str0hhut)
William Lam says
I don't. My guess is that /etc/rc.local contained some default set of commands and instead of trying to support that which could cause issue, it was decided to introduce a specific file for these custom "boot commands". Also editing /etc/rc.local did not persist in the past, so introducing this new file and making it persist may have been the better option.
Rickard Nobel says
Interesting article as always. I would have really thought this would be unsupported by VMware, but seems to be "just" unrecommended.