A short post to bookmark some CLI commands for putting a VMware ESXi host into a maintenance mode. In my lab, I'm running vCenter in a VM, and this VM runs out of a small local datastore. So I can't simply vMotion this VM elsewhere to do a maintenance and patch using VMware Update Manager (VUM).
When the host where that VM runs, needs to be put into maintenance mode, one needs the CLI. That's why this post. But while here I'll add some more commands which are useful for rebooting, or checking up the VMs that runs on the host etc… which might be useful too.
ESXi maintenance mode is mode when it's possible to install patches and updates or plan for a hardware upgrade such as adding more RAM or more internal hard drives. You might also need to service your host to install new firmware to your storage controller, to your motherboard etc. So the use cases for using a maintenance mode are numerous.
The host is in a state of Entering Maintenance Mode until all running virtual machines are suspended or migrated. When a host is entering maintenance mode, you cannot power on virtual machines on it or migrate virtual machines to it.
Whether you patching standalone ESXi host or if you're using VMware Update manager for patching, in both cases you must put a host into maintenance mode. In case you're using VUM the host is placed into maintenance mode automatically.
If you have VMs running on the host, you must migrate them or shut them down. You cannot leave VM running and put a host into a maintenance mode as the system will wait until all running VMs are shut down or are migrated elsewhere.
How to put a host into maintenance mode?
To enter maintenance mode using the command line interface, use this command:
esxcli system maintenanceMode set –enable true
To exit maintenance mode use this command:
esxcli system maintenanceMode set –enable false
Alternatively, there is another command to enter and to exit maintenance mode:
To enter maintenance mode:
vim-cmd /hostsvc/maintenance_mode_enter
To exit maintenance mode:
vimsh -n -e /hostsvc/maintenance_mode_exit
To check if the host is in maintenance mode:
Use one of these commands:
vim-cmd /hostsvc/hostsummary | grep inMaintenanceMode
OR
vimsh -n -e /hostsvc/hostsummary | grep inMaintenanceMode
While here, some quick commands how to reboot, halt or shutdown:
reboot -f
halt
shutdown
Through the vMA (vSphere Management Appliance):
From the vMA command prompt, you can also enter maintenance mode.
vicfg-hostops -o enter –server 10.10.5.10
To exit maintenance mode from vMA enter the following.
vicfg-hostops -o exit –server 10.10.5.10
You can also shutdown or reboot ESXi hosts command from vMA.
vicfg-hostops -o shutdown –server 10.10.5.10
vicfg-hostops -o reboot –server 10.10.5.10
Find out which VMs are running on ESXi host:
esxcli vm process list
Check out also my post on How-to power off unresponsive VM through the CLI.
Links:
ESXi/ESX 4.x and ESXi 5.x shutdown and reboot commands
Wrap Up:
Maintenance mode is a special state where the system assures that no VMs are running so the patching/upgrade of the host is possible. After the host has entered the Maintenance mode, no VMs can be deployed or powered-on on the host.
When no more running virtual machines are on the host, the host’s icon changes to include under maintenance and the host’s Summary panel indicates the new state. Host can exit the maintenance mode automatically after the patching process has finished and rebooted the host only if managed via vSphere Update Manager (VUM). If it is an individual host, no automatic maintenance mode exists.
VMware Update Manager is now part of VMware vCenter Server Appliance (VCSA). Windows-based vCenter needs a separate DB and separate software component. VMware is phasing out the Windows vCenter. The latest news was that the next release of VMware vSphere will be the last release where the Windows vCenter server will be part of the vSphere suite.
More from ESX Virtualization:
- What is VMware Orchestrated Restart?
- How To Reset ESXi Root Password via Microsoft AD
- How to Install latest ESXi VMware Patch – [Guide]
- How to reset ESXi 6.x root password and under which conditions
- What is VMware Instant Clone Technology?
Stay tuned through RSS, and social media channels (Twitter, FB, YouTube)
Rickard Nobel says
If I remember correctly the vicfg-hostops command does not really work well since it (for some reason) does not support DRS and your VMs in a cluster will not be vMotion transferred.
sravana says
how do we check how long the Host is in maintmode. is there any command or any way to find out
Theron says
What about cancelling an “Enter Maintenance mode” task? In a large environment that is currently set to show all uses tasks, they scroll off very quickly. This one cannot be found now in the web client. I see task vim.Task:haTask-ha-host-vim.host.ServiceSystem.start-15432485 but that one isn’t immediately obvious that it is an Enter Maint task (probably is).
But I want to be certain before cancelling it. Is the number show the task id?
terence chang says
The esxcli commands are missing an extra dash before ‘enable’. It should be:
esxcli system maintenanceMode set –-enable true
Vladan SEGET says
Yeah, I know. It’s my WP messing it up. Originally they were there. Sorry about that.