13.4. Managing Virtual Machines from the Command LineSome actions on your virtual machines need to be performed from the Service Console. To give you an example, one time the authors had a virtual machine get stuck during a power-up operation in Virtual Center and we couldn't power it down from the Virtual Center client or the ESX Server MUI. So, we had to perform a hard power off from the command line to stop the VM. To manage virtual machines from the Service Console, use the vmware-cmd command. There are also scripts available to perform actions like backing up and restoring virtual disk files. In this section, we'll cover the following:
13.4.1. Using vmware-cmd to Manage Virtual MachinesThe vmware-cmd command allows you to perform many different tasks related to virtual machines. Figure 13.33 shows the server operations that can be performed on the Service Console using vmware-cmd. As you can see from the list, you can register and unregister virtual machines and get/set resource variables. Figure 13-33. A List of Server Operations that Can Be Performed with vmware-cmdFigure 13.34 shows the VM operations that can be performed from the Service Console using the vmware-cmd utility. Figure 13-34. A List of VM Operations that Can Be Performed with vmware-cmdTo display all registered VMs, type
Figure 13.35 displays the output from the command, which shows all the registered virtual machines on ESX Server. Figure 13-35. Output from the vmware-cmd/ CommandTo power on VMs from the Service Console, type
Figure 13.36 shows the syntax and output of the command. Figure 13-36. Output from vmware-cmd to Perform the Power-Up OperationTo power off VMs from the Service Console, type
or
13.4.2. Viewing Performance Data for Virtual Machines with esxtopTo view virtual machine performance data, type
The output is shown in Figure 13.37 This allows you to view performance statistics for individual virtual machines as well as statistics for overall memory usage, swap file usage, and the disk and network performance of your ESX Server. The esxtop utility is similar to the top utility but is more specific for virtual machine performance data. To exit esxtop, press q to quit. As with the top utility, there are other options you can use to change the way the data is displayed within esxtop. Also, you can view the man pages for esxtop by typing man esxtop at the command line. Figure 13-37. Displays the esxtop Utility ScreenTo find out the virtual machine you're viewing performance statistics for, you need to obtain the VMID number from the MUI and match it with the WID number in esxtop. 13.4.3. Adding a New Virtual Disk, Blank Virtual Disk, and Extending Your Existing Virtual DiskTo create a new blank virtual disk, type
as in the following example:
What this allows you to do is add a new 2GB hard disk which can then be added to all existing virtual machines and formatted at the OS level within the VM. To extend a virtual disk, type
An example of this is shown in the following:
Note: The virtual machine needs to be powered off prior to extending the virtual disk. VMware recommends you make a full backup on the vmdk file prior to completing this task. You will also need to use a utility like Partition Magic to extend the partition within the VM for it to recognize the additional space added to the disk file. 13.4.4. Performing Backups and Restores of Virtual Machine Virtual DisksYou may want to incorporate the following scripts into your disaster recovery process for your virtual machines. If you want to back up a virtual machine's virtual disk while it's still powered on, type
You must replace the backup-server argument with the name of a server that's configured to receive the exported virtual disk over SCP. Note: VMware recommends that you quiesce the application running within the virtual machine in order to get the most consistent backup. If you want to schedule your backups, you could also set up a cron job to run nightly. You can also restore virtual machines backed up with this method by typing
|