Linux Articles January 20, 2011 1

Managing VMware images from command line using vmrun tool

Managing VMware images in VMware Server 2.x can be done in several ways. One way is to utilise Web based GUI and the second way is the command line.

To login to the Web based GUI

  • (SSL) https://hostname:8333/ui/#
  • http://hostname:8222/ui/# (How to disable redirect to SSL could be foundĀ here)

Let’s get focused on Shell commands – application: vmrun

Usage: vmrun [AUTHENTICATION-FLAGS] COMMAND [PARAMETERS]

Listing VM’sĀ 

#To List registered VMs
user@host:~$ vmrun -T server -h 'http://localhost:8222/sdk' -u user \
-p password listRegisteredVM

Total registered VMs: 10
[standard] MyImageDir/my_wmware_image.vmx

# To List all running VMs
user@host:~$ vmrun -T server -h 'http://localhost:8222/sdk' -u user \ 
-p password list

### LINUX SCRIPT ###
#privileged user:
user=`whoami`

read -s -p "Password: " PASS
echo
echo "Registered VMS:"
vmrun -T server -h 'http://localhost:8222/sdk' -u ${user} -p ${PASS} listRegisteredVM

echo "Running VMs:"
vmrun -T server -h 'http://localhost:8222/sdk' -u ${user} -p ${PASS} list

Start/Stop

#Starting a virtual machine with Workstation on a Linux host
user@host:~$ vmrun -T server -h 'http://localhost:8222/sdk' -u user -p password start "[standard] MyImageDir/my_wmware_image.vmx"

#Stopping a virtual machine
user@host:~$ vmrun -T server -h 'http://localhost:8222/sdk' -u user -p password stop "[standard] MyImageDir/my_wmware_image.vmx"

#make sure you will use exact syntax as above (including [standard] - which is a storage name)
#additional tasks: reset, suspend, pause, unpause

Snapshots

#Creating a snapshot of a virtual machine
user@host:~$ vmrun -T ws snapshot "/home/user/MyVms/MyImageDir/my_wmware_image.vmx" mySnapshot

#Reverting to a snapshot
user@host:~$ vmrun -T ws revertToSnapshot "/home/user/MyVms/MyImageDir/my_wmware_image.vmx" mySnapshot mySnapshot

#Deleting a snapshot
user@host:~$ vmrun -T ws deleteSnapshot "/home/user/MyVms/MyImageDir/my_wmware_image.vmx" mySnapshot mySnapshot

For more options please refer to $vmrun –help pages.

Cheers!!