You are on page 1of 14

Using vmrun to Control Virtual Machines

VMware Workstation 6.5 and VMware Server 2.0

Using vmrun to Control Virtual Machines

Using vmrun to Control Virtual Machines Item: EN-000068-00

You can find the most up-to-date technical documentation on our 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

2008 VMware, Inc. All rights reserved. Protected by one or more U.S. Patent Nos. 6,397,242, 6,496,847, 6,704,925, 6,711,672, 6,725,289, 6,735,601, 6,785,886, 6,789,156, 6,795,966, 6,880,022, 6,944,699, 6,961,806, 6,961,941, 7,069,413, 7,082,598, 7,089,377, 7,111,086, 7,111,145, 7,117,481, 7,149,843, 7,155,558, 7,222,221, 7,260,815, 7,260,820, 7,269,683, 7,275,136, 7,277,998, 7,277,999, 7,278,030, 7,281,102, 7,290,253, 7,356,679, 7,409,487, 7,412,492, and 7,412,702; patents pending. VMware, the VMware boxes logo and design, Virtual SMP and VMotion are registered trademarks or trademarks 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.

About This Book

Thismanual,UsingvmruntoControlVirtualMachines,documentsthevmrunutility,whichhelpsyoumanage thecollectionofvirtualmachinesonaVMwarehost.

Revision History
Thisbookisrevisedwitheachreleaseoftheproductorwhennecessary.Arevisedversioncancontainminor ormajorchanges.Table 1summarizesthesignificantchangesineachversionofthisguide. Table 1. Revision History
Revision 20080623 20080815 Description FirstdraftofthismanualfortheVMwareServer2.0RC1andWorkstation6.5Beta2releases. ThirddraftofthismanualfortheVMwareServer2.0RC2andWorkstation6.5RCreleases.

Intended Audience
Thisbookisintendedfordevelopersandsystemadministratorswhowanttocontrolvirtualmachineson variousplatforms,includingVMwareWorkstationandVMwareServer.

Documentation Resources
ToaccessthecurrentversionsofVMwareAPIandSDKdocumentation,goto: http://www.vmware.com/support/pubs/sdk_pubs.html ToaccessthecurrentversionsofotherVMwaremanuals,goto: http://www.vmware.com/support/pubs

Documentation Feedback
VMwarewelcomesyoursuggestionsforimprovingourdocumentation.Sendyourfeedbackto: docfeedback@vmware.com

Technical Support and Education Resources


Thefollowingsectionsdescribethetechnicalsupportandeducationalresourcesavailabletoyou.

Online Support
YoucansubmitquestionsorpostcommentstotheDeveloperCommunitySDKsandAPIsforum,whichis monitoredbyVMwaretechnicalsupportandproductteams.Toaccesstheforum,goto: http://communities.vmware.com/community/developer

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 offeringstohelpyouassess,plan,build,andmanageyourvirtualenvironment.Toaccessinformationabout educationclasses,certificationprograms,andconsultingservices,goto: http://www.vmware.com/services/

VMware, Inc.

Using vmrun to Control Virtual Machines

Youcanusethevmruncommandlineutilitytocontrolspecificvirtualmachines,orteamsofvirtualmachines. ThevmrunutilityisavailableonanyVMwareproductthatincludestheVIXAPIlibraries,orwhenthelibraries areseparatelyinstalled.Thischaptercontainsthefollowingsections: AboutthevmrunUtilityonpage 5 SettingUpvmrunonWindowsonpage 6 SettingUpvmrunonLinuxonpage 6 FlagstoSpecifyVirtualMachineTypeonpage 7 VirtualMachineRunSyntaxonpage 7 ExamplesofUsingvmrunonpage 11

About the vmrun Utility


ThevmrunutilityrunsonanyVMwareplatformwithVIXlibrariesinstalled,includingVMwareWorkstation andVMwareServer.Forinformationaboutthevariousfacilitiesthatvmruncontrols,seetheuser documentationforyourproduct. Youcanusevmruntoperformvarioustasksonvirtualmachines,summarizedbelow.

Power Commands
Virtualmachinepoweroperationsgiveyoutheseoptions:start(poweron),stop(poweroff),reset(reboot), suspend(butallowlocalworktoresume),pause(withoutinterrupting),andunpause(continue). Onsomeproducts,youcangroupvirtualmachinesintoteams,andapplypoweroperationstothewholeteam.

