You are on page 1of 20

Using vmrun to Control Virtual Machines

VMware Workstation 7.0 VMware Fusion 3.0 VMware vSphere 4 VMware Server 2.0

This document supports the version of each product listed and supports all subsequent versions until the document is replaced by a new edition. To check for more recent editions of this document, see http://www.vmware.com/support/pubs.

EN-000222-2

Using vmrun to Control Virtual Machines

You can find the most up-to-date technical documentation on the VMware Web site at: http://www.vmware.com/support/ The VMware Web site also provides the latest product updates. If you have comments about this documentation, submit your feedback to: docfeedback@vmware.com

Copyright 2008, 2009 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents. VMware is a registered trademark or trademark of VMware, Inc. in the United States and/or other jurisdictions. All other marks and names mentioned herein may be trademarks of their respective companies.

VMware, Inc. 3401 Hillview Ave. Palo Alto, CA 94304 www.vmware.com

VMware, Inc.

Contents

AboutThisBook

5 7

UsingvmruntoControlVirtualMachines
AboutthevmrunUtility 7 PowerCommands 7 SnapshotCommands 7 RecordandReplayCommands 7 GuestOperatingSystemCommands 8 MaintenanceCommands 8 VProbesCommands 8 Limitations 8 SettingUpvmrun 8 HowtoGetvmrun 8 LinuxSetup 8 WindowsSetup 9 MacOSXSetup 9 SpecifyingtheVMwareProductPlatform 9 EncryptedVirtualMachines 9 GuestOperations 9 RunningHostedPlatformsLocally 9 RunningVMwarevSphereRemotely 10 RunningVMwareServerRemotely 10 VirtualMachineRunReference 10 PathtoVMXFile 10 DisablingDialogBoxes 10 SyntaxofvmrunCommands 11 ExamplesofUsingvmrun 15 RebootCommands 15 PowerCommands 15 SnapshotCommands 16 RecordandReplayCommands 16 RunningGuestApplications 16 GuesttoHostFileOperations 17 MaintenanceCommands 18

Index 19

VMware, Inc.

Using vmrun to Control Virtual Machines

VMware, Inc.

About This Book

Thismanual,UsingvmruntoControlVirtual Machines,documentsthevmrunutility,whichhelpsyoumanagea collectionofvirtualmachinesonaVMwarehost.

Revision History
Thisbookisrevisedwitheachreleaseoftheproductorwhennecessary.Arevisedversioncancontainminor ormajorchanges.Table 1summarizesthesignificantchangesineachversionofthisguide. Table 1. Revision History
Revision 20091020 20090909 20081231 20080815 20080724 20080623 Description ForVMwareWorkstation7.0,VMwarePlayer3.0,andVMwareFusion3.0. FortheVIXAPI1.7release,whichprovidedsupportforESX/ESXihostsandVMwarevSphere4. NewinformationaboutnullinterpreterforRunScriptInGuestonWindows. MoreexamplesforVMwareServer2.0RC2andWorkstation6.5RC. Initialrelease,includingsupportforVMwareFusiononIntelbasedMacintoshOSXhosts. InitialdraftfortheVMwareServer2.0RC1andWorkstation6.5Beta2releases.

Intended Audience
Thisbookisintendedfordevelopersandsystemadministratorswhowanttocontrolguestvirtualmachines onvariousVMwareproductplatforms.SupportedplatformsincludeWorkstation,Player,VMwareFusion, VMwareServer,andVMwarevSphere(ESX/ESXihostswithvCenterServer).

Document Feedback
VMwarewelcomesyoursuggestionsforimprovingourdocumentation.Sendyourfeedbackto docfeedback@vmware.com.

Technical Support and Education Resources


Thefollowingsectionsdescribethetechnicalsupportresourcesavailabletoyou.Toaccessthecurrentversions ofotherVMwarebooks,gotohttp://www.vmware.com/support/pubs.

Online and Telephone Support


Touseonlinesupporttosubmittechnicalsupportrequests,viewyourproductandcontractinformation,and registeryourproducts,gotohttp://www.vmware.com/support.

VMware, Inc.

Using vmrun to Control Virtual Machines

Support Offerings
TofindouthowVMwaresupportofferingscanhelpmeetyourbusinessneeds,goto http://www.vmware.com/support/services.

VMware Professional Services


VMwareEducationServicescoursesofferextensivehandsonlabs,casestudyexamples,andcoursematerials designedtobeusedasonthejobreferencetools.Coursesareavailableonsite,intheclassroom,andlive online.Foronsitepilotprograms andimplementationbestpractices,VMwareConsultingServicesprovides offeringsto helpyouassess,plan,build,andmanageyourvirtualenvironment.Toaccessinformationabout educationclasses,certificationprograms,andconsultingservices,gotohttp://www.vmware.com/services.

VMware, Inc.

Using vmrun to Control Virtual Machines

Thisdocumentcontainsthefollowingsections:

AboutthevmrunUtilityonpage 7 SettingUpvmrunonpage 8 SpecifyingtheVMwareProductPlatformonpage 9 VirtualMachineRunReferenceonpage 10 ExamplesofUsingvmrunonpage 15

About the vmrun Utility


Youcanusethevmruncommandlineutilitytocontrolvirtualmachinesandautomateguestoperationson VMwarevirtualmachines.ThevmrunutilityisincludedwiththeVIXAPIlibraries. ThevmrunutilityrunsonmostVMwareproductplatforms,includingWorkstation,Player,VMwareFusion, VMwarevSphere(ESX/ESXihostsmanagedbyvCenterServer),andVMwareServer.Ontheseplatforms,the VIXAPIlibrariesandthevmrunutilityareoftenthebestwaytoautomateguestoperations. Capabilitiesofvmrunaresummarizedinthesectionsbelow.

