Vous êtes sur la page 1sur 16

Using vmrun to Control Virtual Machines

VMware Workstation 6.5, VMware Fusion 2.0, and VMware Server 2.0

Using vmrun to Control Virtual Machines

Using vmrun to Control Virtual Machines


Item: EN-000068-02

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

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, 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.

Contents

AboutThisBook

UsingvmruntoControlVirtualMachines

AboutthevmrunUtility 5
PowerCommands 5
SnapshotCommands 5
RecordandReplayCommands 5
GuestOperatingSystemCommands 6
MaintenanceCommands 6
VProbesCommands 6
SettingUpvmrunonWindows 6
SettingUpvmrunonLinux 6
SettingUpvmrunonMacOSX 7
FlagstoSpecifyVirtualMachineType 7
VirtualMachineRunSyntax 7
PathtoVMXFile 8
UsingvmrunCommands 8
DisablingDialogBoxes 11
ExamplesofUsingvmrun 12
RebootCommands 12
PowerCommands 12
SnapshotCommands 12
RecordandReplayCommands 13
RunningGuestApplications 13
GuestHostFileOperations 14
MaintenanceCommands 14

VMware, Inc.

Virtual Disk Manager Users Guide

VMware, Inc.

About This Book

Thismanual,UsingvmruntoControlVirtualMachines,documentsthevmrunutility,whichhelpsyoumanage
thecollectionofvirtualmachinesonaVMwarehost.

Revision History
Thisbookisrevisedwitheachreleaseoftheproductorwhennecessary.Arevisedversioncancontainminor
ormajorchanges.Table 1summarizesthesignificantchangesineachversionofthisguide.
Table 1. Revision History
Revision

Description

20080623

DraftofthismanualfortheVMwareServer2.0RC1andWorkstation6.5Beta2releases.

20080724

InitialreleaseincludingsupportforVMwareFusiononIntelbasedMacintoshOSXhosts.

20080815

RevisionwithadditionalexamplesforVMwareServer2.0RC2andWorkstation6.5RC.

20081231

IncludedadviceaboutnullinterpreterforRunScriptInGuestonWindows.

Intended Audience
Thisbookisintendedfordevelopersandsystemadministratorswhowanttocontrolvirtualmachineson
variousplatforms,includingVMwareWorkstation,VMwareFusion,andVMwareServer.

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://communities.vmware.com/community/developer.

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

VMware, Inc.

Using vmrun to Control Virtual Machines

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

Youcanusethevmruncommandlineutilitytocontrolspecificvirtualmachines,orteamsofvirtualmachines.
ThevmrunutilityisavailableonanyVMwareproductthatincludestheVIXAPIlibraries,orwhenthelibraries
areseparatelyinstalled.Thischaptercontainsthefollowingsections:

AboutthevmrunUtilityonpage 5

SettingUpvmrunonWindowsonpage 6

SettingUpvmrunonLinuxonpage 6

SettingUpvmrunonMacOSXonpage 7

FlagstoSpecifyVirtualMachineTypeonpage 7

VirtualMachineRunSyntaxonpage 7

ExamplesofUsingvmrunonpage 12

About the vmrun Utility


ThevmrunutilityrunsonanyVMwareplatformwithVIXlibrariesinstalled,includingVMwareWorkstation,
VMwareFusion,andVMwareServer.Forinformationaboutthevariousfacilitiesthatvmruncontrols,seethe
userdocumentationforyourproduct.
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.

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

Inacommandorterminalwindow,typevmruntoseecommandlineoptions.

ContinuewithFlagstoSpecifyVirtualMachineTypeonpage 7.

VMware, Inc.

Using vmrun to Control Virtual Machines

Setting Up vmrun on Mac OS X


To use the vmrun utility on a Macintosh
1

InaTerminalwindow,addtheVMwareFusiondirectorytoyoursystempath:
export PATH="$PATH:/Library/Application Support/VMware Fusion"

IntheTerminalwindow,typevmruntoseecommandlineoptions.

ContinuewithFlagstoSpecifyVirtualMachineTypeonpage 7.

Flags to Specify Virtual Machine Type


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

Insyntaxexamples,optionsenclosedinanglebracketsindicatevariablesthatyoufillin.OnVMware
WorkstationandVMwareFusion,vmruncontrolsguestoperatingsystemsonthelocalhost,soyouneednot
specifyaremotehostnameorport.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

ForVMwareWorkstationandVMwareFusion,usethe-Tflagasfollows:
vmrun -T ws
vmrun -T fusion

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

NOTEOnVMwareWorkstationandVMwareFusion,starting(poweringon)avirtualmachinewiththe
defaultguioptionrequiresawindowsystem(userinterface)toberunningonthehost.VMwareServerdoes
notimposethisrequirement.
VMwareServerdoesnotsupportteams,sharedfolders,cloning,recordandreplay,ormultiplesnapshots.
Whenyoutrytocreateasecondsnapshot,theUIasksifyouwanttooverwriteyourexistingsnapshot.
VMwareFusiondoesnotsupportsnapshottrees.

Virtual Machine Run Syntax


Thissectiondocumentsthesyntaxofavailablecommandsinthevmrunutility.

VMware, Inc.

Using vmrun to Control Virtual Machines

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

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

Using vmrun Commands


Table 2listsvmruncommandsandparametersaccordingtotheirfunction.Parametersarelistedoneperline.
Parametersenclosedinsquarebracketsareoptional.Theverticalbarindicatesakeywordchoice.
Table 2. vmrun Commands and Parameters
Command

Description

Parameters

Power Commands
start
(Teamsnotsupportedon
VMwareServerandVMware
Fusion.)

stop
(Teamsnotsupportedon
VMwareServeroron
VMwareFusion.)

reset
(Teamsnotsupportedon
VMwareServeroron
VMwareFusion.)

suspend
(Teamsnotsupportedon
VMwareServeroron
VMwareFusion.)

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.

<pathto.vmxor.vmtmfile>
[gui |nogui ]

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

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

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

Toresumevirtualmachineoperationaftersuspend,use
thestartcommand.OnWindows,theIPaddressis
retrieved.OnLinux,networkingisrestarted.

pause

Pausesavirtualmachine(.vmxfile).Youcanusethis
eithertopausereplay,ortopausenormaloperation.

<pathto.vmxfile>

unpause

Resumesoperationofavirtualmachine(.vmxfile)from
whereyoupausedreplayornormaloperation.

<pathto.vmxfile>

VMware, Inc.

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command

Description

Parameters

listSnapshots

Listsallsnapshotsinavirtualmachine(.vmxfile).

<pathto.vmxfile>

snapshot

Createsasnapshotofavirtualmachine(.vmxfile).For
productssuchasWorkstationthatsupportmultiple
snapshots,youmustprovidethesnapshotname.

<snapshotname>

Snapshot Commands

(VMwareServerdoesnot
supportmultiplesnapshots.
VMwareFusiondoesnot
supportsnapshottrees.)
deleteSnapshot
(VMwareServeralways
deletestherootsnapshot.)

<pathto.vmxfile>

Becausetheforwardslashdefinespathnames,donot
usetheslashcharacterinasnapshotname,becausethat
makesitdifficulttospecifythesnapshotpathlater.
Removesasnapshotfromavirtualmachine(.vmxfile).
ForproductssuchasWorkstationthatsupportmultiple
snapshots,youmustprovidethesnapshotname.

<pathto.vmxfile>
<snapshotname>

Thevirtualmachinemustbepoweredofforsuspended.
Ifthissnapshothaschildren,theybecomechildrenof
thedeletedsnapshotsparent,andsubsequentsnapshots
continueasbeforefromtheendofthechain.
revertToSnapshot

Setsthevirtualmachinetoitsstateatsnapshottime.

<pathto.vmxfile>

(VMwareServeralways
revertstotherootsnapshot.)

Ifasnapshothasauniquenamewithinavirtual
machine,reverttothatsnapshotbyspecifyingthepath
tothevirtualmachinesconfigurationfileandthe
uniquesnapshotname.

<snapshotname>

Ifseveralsnapshotshavethesamename,specifythe
snapshotbyincludingafullpathnameforthesnapshot.
Apathnameisaseriesofsnapshotnames,separatedby
forwardslashcharacters(/).Eachnamespecifiesanew
snapshotinthetree.Forexample,thepathname
Snap1/Snap2identifiesasnapshotnamedSnap2that
wastakenfromthestateofasnapshotnamedSnap1.

or
<pathto.vmxfile>
<snap1/snap2/snapN>

Record and Replay Commands


beginRecording
(Recordingnotsupportedon
VMwareServeroron
VMwareFusion.)

Beginsrecordingarunningvirtualmachine(.vmxfile),
storingactivityinthespecifiedsnapshotobject,with
optionaldescription.
Onlyonerecordingorreplaycanbeactiveatatime.

endRecording

Endstherecordingofavirtualmachine(.vmxfile)that
isinprogress,andcloseitssnapshotobject.

beginReplay

Beginsreplayingtherecordedactivityofapoweredoff
virtualmachine(.vmxfile)fromasnapshotobject,
poweringoffifnecessary.

(Replaynotsupportedon
VMwareServeroron
VMwareFusion.)

<pathto.vmxfile>
<snapshotobjectname>
[<description>]
<pathto.vmxfile>
<pathto.vmxfile>
<snapshotobjectname>

Onlyonerecordingorreplaycanbeactiveatatime.
Youcanpausereplaywiththepausecommand,and
resumereplaywiththeunpausecommand.

endReplay

Endsthereplayingofavirtualmachine(.vmxfile)that
iscurrentlyunderway.

<pathto.vmxfile>

Guest Operating System Commands


writeVariable

Writesavariableintothevirtualmachinestateorguest.
Youcanseteitherruntimeconfigurationinthe.vmxfile,
orenvironmentvariablesintheguestoperatingsystem.
ThelatterrequiresVMwareToolsandavalidguestlogin
(forLinuxguests,settingguestEnvrequiresrootlogin).
Providethevariablenameanditsvalue.

readVariable

VMware, Inc.

Readsavariablefromthevirtualmachinestateorguest.
Youcangeteitherruntimeconfigurationinthe.vmxfile,
orenvironmentvariablesintheguestoperatingsystem.
Thelatterrequiresavalidguestlogin.

<pathto.vmxfile>
[runtimeConfig |
guestEnv ]
<variablename>
<variablevalue>
<pathto.vmxfile>
[runtimeConfig |
guestEnv ]
<variablename>

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command
runProgramInGuest

Description

Parameters

Runsaprogramintheguestoperatingsystem.

<pathto.vmxfile>

The-noWaitoptionreturnsapromptimmediatelyafter
theprogramstartsintheguest,ratherthanwaitingforit
tofinish.Thisoptionisusefulforinteractiveprograms.

[-noWait |
-activeWindow |
-interactive ]

The-activeWindowoptionensuresthattheWindows
GUIisvisible,notminimized.IthasnoeffectonLinux.

<programname>
[<programarguments>]

The-interactiveoptionforcesinteractiveguestlogin.
ItisusefulforWindowsVistagueststomakethe
programvisibleintheconsolewindow.
Providethefullpathnameofaprogramaccessibletothe
guest.VMwareToolsandvalidguestloginarerequired.
Alsoprovidefullaccessiblepathnamesforanyfiles
specifiedintheprogramarguments,whichareoptional
accordingtorequirementsofthenamedprogram.
runScriptInGuest

Runsacommandscriptintheguestoperatingsystem.
VMwareToolsandavalidguestloginarerequired.
Theinterpreterpathisthecommandthatrunsthescript.
Providethecompletetextofthescript,notafilename.

setSharedFolderState
(VMwareServerdoesnot
supportsharedfolders.)

