working

记录工作中的点滴

[VirtualBox]命令行下控制虚拟机

//列出所有虚拟机

VBoxManage.exe list vms

-------------------------------------------------

"CentOS63" {30a7d30e-7f14-4cd3-b2dd-bd371825aceb}

"BT5-R3" {144753b5-2207-4799-9c8a-76003d602e29}

"CentOS63-small" {2e2ef027-9ae1-4120-bc34-1ba6205a7632}

-------------------------------------------------


//列出正在运行的虚拟机

VBoxManage.exe list runningvms

-------------------------------------------------

"CentOS63" {30a7d30e-7f14-4cd3-b2dd-bd371825aceb}

-------------------------------------------------


//界面模式打开虚拟机,使用名称和uuid都可以

VBoxManage.exe startvm "BT5-R3" --type gui

-------------------------------------------------

Waiting for VM "BT5-R3" to power on...

VM "BT5-R3" has been successfully started.

-------------------------------------------------


//后台打开虚拟机

VBoxManage.exe startvm "BT5-R3" --type headless

-------------------------------------------------

Waiting for VM "BT5-R3" to power on...

VM "BT5-R3" has been successfully started.

-------------------------------------------------


//关闭虚拟机,非正常关机

VBoxManage.exe controlvm "BT5-R3" poweroff

-------------------------------------------------

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

-------------------------------------------------


//关闭虚拟机,正常关机

VBoxManage.exe controlvm "BT5-R3" acpipowerbutton

-------------------------------------------------

linux执行没反应

-------------------------------------------------


//列举虚拟机相关信息

VBoxManage.exe guestproperty enumerate "BT5-R3"

-------------------------------------------------

Name: /VirtualBox/GuestInfo/OS/Product, value: Linux, timestamp: 1361331892171875000, flags: 

Name: /VirtualBox/GuestInfo/Net/0/V4/IP, value: 10.101.1.83, timestamp: 1361331892187500003, flags: 

Name: /VirtualBox/HostInfo/GUI/LanguageID, value: zh_CN, timestamp: 1356917913530625000, flags: 

Name: /VirtualBox/GuestInfo/Net/0/MAC, value: 0800275BDC5D, timestamp: 1361331892203125001, flags: 

Name: /VirtualBox/GuestInfo/OS/ServicePack, value: , timestamp: 1361331892171875003, flags: 

Name: /VirtualBox/HostInfo/VBoxVerExt, value: 4.2.6, timestamp: 1361331843937500003, flags: TRANSIENT, RDONLYGUEST

Name: /VirtualBox/GuestAdd/Vbgl/Video/SavedMode, value: 797x482x32, timestamp: 1353304299440750000, flags: 

Name: /VirtualBox/GuestInfo/Net/0/V4/Netmask, value: 255.255.254.0, timestamp: 1361331892203125000, flags: 

Name: /VirtualBox/GuestInfo/OS/Version, value: #1 SMP Fri Feb 17 10:40:05 EST 2012, timestamp: 1361331892171875002, flags: 

Name: /VirtualBox/GuestAdd/VersionExt, value: 4.2.0_RC1, timestamp: 1361331892171875005, flags: 

Name: /VirtualBox/GuestAdd/Revision, value: 80014, timestamp: 1361331892187500000, flags: 

Name: /VirtualBox/HostGuest/SysprepExec, value: , timestamp: 1361331843937500000, flags: TRANSIENT, RDONLYGUEST

Name: /VirtualBox/GuestInfo/OS/LoggedInUsers, value: 0, timestamp: 1361331892187500001, flags: TRANSIENT, TRANSRESET

Name: /VirtualBox/GuestInfo/Net/0/Status, value: Up, timestamp: 1361331892203125002, flags: 

Name: /VirtualBox/HostGuest/SysprepArgs, value: , timestamp: 1361331843937500001, flags: TRANSIENT, RDONLYGUEST

Name: /VirtualBox/GuestAdd/Version, value: 4.2.0, timestamp: 1361331892171875004, flags: 

Name: /VirtualBox/HostInfo/VBoxRev, value: 82870, timestamp: 1361331843937500004, flags: TRANSIENT, RDONLYGUEST

Name: /VirtualBox/GuestInfo/Net/0/V4/Broadcast, value: 10.101.1.255, timestamp: 1361331892187500004, flags: 

Name: /VirtualBox/HostInfo/VBoxVer, value: 4.2.6, timestamp: 1361331843937500002, flags: TRANSIENT, RDONLYGUEST

Name: /VirtualBox/GuestInfo/OS/LoggedInUsersList, value: root, timestamp: 1361331583921875000, flags: TRANSIENT, TRANSRESET

Name: /VirtualBox/GuestInfo/Net/Count, value: 1, timestamp: 1361332652046875000, flags: 

Name: /VirtualBox/GuestInfo/OS/Release, value: 3.2.6, timestamp: 1361331892171875001, flags: 

Name: /VirtualBox/GuestInfo/OS/NoLoggedInUsers, value: true, timestamp: 1361331892187500002, flags: TRANSIENT, TRANSRESET

Name: /VirtualBox/GuestAdd/HostVerLastChecked, value: 4.2.0, timestamp: 1353304332143875000, flags: 

-------------------------------------------------


//列举虚拟机相关信息

VBoxManage.exe guestproperty get "BT5-R3" /VirtualBox/GuestInfo/Net/0/V4/IP

-------------------------------------------------

Value: 10.101.1.83

-------------------------------------------------


//执行命令

VBoxManage.exe guestcontrol "BT5-R3" execute --image "/bin/ls" --username root --password toor --wait-exit --wait-stdout -- -l /usr

  //配置网络

VBoxManage.exe guestcontrol "CentOS63" execute --image "/sbin/ifconfig" --username root --password 1q2w3e --wait-exit --wait-stdout

  //重启

VBoxManage.exe guestcontrol "CentOS63" execute --image "/usr/bin/reboot" --username root --password 1q2w3e --wait-exit --wait-stdout --wait-stderr

  //关机

VBoxManage.exe guestcontrol "CentOS63" execute --image "/usr/bin/halt" --username root --password 1q2w3e --wait-exit --wait-stdout --wait-stderr


评论