Power Commands
Powercommandscontrolthesevirtualmachineoperations:start(poweron),stop(poweroff),reset(reboot), suspend(butallowlocalworktoresume),pause(withoutinterrupting),andunpause(continue). Workstationcangroupvirtualmachinesinteamsandapplypoweroperationstothewholeteam.

Snapshot Commands
Asnapshotcapturesthestateofavirtualmachineatthetimeofthesnapshot,includingalldataonvirtual disks.Youcanthenusethesnapshottorevertthevirtualmachinetoitspreviousstate.Snapshotsareuseful fordatabackup,andasaplaceholderfordevelopmentandtesting. Snapshotcommandslistexistingsnapshotsofavirtualmachine,createasnapshot,deleteasnapshot,and revertavirtualmachinetoitsstateatthetimeofasnapshot. VMwareServerlimitseachvirtualmachinetoonesnapshot.VMwareFusionsupportssnapshotsinalineonly.

Record and Replay Commands


Youcanrecordvirtualmachineeventsforlaterreplay.Therecordingiscalledareplaysnapshot.Itissimilar toamovie.Currently,onlyWorkstationsupportsrecordandreplay. Thesecommandsbeginorendtherecordingofevents,andbeginorendthereplayofarecording.

VMware, Inc.

Using vmrun to Control Virtual Machines

Guest Operating System Commands


Youcanusethevmrunutilitytointeractwithaguestoperatingsysteminthefollowingways:

Runanexecutableprogramintheguestoperatingsystem,orrunaninterpretedscriptthatyouprovide. Checkifafileexistsintheguest,deleteafile,renameafile,listfiles,andcreateordeleteadirectory. Copyafilefromthehosttotheguest,orfromtheguesttothehost. Addasharedfolderfromthehost,makeasharedfolderwritableintheguest,orremoveasharedfolder. Captureascreenimagefromtheguest(WorkstationandVMwareFusiononly). Listtheprocessesrunningintheguestoperatingsystem,orendaprocess(withpermission). Readorwriteavariableintheguestoperatingsystemsenvironmentorvirtualmachinestate.

Thetimeout(waitforVMwareTools)isfiveminutesforallguestrelatedcommands.

Maintenance Commands
Thiscategoryincludescommandstolistallrunningvirtualmachines,upgradethevirtualmachinehardware version,andinstallVMwareToolsintheguestoperatingsystem. Additionally,exceptonVMwareServer,youcancloneavirtualmachineimagetoanothervirtualmachine. OnVMwarevSphereandVMwareServer,youcanregisterandunregistervirtualmachines.

VProbes Commands
OnWorkstationandFusion,vmruncaninteractwithVProbes,afacilityforinstrumentingapoweredonguest operatingsystem,itsprocesses,andthevirtualizationlayer.SeetheVProbesProgrammingReferencefordetails.

Limitations
VMwareFusiondoesnotsupportsnapshottrees,orrecordandreplay. Playerdoesnotsupportpauseandunpause,snapshotoperations,virtualmachinecloning,virtualhardware upgrade,orrecordandreplay. VMwareServerdoesnotsupportteams,sharedfolders,cloning,recordandreplay,ormultiplesnapshots. Whenyoutrytocreateasecondsnapshot,theUIasksyoutooverwriteyourexistingsnapshot.

Setting Up vmrun
Theprocedureforsettingupvmrunvariesbasedontheoperatingsystemoftheclientcomputer.

How to Get vmrun


ThevmrunutilityinstallswithWorkstationandVMwareFusion. Forusewithremoteproductplatforms,youcanobtainvmrunbyinstallingtheVIXstandalonelibraries, availablefreeofchargeontheVMwaredownloadsite.

Linux Setup
To use the vmrun utility on Linux 1 2 Inacommandorterminalwindow,typevmruntoseecommandlineoptions. IfthisfailsonanoldLinuxdistribution:asrootorsuperuser,editthe/etc/ld.so.conffile,addthe followinglinewiththedefaultlocationoftheVIXlibrary,savethefile,andruntheldconfigcommand.
/usr/lib/vmware-vix/lib

VMware, Inc.

Using vmrun to Control Virtual Machines

Windows Setup
To use the vmrun utility on Windows 1 Thevmrunutilityisinstalledinthisfolderbydefault:
C:\Program Files\VMware\VMware VIX

IfVMwareWorkstationisalreadyinyoursystemPath,thisstepisunnecessarybecauseacopyofvmrun isinstalledthere.Ifnot,addtheVIXfolderlocationtoyoursystempath.OnWindowsXP,click: Computer>Properties>Advanced>EnvironmentVariables>Systemvariables>Path>Edit Withtherightarrowkey,movetheinsertionpointtotheendofline,addasemicolon,addthefullpath ofthefolderwherevmrunislocated,andclickOKthreetimes.

Inacommandwindow,typevmruntoseecommandlineoptions.

Mac OS X Setup
To use the vmrun utility on Mac OS 1 InaTerminalwindow,addtheVMwareFusiondirectorytoyoursystempath.
export PATH="$PATH:/Library/Application Support/VMware Fusion"

Typevmruntoseecommandlineoptions.

Specifying the VMware Product Platform


Thevmrunutilityacceptsoptionflags,commands,andparametersinthefollowingsyntax:
vmrun <flags> <command> <parameters>

Inthefollowingsyntaxexamples,optionsenclosedinanglebracketsindicatevariablesthatyousupply.

Encrypted Virtual Machines


Encryptedvirtualmachinesrequireapasswordformostoperations.
-vp <password for encrypted virtual machine>

Guest Operations
Guestoperationsrequireauthenticationbytheguestoperatingsystem,sotheircommanddescriptionsin Table 2,vmrunCommandsandParameters,onpage 11saythatavalidguestloginisrequired.Usethe followingflagstospecifytheguestlogin:
-gu <userName in guest OS> -gp <userPassword in guest OS>

Running Hosted Platforms Locally


OnWorkstationandVMwareFusion,vmruncontrolsguestoperatingsystemsonthelocalhost.Youdonot needtospecifyaremotehostnameorport. ForWorkstation,Player,andVMwareFusion,usethe-Tflag:
vmrun -T ws vmrun -T player vmrun -T fusion

NOTEOnWorkstation,Player,andVMwareFusion,poweringonavirtualmachinewiththedefaultgui optionrequiresawindowsystem(userinterface)toberunningonthehost.VMwarevSphereandVMware Serverdonotimposethisrequirement.

VMware, Inc.

Using vmrun to Control Virtual Machines

Running VMware vSphere Remotely


InVMwarevSphere,usethe-TflagtoconnecttoanESX/ESXi4.0host.
vmrun -T esx

InVMwarevSphere,usethe-TflagtoconnecttothevCenterServer.
vmrun -T vc

VMwarevSphererequiresadditionalflagsforconnectionstoanESX/ESXihostorthevCenterServer:
-h -P -u -p https://<hostName or IPaddr>/sdk <portNumber> <adminLogin on VMware Server> <adminPassword on VMware Server>

Theportnumberdefaultsto443.Youcanalsospecifytheportnumberinthe-hoptionafterthehostnameor IPaddress,separatedbyacolon,instandardURLsyntax.Forexample,thefollowingcommandlistsall runningvirtualmachinesonaremoteserver:


vmrun -T esx -h https://esx.example.com:8333/sdk -u root -p secretpw list

Running VMware Server Remotely


TosetthehosttypeforremoteaccesstoVMwareServer2.0,usethe-Toptionwith-handotheroptions.
vmrun -T server -h https://vm2.example.com:443/sdk -u root -p secretpw list

TosetthehosttypeforremoteaccesstoVMwareServer1.0.x,usethe-Toption,the-hoptionwiththehost nameinsteadoftheURL,andthe-Poptionwiththeportnumber.
vmrun -T server1 -h vm1.example.com -P 443 -u root -p secretpw list

Virtual Machine Run Reference


Thissectiondocumentsthesyntaxofcommandsinthevmrunutility.

Path to VMX File


VMwarestoresvirtualmachinesasapackagethatincludesthevirtualmachinesettingsfile(<vnname>.vmx) andthevirtualdisks.Whenrequired,youmustprovidethecompletepathtothe.vmxfile.The.vmtnfileis similar,forteams.Hereareexamplesofwherethe.vmxfilemightbelocated:

DatastoreonanESX/ESXihost
[Storage1] Win XP/Win XP.vmx

VMwareServerdatastore
[standard] Win XP/Win XP.vmx

WorkstationforWindowspath
C:\Documents and Settings\<username>\My Documents\My Virtual Machines\Win XP\Win XP.vmx

WorkstationforLinuxpath
/home/<username>/VirtualMachines/Ubuntu/Ubuntu.vmx

VMwareFusionforMacOSXpath
~/Documents/Virtual Machines.localized/Windows XP Home.vmwarevm/Windows XP Home.vmx

Disabling Dialog Boxes


Withvirtualmachinesthatrequireuserinputthroughadialogbox,thevmrunutilitymighttimeoutandfail. Todisabledialogboxes,insertthefollowinglineinthevirtualmachineconfigurationfile(.vmx):
msg.autoAnswer = TRUE

10

VMware, Inc.

Using vmrun to Control Virtual Machines

Syntax of vmrun Commands


Table 2listsvmruncommandsandparametersaccordingtotheirfunction.Parametersarelistedoneperline. Parametersenclosedinsquarebracketsareoptional.Theverticalbarindicatesakeywordchoice. Table 2. vmrun Commands and Parameters
Command Power Commands start (Teamssupportedonlyon Workstation.) Startsavirtualmachine(.vmxfile)orteam(.vmtmfile). Thedefaultguioptionstartsthemachineinteractively, whichisrequiredtodisplayaVMwareuserinterface. Thenoguioptionsuppressestheuserinterface, includingthestartupdialogbox,toallownoninteractive scripting. Stopsavirtualmachine(.vmxfile)orteam(.vmtmfile). Usethesoftoptiontopowerofftheguestafterrunning shutdownscripts.Usethehardoptiontopoweroffthe guestwithoutrunningscripts,asifyoupressedthe powerbutton.ThedefaultistousethepowerTypevalue specifiedinthe.vmxfile,ifpresent. Resetsavirtualmachine(.vmxfile)orteam(.vmtmfile). Usethesoftoptiontorunshutdownscriptsbefore rebootingtheguest.Usethehardoptiontorebootthe guestwithoutrunningscripts,asifyoupressedthereset button.ThedefaultistousethepowerTypevalue specifiedinthe.vmxfile,ifpresent. Suspendsavirtualmachine(.vmxfile)orteam(.vmtm) withoutshuttingdown,solocalworkcanresumelater. Thesoftoptionsuspendstheguestafterrunning systemscripts.OnWindowsguests,thesescriptsrelease theIPaddress.OnLinuxguests,thescriptssuspend networking.Thehardoptionsuspendstheguest withoutrunningthescripts.Thedefaultistousethe powerTypevaluespecifiedinthe.vmxfile,ifpresent. Toresumevirtualmachineoperationaftersuspend,use thestartcommand.OnWindows,theIPaddressis retrieved.OnLinux,networkingisrestarted. pause (Pausesupportedonlyon Workstation.) unpause (Unpausesupportedonlyon Workstation.) Snapshot Commands listSnapshots Listsallsnapshotsinavirtualmachine(.vmxfile). Theshowtreeoptiondisplayssnapshotsintreeformat, withchildrenindentedundertheirparent. snapshot (VMwareServerdoesnot supportmultiplesnapshots. VMwareFusiondoesnot supportsnapshottrees.) Createsasnapshotofavirtualmachine(.vmxfile).For productsthatsupportmultiplesnapshots,youmust providethesnapshotname. Becausetheforwardslashdefinespathnames,donot usetheslashcharacterinasnapshotname,becausethat makesitdifficulttospecifythesnapshotpathlater. <pathto.vmxfile> [ showtree ] <pathto.vmxfile> <snapshotname> Pausesavirtualmachine(.vmxfile).Youcanusethis eithertopausereplayortopausenormaloperation. Resumesoperationofavirtualmachine(.vmxfile)from whereyoupausedreplayornormaloperation. <pathto.vmxfile> <pathto.vmxor.vmtmfile> [ gui | nogui ] Description Parameters

