Home > ESX, VMware > Suspend a machine and shutdown VMware ESX 4.1 in a hurry

Suspend a machine and shutdown VMware ESX 4.1 in a hurry

Tired of waiting for VMware vSphere Client to connect to your ESX host, perform an inventory just so you can suspend your VM and shutdown your ESX server?

If you haven’t already enabled sshd on your ESX host do so now.

Thomas Maurer has an easy to follow guide with screen shots – Activate SSHd on ESX 4.1.

If you have an older version you’ll need to switch to ALT-F1 and type unsupported then vi /etc/inetd.conf, uncomment sshd, followed by /sbin/services.sh restart (or a reboot).

For more info on how to enable sshd in older versions of ESX check out ESXi (ESX 3i) Enable SSH



ssh into your ESX 4.1 and login as root…

Using the ESX CLI or ESX Command Line Interface or ESX Console to issue the following commands:


# Get a list of all VMS currently on the ESX host
vim-cmd vmsvc/getallvms

# Suspend Virtual Machine 32 (From output of previous command)
vim-cmd vmsvc/power.suspend 32

# Flush disks
sync
sync

# Power off
poweroff


If you are doing this nightly replace 32 in the second command above with the VM id of your machine and copy and paste this all into the ssh window and walk away.

Advertisements
  1. Henrique
    July 28, 2011 at 11:50 am

    Please,

    i just want to shutdown the host.
    i did what you said, and the next day the server was powered off, but the power alimentation was burned… ok, nothing to do with the script, but the job was deleted and back to the original…

    i have 4 vms running…
    2 winserver2008,
    1 freebsd pfsense firewall,
    1 freebsd freenas storage

    i have set jobs in all of them to shutdown at night… and minutes later i want to power of the esxi host…. how do i do it?

    • August 14, 2012 at 2:03 pm

      Henrique,

      Apologies for the long over due reply.

      If you have more than one VM running and you want to suspend them for the evening you need to manually discover what the VM id’s are using the command:

      vim-cmd vmsvc/getallvms

      Then once you have the ID’s (eg: 32,25,8,16) you simply copy and paste the following commands into a SSH session to the ESX:

      vim-cmd vmsvc/power.suspend 32
      vim-cmd vmsvc/power.suspend 25
      vim-cmd vmsvc/power.suspend 8
      vim-cmd vmsvc/power.suspend 16

      Once the above commands are finished you next command that you pasted into the SSH session will execute:

      sync
      poweroff

      Keep a copy of the commands that you typed so that you can paste them into the SSH session tomorrow. This isn’t a script but rather a *manual* way to copy and paste multiple commands and walk away.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: