命令行模式启动VMWare虚拟机
工作中使用到在CentOS服务器中安装VMWare Workstation部署虚拟机,但服务器无显示器,故记录vmrun 帮助文档。
# vmrun 
vmrun version 1.17.0 build-16894299
Usage: vmrun [AUTHENTICATION-FLAGS] COMMAND [PARAMETERS]
AUTHENTICATION-FLAGS # 身份验证标志
--------------------
These must appear before the command and any command parameters. # 这些参数必须出现在命令和任何命令参数之前。
   -T <hostType> (ws|fusion||player)
   -vp <password for encrypted virtual machine> # 加密虚拟机的密码
   -gu <userName in guest OS> # 来宾操作系统中的用户名
   -gp <password in guest OS> # 来宾操作系统中的密码
# 电源相关命令			  	参数					说明
POWER COMMANDS           PARAMETERS           DESCRIPTION
--------------           ----------           -----------
start                    Path to vmx file     Start a VM or Team
                         [gui|nogui]
stop                     Path to vmx file     Stop a VM or Team
                         [hard|soft]
reset                    Path to vmx file     Reset a VM or Team
                         [hard|soft]
suspend                  Path to vmx file     Suspend a VM or Team
                         [hard|soft]
pause                    Path to vmx file     Pause a VM
unpause                  Path to vmx file     Unpause a VM
# 快照相关命令			  	参数					说明
SNAPSHOT COMMANDS        PARAMETERS           DESCRIPTION
-----------------        ----------           -----------
listSnapshots            Path to vmx file     List all snapshots in a VM
                         [showTree]
snapshot                 Path to vmx file     Create a snapshot of a VM
                         Snapshot name
deleteSnapshot           Path to vmx file     Remove a snapshot from a VM
                         Snapshot name
                         [andDeleteChildren]
revertToSnapshot         Path to vmx file     Set VM state to a snapshot
                         Snapshot name
GUEST OS COMMANDS        PARAMETERS           DESCRIPTION
-----------------        ----------           -----------
runProgramInGuest        Path to vmx file     Run a program in Guest OS
                         [-noWait]
                         [-activeWindow]
                         [-interactive]
                         Complete-Path-To-Program
                         [Program arguments]
fileExistsInGuest        Path to vmx file     Check if a file exists in Guest OS
                         Path to file in guest
directoryExistsInGuest   Path to vmx file     Check if a directory exists in Guest OS
                         Path to directory in guest
setSharedFolderState     Path to vmx file     Modify a Host-Guest shared folder
                         Share name
                         Host path
                         writable | readonly
addSharedFolder          Path to vmx file     Add a Host-Guest shared folder
                         Share name
                         New host path
removeSharedFolder       Path to vmx file     Remove a Host-Guest shared folder
                         Share name
enableSharedFolders      Path to vmx file     Enable shared folders in Guest
                         [runtime]
disableSharedFolders     Path to vmx file     Disable shared folders in Guest
                         [runtime]
listProcessesInGuest     Path to vmx file     List running processes in Guest OS
killProcessInGuest       Path to vmx file     Kill a process in Guest OS
                         process id
runScriptInGuest         Path to vmx file     Run a script in Guest OS
                         [-noWait]
                         [-activeWindow]
                         [-interactive]
                         Interpreter path
                         Script text
deleteFileInGuest        Path to vmx file     Delete a file in Guest OS
                         Path in guest            
createDirectoryInGuest   Path to vmx file     Create a directory in Guest OS
                         Directory path in guest  
deleteDirectoryInGuest   Path to vmx file     Delete a directory in Guest OS
                         Directory path in guest  
CreateTempfileInGuest    Path to vmx file     Create a temporary file in Guest OS
listDirectoryInGuest     Path to vmx file     List a directory in Guest OS
                         Directory path in guest
CopyFileFromHostToGuest  Path to vmx file     Copy a file from host OS to guest OS
                         Path on host
                         Path in guest
CopyFileFromGuestToHost  Path to vmx file     Copy a file from guest OS to host OS
                         Path in guest
                         Path on host