stop (Teamssupportedonlyon Workstation.)

<pathto.vmxor.vmtmfile> [ hard | soft ]

reset (Teamssupportedonlyon Workstation.)

<pathto.vmxor.vmtmfile> [ hard | soft ]

suspend (Teamssupportedonlyon Workstation.)

<pathto.vmxor.vmtmfile> [ hard | soft ]

<pathto.vmxfile>

VMware, Inc.

11

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command deleteSnapshot (VMwareServeralways deletestherootsnapshot.) Description Removesasnapshotfromavirtualmachine(.vmxfile). Forproductsthatsupportmultiplesnapshots,youmust providethesnapshotname. Thevirtualmachinemustbepoweredofforsuspended. Ifthesnapshothaschildren,theybecomechildrenofthe deletedsnapshotsparent,andsubsequentsnapshots continueasbeforefromtheendofthechain. TheandDeleteChildrenoptiondeletesthespecified snapshotanditschildrenrecursively. SeerevertToSnapshotforsolutionstonameconflicts. revertToSnapshot (VMwareServeralways revertstotherootsnapshot.) Setsthevirtualmachinetoitsstateatsnapshottime. However,ifthevirtualmachinewaspoweredonatthe timeofthesnapshot,vmrunrevertsittosuspendedstate. Ifasnapshothasauniquenamewithinavirtual machine,reverttothatsnapshotbyspecifyingthepath tothevirtualmachinesconfigurationfileandthe uniquesnapshotname. Ifseveralsnapshotshavethesamename,specifythe snapshotbyincludingafullpathnameforthesnapshot. Apathnameisaseriesofsnapshotnames,separatedby forwardslashcharacters(/).Eachnamespecifiesanew snapshotinthetree.Forexample,thepathname Snap1/Snap2identifiesasnapshotnamedSnap2that wastakenfromthestateofasnapshotnamedSnap1. Record and Replay Commands beginRecording (Recordingsupportedonly onWorkstation.) endRecording beginReplay (Replaysupportedonlyon Workstation.) Beginsrecordingarunningvirtualmachine(.vmxfile), storingactivityinthespecifiedsnapshotobject,with optionaldescriptionforyourconvenience. Onlyonerecordingorreplaycanbeactiveatatime. Endstherecordingofavirtualmachine(.vmxfile)that isinprogress,andclosesitssnapshotobject. Beginsreplayingtherecordedactivityofapoweredoff virtualmachine(.vmxfile)fromasnapshotobject, poweringoffthevirtualmachineifnecessary. Onlyonerecordingorreplaycanbeactiveatatime. Youcanpausereplaywiththepausecommand,and resumereplaywiththeunpausecommand. endReplay Endsreplayoftherecordedvirtualmachine(.vmxfile) thatisunderway. <pathto.vmxfile> <pathto.vmxfile> <snapshotobjectname> [<description>] <pathto.vmxfile> <pathto.vmxfile> <snapshotobjectname> <pathto.vmxfile> <snapshotname> or <pathto.vmxfile> <snap1/snap2/snapN> Parameters <pathto.vmxfile> <snapshotname> [ andDeleteChildren ]

Guest Operating System Commands Thetimeout(waitforVMwareTools)isfiveminutesforallguestrelatedcommands. runProgramInGuest Runsaspecifiedprogramintheguestoperatingsystem. The-noWaitoptionreturnsapromptimmediatelyafter theprogramstartsintheguest,ratherthanwaitingforit tofinish.Thisoptionisusefulforinteractiveprograms. The-activeWindowoptionensuresthattheWindows GUIisvisible,notminimized.IthasnoeffectonLinux. The-interactiveoptionforcesinteractiveguestlogin. ItisusefulforWindowsVistagueststomakethe programvisibleintheconsolewindow. Youmustprovidethefullpathnameofaprogram accessibletotheguest.Alsoprovidefullaccessible pathnamesforanyfilesspecifiedintheprogram arguments,accordingtorequirementsoftheprogram. VMwareToolsandavalidguestloginarerequired. <pathto.vmxfile> [ -noWait | -activeWindow | -interactive ] <programname> [<programarguments>]

12