addSharedFolder
(VMwareServerdoesnot
supportsharedfolders.)
removeSharedFolder
(VMwareServerdoesnot
supportsharedfolders.)

Modifiesthewritabilitystateofafoldersharedbetween
thehostandaguestvirtualmachine(.vmxfile).
Thesharenameisamountpointintheguestfilesystem.
Thepathtofolderistheexporteddirectoryonthehost.
Asharedfoldercanbemadewritableorreadonly.

<pathto.vmxfile>
<interpreterpath>
<scripttext>
<pathto.vmxfile>
<sharename>
<pathtofolderonhost>
writable |readonly
<pathto.vmxfile>

Addsafoldertobesharedbetweenthehostandguest.
Thesharenameisamountpointintheguestfilesystem.
Thepathtofolderistheexporteddirectoryonthehost.

<sharename>

Removesaguestvirtualmachinesaccesstoashared
folderonthehost.Thesharenameisamountpointin
theguestfilesystem.

<sharename>

listProcessesInGuest

Listsallprocessesrunningintheguestoperating
system.VMwareToolsandavalidguestloginare
required.

killProcessInGuest

Stopsaspecifiedprocessintheguestoperatingsystem.
VMwareToolsandavalidguestloginarerequired.

<pathtofolderonhost>
<pathto.vmxfile>

<pathto.vmxfile>

<pathto.vmxfile>
<processID>

TakeprocessIDfromthenumberlistedafterpid=inthe
outputoflistProcessesInGuest.
fileExistsInGuest

deleteFileInGuest

renameFileInGuest

createDirectoryInGuest

deleteDirectoryInGuest

listDirectoryInGuest

10

Checkswhetherthespecifiedfileexistsintheguest
operatingsystem.VMwareToolsandavalidguestlogin
arerequired.

<pathto.vmxfile>
<pathtofileonguest>

Deletesaspecifiedfilefromtheguestoperatingsystem.
VMwareToolsandavalidguestloginarerequired.

<pathtofileonguest>

<pathto.vmxfile>

Renamesormovesafileintheguestoperatingsystem.
VMwareToolsandavalidguestloginarerequired.

<originalfilename>

<pathto.vmxfile>

Specifythesourcename(original)beforethedestination
(new).

<newfilename>

Createsthespecifieddirectoryintheguestoperating
system.VMwareToolsandavalidguestloginare
required.

<directorypathonguest>

<pathto.vmxfile>

<pathto.vmxfile>

Deletesadirectoryfromtheguestoperatingsystem.
VMwareToolsandavalidguestloginarerequired.

<directorypathonguest>

Listsdirectorycontentsintheguestoperatingsystem.
VMwareToolsandavalidguestloginarerequired.

<directorypathonguest>

<pathto.vmxfile>

VMware, Inc.

Using vmrun to Control Virtual Machines

Table 2. vmrun Commands and Parameters (Continued)


Command

Description

Parameters

copyFileFromHostToGuest

Copiesafilefromthehosttotheguestoperatingsystem.
VMwareToolsandavalidguestloginarerequired.

<filepathonhost>

Specifythesourcefile(host)beforethedestinationfile
(guest).
copyFileFromGuestToHost

Copiesafilefromtheguestoperatingsystemtothehost.
VMwareToolsandavalidguestloginarerequired.
Specifythesourcefile(guest)beforethedestinationfile
(host).

captureScreen

Capturesthescreenofthevirtualmachinetoalocalfile.
ThespecifiedoutputfileonthehostisinPNGformat.

<pathto.vmxfile>
<filepathinguest>
<pathto.vmxfile>
<filepathinguest>
<filepathonhost>
<pathto.vmxfile>
<outputpathonhost>

Avalidguestloginisrequired.
Maintenance Commands
list

Listsallrunningvirtualmachines.

None

upgradevm

Upgradesavirtualmachinetothecurrentversionof
virtualhardware.Hasnoeffectifalreadycurrent.

<pathto.vmxfile>