renameFileInGuest        Path to vmx file     Rename a file in Guest OS
                         Original name
                         New name
typeKeystrokesInGuest    Path to vmx file     Type Keystrokes in Guest OS
                         keystroke string
connectNamedDevice       Path to vmx file     Connect the named device in the Guest OS
                         device name
disconnectNamedDevice    Path to vmx file     Disconnect the named device in the Guest OS
                         device name
captureScreen            Path to vmx file     Capture the screen of the VM to a local file
                         Path on host
writeVariable            Path to vmx file     Write a variable in the VM state
                         [runtimeConfig|guestEnv|guestVar]
                         variable name
                         variable value
readVariable             Path to vmx file     Read a variable in the VM state
                         [runtimeConfig|guestEnv|guestVar]
                         variable name
getGuestIPAddress        Path to vmx file     Gets the IP address of the guest
                         [-wait]
# 通用命令				  	参数					说明
GENERAL COMMANDS         PARAMETERS           DESCRIPTION
----------------         ----------           -----------
list                                          List all running VMs
upgradevm                Path to vmx file     Upgrade VM file format, virtual hw
installTools             Path to vmx file     Install Tools in Guest
checkToolsState          Path to vmx file     Check the current Tools state
deleteVM                 Path to vmx file     Delete a VM
clone                    Path to vmx file     Create a copy of the VM
                         Path to destination vmx file
                         full|linked
                         [-snapshot=Snapshot Name]
                         [-cloneName=Name]
Template VM COMMANDS     PARAMETERS           DESCRIPTION
---------------------    ----------           -----------
downloadPhotonVM         Path for new VM      Download Photon VM
Examples:
# 在Windows主机上启动带有工作站的虚拟机
Starting a virtual machine with Workstation on a Windows host
   vmrun -T ws start "c:\my VMs\myVM.vmx"
# 在带有工作站的虚拟机上运行程序,在带有Windows来宾的Windows主机上运行
Running a program in a virtual machine with Workstation on a Windows host with Windows guest
   vmrun -T ws -gu guestUser -gp guestPassword runProgramInGuest "c:\my VMs\myVM.vmx" "c:\Program Files\myProgram.exe"
# 在Windows主机上创建带有工作站的虚拟机的快照
Creating a snapshot of a virtual machine with Workstation on a Windows host
   vmrun -T ws snapshot "c:\my VMs\myVM.vmx" mySnapshot
# 还原到Windows主机上带有工作站的快照
Reverting to a snapshot with Workstation on a Windows host
   vmrun -T ws revertToSnapshot "c:\my VMs\myVM.vmx" mySnapshot
# 在Windows主机上删除带有工作站的快照
Deleting a snapshot with Workstation on a Windows host
   vmrun -T ws deleteSnapshot "c:\my VMs\myVM.vmx" mySnapshot
# 在Windows主机上启用工作站共享文件夹
Enabling Shared Folders with Workstation on a Windows host
   vmrun -T ws enableSharedFolders "c:\my VMs\myVM.vmx"
可能用到的命令
# 开启虚拟机
vmrun start "/path/to/VMX file/xx.vmx" nogui
# 关闭虚拟机
vmrun stop "/path/to/VMX file/xx.vmx"
# 查看所有快照 
vmrun listSnapshots "/path/to/VMX file/xx.vmx" showTree
# 保存快照,snapshot_name为任意字符串
vmrun snapshot "/path/to/VMX file/xx.vmx" snapshot_name
# 恢复虚拟机至某快照,snapshot_name为所有快照结果中的一个名字
vmrun revertToSnapshot  "/path/to/VMX file/xx.vmx" snapshot_name
# 其他命令参看上边帮助文档
- 作者:xmlwch
 - 原文链接:https://m730.xmlwch.cn/2022/03/28/chlinux/linux-comm-vmrun.html
 - 版权声明:本作品采用 知识共享 署名-相同方式共享 4.0 国际(CC BY-SA 4.0)许可协议 进行许可,转载无需与我联系,但请注明出处。