VMware, Inc.

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command fileExistsInGuest Description Checkswhetherthespecifiedfileexistsintheguest operatingsystem.VMwareToolsandavalidguestlogin arerequired. Modifiesthewritabilitystateofaspecifiedfoldershared betweenthehostandaguestvirtualmachine(.vmxfile). Thesharenameisamountpointintheguestfilesystem. Thepathtofolderistheexporteddirectoryonthehost. Asharedfoldercanbemadewritableorreadonly. Addsafoldertobesharedbetweenthehostandguest. Thesharenameisamountpointintheguestfilesystem. Thepathtofolderistheexporteddirectoryonthehost. OnWindowsguests,theremightbeadelaybefore sharedfoldersarevisibletotheInGuestcommands. Removestheguestvirtualmachinesaccesstoashared folderonthehost.Thesharenameisamountpointin theguestfilesystem. Allowstheguestvirtualmachine,specifiedby.vmxfile, tosharefolderswithitshost.Afterenabling,run addSharedFoldertospecifyeachhostfoldertoshare. Theoptionalruntimeargumentmeanstosharefolders onlyuntilthevirtualmachineispoweredoff.Otherwise, thesettingpersistsatnextpoweron. Stopstheguestvirtualmachine,specifiedby.vmxfile, fromsharingfolderswithitshost. Theoptionalruntimeargumentmeanstostopsharing foldersonlyuntilthevirtualmachineispoweredoff. Otherwise,thesettingpersistsatnextpoweron. Listsallprocessesrunningintheguestoperating system.VMwareToolsandavalidguestloginare required. Stopsaspecifiedprocessintheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. TheprocessIDcanbeanynumberlistedafterpid=in theoutputoflistProcessesInGuest. runScriptInGuest Runsthespecifiedcommandscriptintheguest operatingsystem.VMwareToolsandavalidguestlogin arerequired. Theinterpreterpathisthecommandthatrunsthescript. Providethecompletetextofthescript,notafilename. deleteFileInGuest Deletesthegivefilefromtheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. ForWindowsVistarestrictionsonthiscommand,see noteinGuesttoHostFileOperationsonpage 17. createDirectoryInGuest Createsthespecifieddirectoryintheguestoperating system.VMwareToolsandavalidguestloginare required. ForWindowsVistarestrictionsonthiscommand,see noteinGuesttoHostFileOperationsonpage 17. deleteDirectoryInGuest Deletesthespecifieddirectoryfromtheguestoperating system.VMwareToolsandavalidguestloginare required. ForWindowsVistarestrictionsonthiscommand,see noteinGuesttoHostFileOperationsonpage 17. <pathto.vmxfile> <directorypathonguest> <pathto.vmxfile> <directorypathonguest> <pathto.vmxfile> <interpreterpath> <scripttext> <pathto.vmxfile> <pathto.vmxfile> [runtime] Parameters <pathto.vmxfile> <pathtofileonguest> <pathto.vmxfile> <sharename> <pathtofolderonhost> writable |readonly <pathto.vmxfile> <sharename> <pathtofolderonhost>

setSharedFolderState (VMwarevSphereand VMwareServerdonot supportsharedfolders.) addSharedFolder (VMwarevSphereand VMwareServerdonot supportsharedfolders.) removeSharedFolder (VMwarevSphereand VMwareServerdonot supportsharedfolders.) enableSharedFolders (VMwarevSphereand VMwareServerdonot supportsharedfolders.)

<pathto.vmxfile> <sharename>

<pathto.vmxfile> [runtime]

disableSharedFolders (VMwarevSphereand VMwareServerdonot supportsharedfolders.) listProcessesInGuest

killProcessInGuest

<pathto.vmxfile> <processID>

<pathto.vmxfile> <pathtofileonguest>

VMware, Inc.

13

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command listDirectoryInGuest Description Listscontentsofthespecifieddirectoryintheguest operatingsystem.VMwareToolsandavalidguestlogin arerequired. Copiesafilefromthehosttotheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. Specifythesourcefile(host)beforethedestinationfile (guest). ForWindowsVistarestrictionsonthiscommand,see noteinGuesttoHostFileOperationsonpage 17. copyFileFromGuestToHost Copiesafilefromtheguestoperatingsystemtothehost. VMwareToolsandavalidguestloginarerequired. Specifythesourcefile(guest)beforethedestinationfile (host). renameFileInGuest Renamesormovesafileintheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. Specifythesourcename(original)beforethedestination (new). captureScreen Capturesthescreenofthevirtualmachinetoalocalfile. ThespecifiedoutputfileonthehostisinPNGformat. Avalidguestloginisrequired. writeVariable Writesavariabletothevirtualmachinestateorguest. Youcanseteitherruntimeconfigurationinthe.vmxfile, orenvironmentvariablesintheguestoperatingsystem. EnvironmentvariablesrequireVMwareToolsandvalid guestlogin.ForLinuxguests,settingtheguestEnv requiresrootlogin. Providethevariablenameanditsvalue. readVariable Readsavariablefromthevirtualmachinestateorguest. Youcangeteitherruntimeconfigurationinthe.vmxfile, orenvironmentvariablesintheguestoperatingsystem. Thelatterrequiresavalidguestlogin. <pathto.vmxfile> [ runtimeConfig | guestEnv ] <variablename> <pathto.vmxfile> [ runtimeConfig | guestEnv ] <variablename> <variablevalue> <pathto.vmxfile> <filepathinguest> <filepathonhost> <pathto.vmxfile> <originalfilename> <newfilename> <pathto.vmxfile> <outputpathonhost> Parameters <pathto.vmxfile> <directorypathonguest> <pathto.vmxfile> <filepathonhost> <filepathinguest>

copyFileFromHostToGuest