Snapshot Commands
Asnapshotcapturesthestateofavirtualmachineatthetimeofthesnapshot,includingalldataonvirtual disks.Youcantakeasnapshotofavirtualmachineinanypowerstateandreverttothesnapshotatanytime. Snapshotsareusefulforexperimentationandespeciallyusefulforbackups. Thesecommandslistexistingsnapshotsofavirtualmachine,createanewsnapshot,deleteasnapshot,and revertavirtualmachinetoitsstateasofaspecificsnapshot.VMwareServerlimitsyoutoonesnapshot.

Record and Replay Commands


Youcanrecordvirtualmachineeventsforlaterreplay.Therecordingiscalledasnapshotobject,butisreally morelikeamovie.Atthistime,onlyVMwareWorkstationsupportsrecordandreplay. Thesecommandsbeginorendtherecordingofevents,andbeginorendthereplayofarecording.

VMware, Inc.

Using vmrun to Control Virtual Machines

Guest Operating System Commands


Youcanusethevmrunutilitytointeractwithaguestoperatingsysteminthefollowingways: Runanexecutableprogramintheguestoperatingsystem,orrunaninterpretedscript.Theseinterfaces serveasimilarpurpose,butrunProgramInGuestprovidesmorefinegrainedcontrol. Checkifafileexistsintheguest,deleteafile,renameafile,listfiles,andcreateordeleteadirectory. Copyafilefromthehosttotheguest,orcopyafilefromtheguesttothehost. Addasharedfolderfromthehost,makeasharedfolderwritableintheguest,removeasharedfolder,or captureascreenimagefromtheguest(exceptonVMwareServer). Listtheprocessesrunningintheguestoperatingsystem,orterminateanyprocess(withpermission). Readorwriteavariableintotheguestoperatingsystemsenvironmentorvirtualmachinestate.

Maintenance Commands
Thiscategoryincludescommandstolistallrunningvirtualmachines,upgradethevirtualmachinehardware version,andinstallVMwareToolsintheguestoperatingsystem. Additionally,exceptonVMwareServer,youcancloneanyvirtualmachineimagetoanothervirtualmachine. VMwareServerallowsyoutoregisterandunregistervirtualmachines.

VProbes Commands
YoucanusevmruntoscriptVProbes,afacilityfortransparentlyinstrumentingapoweredonguestoperating system,itsrunningprocesses,andvirtualizationsoftware.SeetheVProbesProgrammingReferencefordetails.

Setting Up vmrun on Windows


To use the vmrun utility on Windows 1 Locatethevmrunutility,whichgetsinstalledinthisfolderbydefault:
C:\Program Files\VMware\VMware VIX

Addtheinstalllocationtoyoursystempath.OnWindowsXPforexample,choose: Computer>Properties>Advanced>EnvironmentVariables>Systemvariables>Path>Edit IfVMwareWorkstationisalreadyinyoursystemPath,thisstepisunnecessarybecauseacopyofvmrun isalsoinstalledthere. Usingtherightarrowkey,movetheinputpointertotheendofline,addasemicolon,addthefullpathof thefolderwherevmrunislocated,andclickOKseveraltimes.

3 4

Inacommandwindow,typevmruntoseecommandlineoptions. ContinuewithFlagstoSpecifyVirtualMachineTypeonpage 7.

Setting Up vmrun on Linux


To use the vmrun utility on Linux 1 (Optional)Asrootorsuperuser,editthe/etc/ld.so.conffile,addalinewiththelibrarylocation defaultdirectorybelow,savethefile,andruntheldconfigcommand.
/usr/lib/vmware-vix/lib

2 3

Inacommandorterminalwindow,typevmruntoseecommandlineoptions. ContinuewithFlagstoSpecifyVirtualMachineTypeonpage 7.

VMware, Inc.

Using vmrun to Control Virtual Machines

Flags to Specify Virtual Machine Type


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

Insyntaxexamples,optionsenclosedinanglebracketsindicatevariablesthatyoufillin.OnVMware Workstation,vmruncontrolsguestoperatingsystemsonthelocalhost,soyouneednotspecifyaremotehost nameorport.Possiblynoflagsarerequired. Forcommandsthatrequireauthenticationbytheguestoperatingsystem,thecommanddescriptionsin Table 2,vmrunCommandsandParameters,onpage 8statevalidguestloginrequired,inwhichcaseyou mustusethefollowingflags:


-gu <userName in guest OS> -gp <userPassword in guest OS>

TosetthehosttypeforremoteaccesstoVMwareServer2.0,usethefollowingflags:
-T -h -P -u -p server https://<hostName or IPaddr>/sdk <portNumber> <adminLogin on VMware Server> <adminPassword on VMware Server>

Ifnotspecified,theportnumberdefaultsto443.Youcanalsospecifytheportnumberinthe-hoptionafter thehostnameorIPaddress,separatedbyacolon,instandardURLsyntax.Forexample,thiscommandlists allrunningvirtualmachinesonaremoteserver:


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

ForVMwareWorkstation,usethe-Tflagasfollows:
vmrun -T ws

ForVMwareServer1.0,usethe-Tflagasfollows:
vmrun -T server1

NOTEOnVMwareWorkstation,starting(poweringon)avirtualmachinewiththedefaultguioptionrequires awindowsystem(userinterface)toberunningonthehost.VMwareServerdoesnotimposethisrequirement. VMwareServerdoesnotsupportteams,sharedfolders,cloning,recordandreplay,ormultiplesnapshots. Whenyoutrytocreateasecondsnapshot,theUIasksifyouwanttooverwriteyourexistingsnapshot.

Virtual Machine Run Syntax


Thissectiondocumentsthesyntaxofavailablecommandsinthevmrunutility.

Path to VMX File


VMwarestoresvirtualmachinesasapackagethatincludesthevirtualmachinesettingsfile(<vnname>.vmx) andthevirtualdisks.Whenrequired,youmustprovidethecompletepathtothe.vmxfile.Herearesome examplesofwherethe.vmxfilemightbelocated: VMwareServerdatastore:
[storage1]Win XP/Win XP.vmx

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

VMwareWorkstationforLinuxpath:
/home/<username>/VirtualMachines/Ubuntu/Ubuntu.vmx

VMware, Inc.

Using vmrun to Control Virtual Machines

Using vmrun Commands


Table 2listsvmruncommandsandparametersaccordingtotheirfunction.Parametersarelistedoneperline. Parametersenclosedinsquarebracketsareoptional.Theverticalbarindicatesakeywordchoice. Table 2. vmrun Commands and Parameters
Command Power Commands start (Teamsnotsupportedon VMwareServer.) Startsavirtualmachine(.vmxfile)orteam(.vmtmfile). Thedefaultguioptionstartsthemachineinteractively, whichisrequiredtodisplayaVMwareuserinterface. Thenoguioptionsuppressestheuserinterface, includingstartupdialogbox,toallownoninteractive scripting. Stopsavirtualmachine(.vmxfile)orteam(.vmtmfile). Usethesoftparametertopowerofftheguestafter runningshutdownscripts.Usethehardparameterto powerofftheguestwithoutrunningscripts,asifyou pressedthepowerbutton.Thedefaultistousethe powerTypespecifiedinthe.vmxfile,ifpresent. Resetsavirtualmachine(.vmxfile)orteam(.vmtmfile). Usethesoftparametertorunshutdownscriptsbefore rebootingtheguest.Usethehardparametertoreboot theguestwithoutrunningscripts,asifyoupressedthe resetbutton.ThedefaultistousethepowerType specifiedinthe.vmxfile,ifpresent. Suspendsavirtualmachine(.vmxfile)orteam(.vmtm) withoutshuttingdown,solocalworkcanresumelater. Thesoftparametersuspendstheguestafterrunning systemscripts.OnWindowsguests,thesescriptsrelease theIPaddress.OnLinuxguests,thescriptssuspend networking.Thehardparametersuspendstheguest withoutrunningthescripts.Thedefaultistousethe powerTypespecifiedinthe.vmxfile,ifpresent. Toresumevirtualmachineoperationaftersuspend,use thestartcommand.OnWindows,theIPaddressis retrieved.OnLinux,networkingisrestarted. pause unpause Snapshot Commands listSnapshots snapshot (VMwareServerdoesnot supportmultiplesnapshots.) Listsallsnapshotsinavirtualmachine(.vmxfile). Createsasnapshotofavirtualmachine(.vmxfile).For productssuchasWorkstationthatsupportmultiple snapshots,youmustprovidethesnapshotname. Becausetheforwardslashdefinespathnames,donot usetheslashcharacterinasnapshotname,becausethat makesitdifficulttospecifythesnapshotpathlater. deleteSnapshot (VMwareServeralways deletestherootsnapshot.) Removesasnapshotfromavirtualmachine(.vmxfile). ForproductssuchasWorkstationthatsupportmultiple snapshots,youmustprovidethesnapshotname. Thevirtualmachinemustbepoweredofforsuspended. Ifthissnapshothaschildren,theybecomechildrenof thedeletedsnapshotsparent,andsubsequentsnapshots continueasbeforefromtheendofthechain. <pathto.vmxfile> <snapshotname> <pathto.vmxfile> <pathto.vmxfile> <snapshotname> Pausesavirtualmachine(.vmxfile).Youcanusethis eithertopausereplay,ortopausenormaloperation. Resumesoperationofavirtualmachine(.vmxfile)from whereyoupausedreplayornormaloperation. <pathto.vmxfile> <pathto.vmxfile> <pathto.vmxor.vmtmfile> [gui |nogui ] Description Parameters

stop (Teamsnotsupportedon VMwareServer.)

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

reset (Teamsnotsupportedon VMwareServer.)

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

suspend (Teamsnotsupportedon VMwareServer.)

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

VMware, Inc.

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command revertToSnapshot (VMwareServeralways revertstotherootsnapshot.) Description Setsthevirtualmachinetoitsstateatsnapshottime. Ifasnapshothasauniquenamewithinavirtual machine,reverttothatsnapshotbyspecifyingthepath tothevirtualmachinesconfigurationfileandthe uniquesnapshotname. Ifseveralsnapshotshavethesamename,specifythe snapshotbyincludingafullpathnameforthesnapshot. Apathnameisaseriesofsnapshotnames,separatedby forwardslashcharacters(/).Eachnamespecifiesanew snapshotinthetree.Forexample,thepathname Snap1/Snap2identifiesasnapshotnamedSnap2that wastakenfromthestateofasnapshotnamedSnap1. Record and Replay Commands beginRecording (Recordingnotsupportedon VMwareServer.) endRecording beginReplay (Replaynotsupportedon VMwareServer.) Beginsrecordingarunningvirtualmachine(.vmxfile), storingactivityinthespecifiedsnapshotobject,with optionaldescription. Onlyonerecordingorreplaycanbeactiveatatime. Endstherecordingofavirtualmachine(.vmxfile)that isinprogress,andcloseitssnapshotobject. Beginsreplayingtherecordedactivityofapoweredoff virtualmachine(.vmxfile)fromasnapshotobject, poweringoffifnecessary. Onlyonerecordingorreplaycanbeactiveatatime. Youcanpausereplaywiththepausecommand,and resumereplaywiththeunpausecommand. endReplay Endsthereplayingofavirtualmachine(.vmxfile)that iscurrentlyunderway. <pathto.vmxfile> <pathto.vmxfile> <snapshotobjectname> [<description>] <pathto.vmxfile> <pathto.vmxfile> <snapshotobjectname> Parameters <pathto.vmxfile> <snapshotname> or <pathto.vmxfile> <snap1/snap2/snapN>

Guest Operating System Commands runProgramInGuest Runsaprogramintheguestoperatingsystem. The-noWaitoptionreturnsapromptimmediatelyafter theprogramstartsintheguest,ratherthanwaitingforit tofinish.Thisoptionisusefulforinteractiveprograms. The-activeWindowoptionensuresthattheWindows GUIisvisible,notminimized.IthasnoeffectonLinux. The-interactiveoptionforcesinteractiveguestlogin. ItisusefulforWindowsVistagueststomakethe programvisibleintheconsolewindow. Providethefullpathnameofaprogramaccessibletothe guest.VMwareToolsandvalidguestloginarerequired. Alsoprovidefullaccessiblepathnamesforanyfiles specifiedintheprogramarguments,whichareoptional accordingtorequirementsofthenamedprogram. runScriptInGuest Runsacommandscriptintheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. Theinterpreterpathisthecommandthatrunsthescript. Providethecompletetextofthescript,notafilename. setSharedFolderState (VMwareServerdoesnot supportsharedfolders.) Modifiesthewritabilitystateofafoldersharedbetween thehostandaguestvirtualmachine(.vmxfile). Thesharenameisamountpointintheguestfilesystem. Thepathtofolderistheexporteddirectoryonthehost. Asharedfoldercanbemadewritableorreadonly. Addsafoldertobesharedbetweenthehostandguest. Thesharenameisamountpointintheguestfilesystem. Thepathtofolderistheexporteddirectoryonthehost. <pathto.vmxfile> <interpreterpath> <scripttext> <pathto.vmxfile> <sharename> <pathtofolderonhost> writable |readonly <pathto.vmxfile> <sharename> <pathtofolderonhost> <pathto.vmxfile> [-noWait | -activeWindow | -interactive ] <programname> [<programarguments>]

addSharedFolder (VMwareServerdoesnot supportsharedfolders.)

VMware, Inc.

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command removeSharedFolder (VMwareServerdoesnot supportsharedfolders.) listProcessesInGuest Description Removesaguestvirtualmachinesaccesstoashared folderonthehost.Thesharenameisamountpointin theguestfilesystem. Listsallprocessesrunningintheguestoperating system.VMwareToolsandavalidguestloginare required. Stopsaspecifiedprocessintheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. TakeprocessIDfromthenumberlistedafterpid=inthe outputoflistProcessesInGuest. fileExistsInGuest Checkswhetherthespecifiedfileexistsintheguest operatingsystem.VMwareToolsandavalidguestlogin arerequired. Deletesaspecifiedfilefromtheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. Renamesormovesafileintheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. Specifythesourcename(original)beforethedestination (new). createDirectoryInGuest Createsthespecifieddirectoryintheguestoperating system.VMwareToolsandavalidguestloginare required. Deletesadirectoryfromtheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. Listsdirectorycontentsintheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. Copiesafilefromthehosttotheguestoperatingsystem. VMwareToolsandavalidguestloginarerequired. Specifythesourcefile(host)beforethedestinationfile (guest). copyFileFromGuestToHost Copiesafilefromtheguestoperatingsystemtothehost. VMwareToolsandavalidguestloginarerequired. Specifythesourcefile(guest)beforethedestinationfile (host). captureScreen Capturesthescreenofthevirtualmachinetoalocalfile. ThespecifiedoutputfileonthehostisinPNGformat. Avalidguestloginisrequired. writeVariable Writesavariableintothevirtualmachinestateorguest. Youcanseteitherruntimeconfigurationinthe.vmxfile, orenvironmentvariablesintheguestoperatingsystem. ThelatterrequiresVMwareToolsandavalidguest login.Providethevariablenameanditsvalue. Readsavariablefromthevirtualmachinestateorguest. Youcangeteitherruntimeconfigurationinthe.vmxfile, orenvironmentvariablesintheguestoperatingsystem. Thelatterrequiresavalidguestlogin. <pathto.vmxfile> [runtimeConfig | guestEnv ] <variablename> <variablevalue> <pathto.vmxfile> [runtimeConfig | guestEnv ] <variablename> <pathto.vmxfile> <pathtofileonguest> <pathto.vmxfile> <pathtofileonguest> <pathto.vmxfile> <originalfilename> <newfilename> <pathto.vmxfile> <directorypathonguest> <pathto.vmxfile> <directorypathonguest> <pathto.vmxfile> <directorypathonguest> <pathto.vmxfile> <filepathonhost> <filepathinguest> <pathto.vmxfile> <filepathinguest> <filepathonhost> <pathto.vmxfile> <outputpathonhost> Parameters <pathto.vmxfile> <sharename> <pathto.vmxfile>

killProcessInGuest

<pathto.vmxfile> <processID>

deleteFileInGuest

renameFileInGuest

deleteDirectoryInGuest

listDirectoryInGuest

copyFileFromHostToGuest

readVariable

Maintenance Commands list upgradevm Listsallrunningvirtualmachines. Upgradesavirtualmachinetothecurrentversionof virtualhardware.Hasnoeffectifalreadycurrent. None <pathto.vmxfile>

10

VMware, Inc.

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command installtools Description PreparestoinstallVMwareToolsintheguestoperating system.InWindowsguestswithautorunenabled,the VMwareToolsinstallerstartsbyitself.InLinuxguests withoutautorun,thiscommandconnectsthevirtual CDROMdrivetotheVMwareToolsISOimagesuitable fortheguest,buttheinstallerdoesnotstart.Youmust completetheinstallationwithadditionalmanualsteps, asdescribedinyourproductdocumentation. Registersavirtualmachine(.vmxfile),addingittothe hostsinventory.Pathformatdependsontheproduct. ForVMwareServer2.0,"[storage1] vm/vm.vmx" (startingwiththedatastore)istypical. Unregistersavirtualmachine(.vmxfile),removingit fromthehostsinventory.Pathformatdependsonthe product.ForServer2.0,"[storage1] vm/vm.vmx" (startingwiththedatastore)istypical. Createsacopyofthevirtualmachineandguest operatingsystem.Providethesource.vmxfilepath name,andthedestination.vmxfilepathname.Youcan createeitheranormalfullcloneoralinkedclone.If youwanttomaketheclonefromasnapshot,ratherthan fromthecurrentvirtualmachinestate,specifya snapshotname. Parameters <pathto.vmxfile>

