I was recently doing some maintenance and upgrades on some of the hosts in my lab environment when I had the need to enter maintenance mode and reboot my hosts from the command line. I have used esxcli a bit, which is handy if you’re going for your VCAP-DCA exam, but I’d not rebooted a host from command line. Fortunately it was easy to find out how to do it, and it’s well documented. I thought I’d let you know where to find it, and what the commands are, just in case you ever need to know.
Firstly, to put a host into maintenance mode there are two options. ESXCLI, which I was familiar with, or vicfg-hostops, which I’ve only just discovered.
To enter and exit maintenance mode:
esxcli <conn_options> system maintenancemode set –enable true, where <conn_options> are the connection options such as –server=<servername>
To exit maintenance mode
esxcli <conn_options> system maintenancemode set –enable false
In addition to the above using vicfg-hostops you can issue the following
vicfg-hostops <conn_options> –operation enter or –operation exit to enter or exit maintenance mode.
All of the above is documented in the official VMware vSphere CLI Documentation – Entering and Exiting Maintenance Mode.
To reboot a host:
To reboot a host from the command line we would use the vicfg-hostops –operation reboot command, to force a reboot you could add the –force option, similarly to shutdown a host you use –operation shutdown, which can also be used with the –force option.
This is also nicely documented in the official VMware vSphere CLI Documentation – Stopping, Rebooting, and Examining Hosts.
Final Word
The VMware CLI options have come a long way over the years and you can really quickly and easily automate a lot of tasks using esxcli, PowerCLI and the other command line tools. I would encourage all of you to check them out. They are covered in the blueprint for the VCAP-DCA exam, so if you wanted to achieve the advanced level administration certification from VMware you should learn how to use these tools, and how much easier they could make your job if you’re a vSphere Admin.
—
This post appeared on the Long White Virtual Clouds blog at longwhiteclouds.com, by Michael Webster +. Copyright © 2013 – IT Solutions 2000 Ltd and Michael Webster +. All rights reserved. Not to be reproduced for commercial purposes without written permission.
I believe "vim-cmd hostsvc/maintenance_mode_enter" and "vim-cmd hostsvc/maintenance_mode_exit" still work just fine. Matter of factly I have used them to upgrade a 5.1 to 5.5 using the CLI. As for the reboot, "dcui" will also allow you to reboot the box.
DCUI and GUI work just fine. That really wasn\’t the point. Doing it programmatically from either vCLI, vMA or through SSH. VIM-CMD is deprecated as far as I know so I wouldn\’t want to rely on it going forward.
Or issue a plain "reboot" right there at the prompt. No apparent reason why this should not be done, when in maintenance mode…or even when not to simulate an unexpected shutdown/reboot…
If SSH is disabled, the host is in lockdown mode, and your trying to do this programmatically the reboot command isn\’t an option.
More annoyingly, “maintenancemode” has to be “maintenanceMode” or the dummy is spat. Not very consistent.
Enter maintenance mode – esxcli system maintenanceMode set -e on
Exit maintenance mode – esxcli system maintenanceMode set -e off
Status – esxcli system maintenanceMode get
“vicfg-hostops –operation reboot” doesn’t work in 5.5, just logged in via ssh and tried it. nothing worse then a post without validity… now if there is something else you left out then again, nothing worse than a post without all the details…
how to put ESXi 5.0 in maintenance mode through CMD…
Very useful post!
You can also shutdown all host VMs using two ESXi integrated scripts:
/sbin/shutdown.sh && /sbin/poweroff
Source: http://www.sysadmit.com/2016/07/vmware-esxi-apagar-todas-las-vms-desde-SSH.html