Maintenance Commands list upgradevm Listsallrunningvirtualmachines. Upgradesavirtualmachinetothecurrentversionof virtualhardware.Hasnoeffectifthevirtualhardware versionisthemostrecentsupported. PreparestoinstallVMwareToolsintheguestoperating system.InWindowsguestswithautorunenabled,the VMwareToolsinstallerstartsbyitself.InLinuxguests withoutautorun,thiscommandconnectsthevirtual CDROMdrivetotheVMwareToolsISOimagesuitable fortheguest,buttheinstallerdoesnotstart.Youmust completetheinstallationwithadditionalmanualsteps, asdescribedintheproductdocumentation. Registersthespecifiedvirtualmachine,addingittothe hostsinventory.Pathformatdependsontheproduct. ForVMwareServer2.0,"[storage1] vm/vm.vmx" (startingwiththedatastore)istypical. Unregistersthespecifiedvirtualmachine,removingit fromthehostsinventory.Pathformatdependsonthe product.ForServer2.0,"[storage1] vm/vm.vmx" (startingwiththedatastore)istypical. Listsallregisteredvirtualmachines. Removesthespecifiedvirtualmachine. None <pathto.vmxfile>

installTools

<pathto.vmxfile>

register (Registrationnotsupported onWorkstationoron VMwareFusion.) unregister (Registrationnotsupported onWorkstationoron VMwareFusion.) listRegisteredVM deleteVM

<pathto.vmxfile>

<pathto.vmxfile>

None <pathto.vmxfile>

14

VMware, Inc.

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command clone (Cloningnotsupportedon VMwareServeroron VMwareFusion.) VProbes Commands (VProbespermittedonlyonWorkstationandVMwareFusion.) vprobeVersion vprobeLoad ShowstheVProbesversiononthevirtualmachine. LoadsaVPscriptontothevirtualmachine. LoadsaVPscriptfileontothevirtualmachine. DisablesallVProbesonthevirtualmachine. ListsactiveVProbesonthevirtualmachine. ListsVProbesglobalvariablesonthevirtualmachine. <pathto.vmxfile> <pathto.vmxfile> <textoftheVPscript> vprobeLoadFile <pathto.vmxfile> <pathtoVPscript> vprobeReset vprobeListProbes vprobeListGlobals <pathto.vmxfile> <pathto.vmxfile> <pathto.vmxfile> Description Createsacopyofthevirtualmachineandguest.Provide boththesourceandthedestination.vmxfilepathname. Youcancreateeitherafullcloneoralinkedclone.To createtheclonefromasnapshot,ratherthanfromthe currentvirtualmachinestate,specifyasnapshotname. Parameters <pathto.vmxfile> <destination.vmxfilepath> full |linked [<snapshotname>]

Examples of Using vmrun


ThefollowingcommandlineexamplesworkonWorkstation(-Tws),VMwareFusion(-Tfusion),or VMwareESX/ESXihosts(-Tesx). Youcanderivetheguestoperatingsystemtypeinexamplesbydistinguishing/forLinuxand\forWindows.

Reboot Commands
RebootavirtualmachinerunningonWorkstationforLinux:
vmrun -T ws reset /path/to/vm/RHEL4/RHEL4.vmx soft

RebootavirtualmachinerunningonWorkstationforWindows:
cd "C:\Documents and Settings\<user>\My Documents\My Virtual Machines" vmrun -T ws reset "WindowsXP\WindowsXP.vmx" soft

RebootavirtualmachinerunningonVMwareFusion:
vmrun -T fusion reset ~/Documents/VirtualMachines.localized/WindowsXP.vmwarevm/WindowsXP.vmx soft

RebootavirtualmachinerunningonanESX/ESXihost:
vmrun -T esx -h https://10.0.1.8/sdk -u root -p <pass> reset "[storage1] WinXP/WinXP.vmx" soft

Power Commands
PoweronavirtualmachinewithWorkstationonaWindowshost:
vmrun start "C:\Documents and Settings\<user>\My Documents\My Virtual Machines\WinXP\WinXP.vmx"

ThiserrormessagefollowingthiscommandindicatesthattheVIXpackageyouinstalleddoesnotsupport VMwareServer:
vmrun -T server start "My Virtual Machines\WinXP\WinXP.vmx" Error: The specified service provider was not found

PoweroffavirtualmachinewithWorkstationonaWindowshost:
vmrun stop "C:\Documents and Settings\<user>\My Documents\My Virtual Machines\WinXP\WinXP.vmx"

OntheremoteESX/ESXihostwithIPaddress10.0.1.8,poweronavirtualmachine:
vmrun -T esx -h https://10.0.1.8/sdk -u root -p <pass> start "[storage1] WinXP/WinXP.vmx"

VMware, Inc.

15

Using vmrun to Control Virtual Machines

IfHTTPSserviceisnotconfiguredonport443,specifytheappropriateportafterthecolon:
vmrun -T esx -h https://10.0.1.9:8333/sdk -u root -p <pass> start "[storage1] WinXP/WinXP.vmx"

OntheremoteESX/ESXihostwithIPaddress10.0.1.8,poweroffthevirtualmachine:
vmrun -T esx -h https://10.0.1.8/sdk -u root -p <pass> start "[storage1] WinXP/WinXP.vmx"

ForVMwareServerinstalledonWindowshosts,the-uuserisusuallyAdministrator,notroot.
vmrun -T server -h https://10.0.1.8/sdk -u Administrator -p <pass> start "[std] WinXP/WinXP.vmx"

Snapshot Commands
CreateasnapshotofavirtualmachinewithWorkstationonaLinuxhostorVMwareFusion:
vmrun -T ws snapshot /path/to/vm/Ubuntu/Ubuntu.vmx mySnapshot

Listsnapshotsonthevirtualmachine,showingtheonemadeinthepreviouscommand:
vmrun -T ws listSnapshots /path/to/vm/Ubuntu/Ubuntu.vmx Total snapshots: 1 mySnapshot

Reverttothesnapshotyoumade,whichsuspendsthevirtualmachine,andrestarttoresumeoperation:
vmrun -T ws revertToSnapshot /path/to/vm/Ubuntu/Ubuntu.vmx mySnapshot vmrun -T ws start /path/to/vm/Ubuntu/Ubuntu.vmx