register (Registrationnotsupported onVMwareWorkstation.) unregister (Registrationnotsupported onVMwareWorkstation.) clone (Cloningnotsupportedon VMwareServer.)

<pathto.vmxfile>

<pathto.vmxfile>

<pathto.vmxfile> <destination.vmxfilepath> full |linked [<snapshotname>]

VProbes Commands (VMwareServerdoesnot supportVProbes.) vprobeVersion vprobeLoad ShowstheVProbesversiononthevirtualmachine. LoadstheVProbesscriptonthevirtualmachine. DisablesallVProbesonthevirtualmachine. ListstheactiveVProbesonthevirtualmachine. ListsVProbesglobalvariablesonthevirtualmachine. <pathto.vmxfile> <pathto.vmxfile> <textofVProbesscript> vprobeReset vprobeListProbes vprobeListGlobals <pathto.vmxfile> <pathto.vmxfile> <pathto.vmxfile>

Disabling Dialog Boxes


WithvirtualmachinesthatrequireinputthroughaVMwareWorkstationdialogbox,thevmrunutilitymight timeoutandfail.TodisableWorkstationdialogboxes,insertthefollowinglineintotheconfigurationfile (.vmx)foravirtualmachine:
msg.autoAnswer = TRUE

Examples of Using vmrun


CommandlineexamplesbelowworkeitheronVMwareWorkstation(-Tws)orVMwareServer(Tserver). Youcanderivetheguestoperatingsystemtypeinexamplesbydistinguishing/forLinuxand\forWindows.

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

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

VMware, Inc.

11

Using vmrun to Control Virtual Machines

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

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

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

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

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

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

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

ForVMwareServerinstalledonWindowshosts,the-uuserisusuallyAdministrator,notroot.

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

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

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

Deletethesnapshot,specifyingitbyname:
vmrun -T ws deleteSnapshot /path/to/vm/Ubuntu/Ubuntu.vmx mySnapshot

Record and Replay Commands


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

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

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

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

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

12

VMware, Inc.

Using vmrun to Control Virtual Machines

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

Running Guest Applications


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

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

RunabatchscriptonaWindowsguest,usingcmd.exe/casacommandinterpreter:
vmrun -T ws -gu <user> -gp <pass> runProgramInGuest WinXP\WinXP.vmx cmd.exe "/c C:\runit.bat"

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

StartanXclockonaLinuxguest(requires-displayoptiontoappearontheconsole):
vmrun -T ws -gu <user> -gp <pass> runProgramInGuest Ubuntu/Ubuntu.vmx /usr/bin/xclock -display :0

Sameasabove,butimmediatelyreturntocommandlinecontrol:
vmrun -T ws -gu <user> -gp <pass> runProgramInGuest Ubuntu/Ubuntu.vmx -noWait /usr/bin/xclock -display :0

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

RunaprograminaLinuxvirtualmachineonVMwareServer:
vmrun -T server -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

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

RunaPerlscriptonaWindowsguesttoinsertDOSstylecarriagereturnsintoafile:
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

Guest-Host File Operations


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

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

Beforeusingsharedfolders,youmustenablethembyselectingVM>Settings>Options>SharedFolders> Enabledintheuserinterface.ToshareafolderonaWindowshostwithaparticularLinuxguest:
vmrun -T ws addSharedFolder Ubuntu\Ubuntu.vmx /mnt/hgfs/Share C:\Share

Sharedfoldersarewritablebydefault.Tomakeasharedfolderreadonly:
vmrun -T ws setSharedFolderState Ubuntu\Ubuntu.vmx /mnt/hgfs/Share C:\Share readonly

Tostopsharingthefolder:
vmrun -T ws removeSharedFolder Ubuntu\Ubuntu.vmx /mnt/hgfs/Share

VMware, Inc.

13

Using vmrun to Control Virtual Machines

Maintenance Commands
ListrunningvirtualmachinesonVMwareWorkstation:
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

RegisteranewvirtualmachineinstalledonVMwareServer:
vmrun -T server -h https://10.0.1.8/sdk -u root -p <pass> register "[storage1] RHEL5/RHEL5.vmx"

UnregisteranoldvirtualmachinegoingoutofserviceonVMwareServer:
vmrun -T server -h https://10.0.1.8/sdk -u root -p <pass> unregister "[storage1] RHEL3/RHEL3.vmx"

14

VMware, Inc.

You might also like