close

http://www.youtube.com/watch?v=RmSB2s1lWvg&feature=player_embedded

遇過 VM 無法關機或停止的狀況嗎? 當透過 GUI 畫面無法動作時,就必須用 command line 來將 VM power off。 以下是在 COS 下的幾個 command,供您參考:

1. vmware-cmd -l:秀出此 host 上的每個 VM 路徑名稱,找出關不掉的 VM vmx 路徑。

2. vmware-cmd getstate:向 ESX host 探詢 VM 目前狀態,記得這只是 ESX 自認為的 VM 狀態。

3. vmware-cmd stop:請 ESX 將 VM power off。

4. 再用 getstate 探詢,若仍為 on,則使用 stop hard。

5. 如果 stop hard 後,VM 還是一直在運作的話,那麼最後的辦法就是 kill process。 但此舉可能會造成 ESX 或 VM 產生不可預期的狀況,有潛在的危險性。VMware 建議如果不想這麼做,可以找 support。( 請參閱之前的文章 : http://vlife.pixnet.net/blog/post/31582502 ) 以上為 ESX host 的使用方式,

如果是 ESXi 的話,請參閱

http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&externalId=1014165

Powering off a virtual machine on an ESXi host

Symptoms

You are experiencing these issues:

  • You cannot power off an ESXi hosted virtual machine.
  • A virtual machine is not responsive and cannot be stopped or killed. 

Purpose

This article describes how to correctly stop virtual machines in an ESXi environment.
 
Note: This article applies to ESXi only and does not apply to ESX. For ESX hosts, see Powering off a virtual machine (1004340).

Resolution

Warning: Follow the sections and steps in this article in order. Do not skip a section or step, as each step may have an impact on the virtual machine.
 
Powering off the virtual machine
 
Attempt to power off the virtual machine:
  1. Connect VMware Infrastructure (VI) Client to VMware VirtualCenter Server.
  2. Right-click on the virtual machine and click Power off.
  3. Connect VI Client directly to the ESXi host.
  4. Right-click on the virtual machine and click Power off.

If this does not work, you will need to install the Remote Command-Line Interface (RCLI) or vMA tools.

Installing the Remote Command-Line Interface tool

The Remote Command-Line Interface (RCLI) is used for the parts of this article. Ensure that it is installed before you proceed.

For ESXi 3.5 hosts, see Remote CLI Installation and Execution in the Remote Command-Line Interface Installation and Reference Guide.

For ESXi 4.0 hosts, see vSphere CLI Installation, Execution, and Command Overviews in the vSphere Command-Line Interface Installation and Reference Guide.
 
 
Note: The Remote Command-Line Interface can be accessed via the vMA tool for ESXi 4.0. If it is your preference to use this tool, see Installing vMA and Running Commands from vMA in the vSphere Command-Line Interface Installation and Reference Guide.
 
Determining the virtual machine's state
 
Note: Before proceeding, refer to the RCLI manual for your specific version. The commands used in this section are explained in greater detail in Remote Command-Line Interface Installation and Reference Guide (for ESXi 3.5 hosts), vSphere Command-Line Interface Installation and Reference Guide (for ESXi 4.0 hosts), and vSphere Command-Line Interface Installation and Scripting Guide (for ESXi 4.1 hosts)
 
Determine the host on which the virtual machine is running. This information is available in the virtual machine's Summary tab in VI Client.

Using the ESXi command line tool to power off the virtual machine

This procedure uses additional ESXi command line tools. Attempt each process before proceeding to the next, as they are listed in order of potential impact to the system if performed incorrectly.

  1. On the ESXi console, enter Tech Support mode and log in as root. For more information, see Tech Support mode for Emergency Support (1003677) or Using Tech Support Mode in ESXi 4.1 (1017910)
  2. Get the World_ID with the command:

    # vm-support -x

  3. Kill the virtual machine by using the following command in the home directory of the virtual machine.
    • For ESXi 3.x, run the command:

      # vm-support -X <World_ID> -f –w <dir>

      where

      -f allows you to force vm-support to use a VMFS working directory.
      -w sets the working directory used for the output files. This is the directory where vm-support saves its final .tar archive. If this option is not specified, the working directory will be the directory from which vm-support is run.

    • For ESXi 4.x:

      # vm-support -X <World_ID> –w <dir>

      Note: If the vm-support command is slow with the -X switch, add -d0 to speed up the process.

Using alternate ESXi command line methods to power off the virtual machine

  1. On the ESXi console, enter Tech Support mode and log in as root. For more information, see Tech Support mode for Emergency Support (1003677).
  2. To list all running virtual machines and their corresponding VMIDs, run the command:

    vim-cmd vmsvc/getallvms
  3. Power off the virtual machine using the VMID found in Step 2 and run:

    vim-cmd vmsvc/power.off <vm id> for ESXi 3.5 and 4.0
    vim-cmd vmsvc/power.off <vmid> for ESXi 4.1

Using the ESXi command line method to kill the virtual machine

If the virtual machine does not power off using the steps in this article, it has likely lost control of its process. You need to manually kill the process at the command line.
 
Caution: This procedure is potentially hazardous to the ESXi host. If you do not identify the appropriate process id (PID), and kill the wrong process, it may have unanticipated results. If you are not comfortable with the following procedure, contact VMware Technical Support and open a Service Request. Please refer to this article when you create the SR.
  1. To determine if the virtual machine process is running on the ESXi host, run the command:

    # ps | grep vmx

    On an ESXi 3.x host, if the .vmx process is running, the output appears similar to:

    ps|grep vmx
    7662 7662 vmx                        /bin/vmx
    7667 7662 vmx                        /bin/vmx
    7668 7662 mks:VMtoKill               /bin/vmx
    7669 7662 vcpu-0:VMtoKill            /bin/vmx


    On an ESXi 4.0 host, if the .vmx process is running, the output appears similar to:

    ps |grep vmx
    7662 7662 vmx                        /bin/vmx
    7663 7662 mks :VMtoKill              /bin/vmx
    7664 7662 vcpu-0:VMtoKill            /bin/vmx


    The parent process ID (PID) for this process is in bold. In this example, the PID is 7662. Several rows are returned, but you must make sure you identify the parent process. The first column contains the PID, and the second contains the parent's PID. Ensure you terminate only the parent process. Take note of this number for use in the following steps.

    Caution: Ensure that you identify the line specific only to the virtual machine you are attempting to repair. If you continue this process for another virtual machine the one in question, you can cause downtime for the other virtual machine.

  2. If the .vmx process is listed, it is possible that the process has runaway and must be stopped manually. To kill the process, run the command:

    # kill <PID>

  3. Wait 30 seconds and check for the process again.
  4. If it is not terminated, run the command:

    # kill -9 <PID>

  5. Wait 30 seconds and check for the process again.
  6. If it is not terminated, the ESXi host must be rebooted to clear the process. This is a last resort option, and should be attempted only if the preceding steps in this article are unsuccessful.
In ESX/ESXi 4.1, you can use the k switch in esxtop to kill a virtual machine. This method is quicker than vm-support -X, but be aware that it does not generate a support bundle.
  1. Run esxtop.
  2. Press c to switch to the CPU resource utilization screen.
  3. Press f to add the column for the world ID. 
  4. Press k and type in that ID.
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 sisley0921 的頭像
    sisley0921

    天丫

    sisley0921 發表在 痞客邦 留言(0) 人氣()