Deletethesnapshotbyspecifyingitsname:
vmrun -T ws deleteSnapshot /path/to/vm/Ubuntu/Ubuntu.vmx mySnapshot

Record and Replay Commands


StartrecordingusereventsonaWindowsguest,beginningwithasnapshotofthevirtualmachinestate:
vmrun -T ws -gu <user> -gp <pass> beginRecording WinXP\WinXP.vmx session1

Whenyoustoprecording,nametherecordingsession:
vmrun -T ws -gu <user> -gp <pass> endRecording WinXP\WinXP.vmx

Reverttothevirtualmachinesnapshotandstartreplayingtherecordingofuserevents:
vmrun -T ws -gu <user> -gp <pass> beginReplay WinXP\WinXP.vmx session1

Pausereplay:
vmrun -T ws -gu <user> -gp <pass> pause WinXP\WinXP.vmx

Resumereplay:
vmrun -T ws -gu <user> -gp <pass> unpause WinXP\WinXP.vmx

Endreplay:
vmrun -T ws -gu <user> -gp <pass> endReplay WinXP\WinXP.vmx

Running Guest Applications


Startthecommandtool,minimized,onaWindowsguest:
vmrun -T ws -gu <user> -gp <pass> runProgramInGuest WinXP\WinXP.vmx cmd.exe

StartthecommandtoolonaWindowsguestasanactivewindowonthedesktop:
vmrun -T ws -gu <user> -gp <pass> runProgramInGuest WinXP\WinXP.vmx -activeWindow cmd.exe

RunabatchscriptfileonaWindowsguest,withPerlasthescriptinterpreter:
vmrun -T ws -gu <user> -gp <pass> runScriptInGuest Win2k\Win2k.vmx C:\perl\perl.exe C:\script.pl

16

VMware, Inc.

Using vmrun to Control Virtual Machines

Runabatchscriptandkeeprunningafterwards.Tousecmd.exeonWindows,youmustspecifythescript interpreterasnull:
vmrun -T ws -gu <user> -gp <pass> runScriptInGuest WindowsXP\WindowsProfessionalXP.vmx "" "cmd.exe /k \"C:\\Program Files\\Microsoft Visual Studio\\VC\\vcvarsall.bat\" x86"

RunaBashshellscriptcalledrunitonaLinuxguest:
vmrun -T ws -gu <user> -gp <pass> runScriptInGuest Ubuntu/Ubuntu.vmx /bin/bash /home/<user>/runit

StartanXclockonaLinuxguest(thisrequiresthe-displayoptiontoappearontheconsole).Runthesame Xclockcommand,butreturncontrolbacktotheconsoleimmediately:
vmrun -gu <user> -gp <pass> runProgramInGuest SUSE/SUSE.vmx /usr/bin/xclock -display :0 vmrun -gu <user> -gp <pass> runProgramInGuest SUSE/SUSE.vmx -noWait /usr/bin/xclock -display :0

ForLinuxapplicationsthatdonotacceptthe-displayoption,youcansettheguestenvironmentforthe vmware-guestdprocess,whichaffectssubsequentcommands(guestEnvrequiresrootpermission):
vmrun -T ws -gu root -gp <rootpass> writeVariable Ubuntu/Ubuntu.vmx guestEnv DISPLAY :0 vmrun -T ws -gu <user> -gp <userpass> runProgramInGuest Ubuntu/Ubuntu.vmx /usr/bin/firefox

ListprocessesinaLinuxguest,andendtheprocessnumbered8192:
vmrun -T ws -gu <user> -gp <pass> listProcessesInGuest Ubuntu/Ubuntu.vmx vmrun -T ws -gu <user> -gp <pass> killProcessInGuest Ubuntu/Ubuntu.vmx 8192

RunaPerlscriptonaLinuxguesttoremoveDOSstylecarriagereturnsfromafile:
vmrun -T ws -gu <user> -gp <pass> runProgramInGuest Ubuntu/Ubuntu.vmx /usr/bin/perl -e "open(FILE, '>/tmp/unix.txt'); while (<>) { s/\r\n/\n/ ; print FILE}" /tmp/dos.txt

RunaPerlscriptonaWindowsguesttoinsertDOSstylecarriagereturnsinafile:
vmrun -T ws -gu <user> -gp <pass> runProgramInGuest WinXP\WinXP.vmx C:\cygwin\bin\perl.exe -e "open(FILE, >C:\dos.txt); while (<>) { s/\n/\r\n/ ; print FILE}" C:\unix.txt

RunaprograminaLinuxvirtualmachineonanESX/ESXihost:
vmrun -T esx -h https://10.0.1.8/sdk -u root -p <pass> -gu <user> -gp <userpass> runProgramInGuest "[storage1] RHEL4/RHEL4.vmx" /usr/X11R6/bin/xclock -display :0

Guest to Host File Operations


Tocopyafilefromthehosttoaguest,theusermusthavewritepermissiononthedestination:
vmrun -gu <user> -gp <pass> copyFileFromHostToGuest Ubuntu\Ubuntu.vmx C:\Temp\img.db /tmp/img.db

Tocopyafilefromaguesttothehost,theusermusthavereadpermissiononthesourcefile:
vmrun -gu <user> -gp <pass> copyFileFromGuestToHost Ubuntu\Ubuntu.vmx /home/<user>/addr addr.txt

Beforesharingfolders,youmustenablethemwiththeenabledSharedFolderscommand,orbyselecting VM>Settings>Options>SharedFolders>Enabledintheuserinterface.OnLinuxguests,the/mnt/hgfs directoryisavailableforsharing,butyoucanuseadifferentdirectoryforsharedfolders. ToshareafolderonaWindowshostwithaparticularLinuxguest:


vmrun -T ws addSharedFolder Ubuntu\Ubuntu.vmx <sharedFolderName> C:\Share

Sharedfoldersarewritablebydefault.Tomakeasharedfolderreadonlyortodeletethesharedfolder:
vmrun -T ws setSharedFolderState Ubuntu\Ubuntu.vmx <sharedFolderName> C:\Share readonly vmrun -T ws removeSharedFolder Ubuntu\Ubuntu.vmx <sharedFolderName>

NOTEOnWindowsVista,onlytheAdministratoraccountcanperformcertainoperations.Onlythe AdministratoraccountcanusecopyFileFromHostToGuestanddeleteFileInGuesttowriteanddelete filesinC:\andsystemdirectories.OnlytheAdministratoraccountcanusecreateDirectoryInGuestand deleteDirectoryInGuesttomodifysystemdirectories.Regularusers,eventhosewithadministrator privilege,cannotperformtheseoperations.

VMware, Inc.

17

Using vmrun to Control Virtual Machines

Maintenance Commands
ListrunningvirtualmachinesonWorkstation:
vmrun -T ws list Total running VMs: 2 C:\Documents and Settings\user\My Documents\My Virtual Machines\Ubuntu\Ubuntu.vmx C:\Documents and Settings\user\My Documents\My Virtual Machines\WinXP\WinXP.vmx

PreparetoinstallVMwareToolsonVMwareFusion:
vmrun -T fusion installTools RedHatEnt5/RedHatEnt5.vmx

RegisteranewvirtualmachineinstalledonanESX/ESXihost:
vmrun -T esx -h https://10.0.1.5/sdk -u root -p <pass> register "[storage1] RHEL5/RHEL5.vmx"

UnregisteranoldvirtualmachinegoingoutofserviceonanESX/ESXihost:
vmrun -T esx -h https://10.0.1.5/sdk -u root -p <pass> unregister "[storage1] RHEL3/RHEL3.vmx"

OnVMwarevCenterServer,thevmrunutilitysupportsthesameformofpathtoVMXspecificationas ESX/ESXihosts.YoucannotreachavirtualmachinefilethroughitsresourcepoolorvApp.
vmrun -T vc -h https://10.0.1.9/sdk -u Administrator -p <pw> register "[storage1] RHEL5/RHEL5.vmx"

18

VMware, Inc.

Index

A
addSharedFolder command 13, 17

B
beginRecording command 12, 16 beginReplay command 12, 16

C
captureScreen command 14 clone command 15 command-line flags 9 copyFileFromGuestToHost command 14, 17 copyFileFromHostToGuest command 14, 17 createDirectoryInGuest command 13

listDirectoryInGuest 14 listProcessesInGuest 13 readVariable 14 removeSharedFolder 13 renameFileInGuest 14 runProgramInGuest 12 runScriptInGuest 13 setSharedFolderState 13 user name and password 9 writeVariable 14

I
installTools command 14, 18

K D
deleteDirectoryInGuest command 13 deleteFileInGuest command 13 deleteSnapshot command 12, 16 deleteVM command 14 dialog boxes, disabling 10 disableSharedFolders command 13 killProcessInGuest command 13, 17

L
Linux setup 8 list command 14, 18 listDirectoryInGuest command 14 listProcessesInGuest command 13, 17 listRegisteredVM command 14 listSnapshots command 11, 16

E
enableSharedFolders 13 endRecording command 12, 16 endReplay command 12, 16 ESX/ESXi hosts, flags for 10

M
Mac OS setup 9 maintenance commands 8 clone 15 deleteVM 14 installTools 14 list 14 listRegisteredVM 14 register 14 unregister 14 upgradevm 14

F
fileExistsInGuest command 13 flags on command line 9 Fusion, flags for 9

G
guest operations 8 addSharedFolder 13 captureScreen 14 copyFileFromGuestToHost 14 copyFileFromHostToGuest 14 createDirectoryInGuest 13 deleteDirectoryInGuest 13 deleteFileInGuest 13 disableSharedFolders 13 enableSharedFolders 13 fileExistsInGuest 13 killProcessInGuest 13
VMware, Inc.

P
path to VMX file 10 pause command 11, 16 power commands 7 pause 11 reset 11 start 11 stop 11 suspend 11 unpause 11
19

Using vmrun to Control Virtual Machines

R
record and replay commands 7 beginRecording 12 beginReplay 12 endRecording 12 endReplay 12 register command 14, 18 removeSharedFolder command 13, 17 renameFileInGuest command 14 reset command 11, 15 revertToSnapshot command 12, 16 runProgramInGuest command 12, 16 runScriptInGuest command 13, 16

W
Windows setup 9 Workstation, flags for 9 writeVariable command 14, 17

S
Server, flags for 10 setSharedFolderState command 13, 17 setup on Linux 8 setup on Mac OS 9 setup on Windows 9 snapshot command 11, 16 snapshot commands 7 deleteSnapshot 12 listSnapshots 11 revertToSnapshot 12 snapshot 11 start command 11, 15 stop command 11, 15 suspend command 11

T
technical support resources 5

U
unpause command 11, 16 unregister command 14, 18 upgradevm command 14

V
vCenter Server, flags for 10 vmrun utility 7 VMware Fusion, flags for 9 VMware Server, flags for 10 VMware vSphere, flags for 10 VMware Workstation, flags for 9 VMX file, specifying 10 VProbes commands 8 vprobeListGlobals 15 vprobeListProbes 15 vprobeLoad 15 vprobeLoadFile 15 vprobeReset 15 vprobeVersion 15

20

VMware, Inc.