installtools

PreparestoinstallVMwareToolsintheguestoperating
system.InWindowsguestswithautorunenabled,the
VMwareToolsinstallerstartsbyitself.InLinuxguests
withoutautorun,thiscommandconnectsthevirtual
CDROMdrivetotheVMwareToolsISOimagesuitable
fortheguest,buttheinstallerdoesnotstart.Youmust
completetheinstallationwithadditionalmanualsteps,
asdescribedinyourproductdocumentation.

<pathto.vmxfile>

register

Registersavirtualmachine(.vmxfile),addingittothe
hostsinventory.Pathformatdependsontheproduct.
ForVMwareServer2.0,"[storage1] vm/vm.vmx"
(startingwiththedatastore)istypical.

<pathto.vmxfile>

Unregistersavirtualmachine(.vmxfile),removingit
fromthehostsinventory.Pathformatdependsonthe
product.ForServer2.0,"[storage1] vm/vm.vmx"
(startingwiththedatastore)istypical.

<pathto.vmxfile>

(Registrationnotsupported
onVMwareWorkstationor
onVMwareFusion.)
unregister
(Registrationnotsupported
onVMwareWorkstationor
onVMwareFusion.)
clone
(Cloningnotsupportedon
VMwareServeroron
VMwareFusion.)

Createsacopyofthevirtualmachineandguest.Provide
thesource.vmxfilepathname,andthedestination.vmx
filepathname.Youcancreateeitheranormalfull
cloneoralinkedclone.Ifyouwanttomaketheclone
fromasnapshot,ratherthanfromthecurrentvirtual
machinestate,specifyasnapshotname.

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

VProbes Commands
(VMwareServerdoesnotsupportVProbes.)
vprobeVersion

ShowstheVProbesversiononthevirtualmachine.

vprobeLoad

LoadstheVProbesscriptonthevirtualmachine.

<pathto.vmxfile>
<pathto.vmxfile>
<textofVProbesscript>

vprobeReset

DisablesallVProbesonthevirtualmachine.

<pathto.vmxfile>

vprobeListProbes

ListstheactiveVProbesonthevirtualmachine.

<pathto.vmxfile>

vprobeListGlobals

ListsVProbesglobalvariablesonthevirtualmachine.

<pathto.vmxfile>

Disabling Dialog Boxes


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

VMware, Inc.

11

Using vmrun to Control Virtual Machines

Examples of Using vmrun


CommandlineexamplesbelowworkeitheronVMwareWorkstation(-Tws),VMwareFusion(-Tfusion),or
VMwareServer(Tserver).Youcanderivetheguestoperatingsystemtypeinexamplesbydistinguishing/for
Linuxand\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

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

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
CreateasnapshotofavirtualmachinewithVMwareWorkstationonaLinuxhostorVMwareFusion:
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
12

VMware, Inc.

Using vmrun to Control Virtual Machines

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

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,usingPerlasthescriptinterpreter:
vmrun -T ws -gu <user> -gp <pass> runScriptInGuest Win2k\Win2k.vmx C:\perl\perl.exe C:\script.pl

Runabatchscriptandkeeprunningafterwards.Tousecmd.exeonWindows,specifyinterpreterasnull:
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(requires-displayoptiontoappearontheconsole):
vmrun -gu <user> -gp <pass> runProgramInGuest SUSE/SUSE.vmx /usr/bin/xclock -display :0

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

ForLinuxapplicationsthatdonotacceptthe-displaycommandlineoption,firstsettheguestenvironment
forthevmware-guestdprocess,whichrequiresrootpermission:
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,andkilltheprocessnumbered8192:
vmrun -T ws -gu <user> -gp <pass> listProcessesInGuest Ubuntu/Ubuntu.vmx
vmrun -T ws -gu <user> -gp <pass> killProcessesInGuest 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

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

VMware, Inc.

13

Using vmrun to Control Virtual Machines

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

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

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"

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

14

VMware, Inc.

Vous aimerez peut-être aussi