VirtualBox 虚拟机后台运行方法

怎么用VirtualBox后台运行?~
-

VirtualBox 这个虚拟机我第一次使用!~
对他不是很熟悉,配置完成后发现不能后台运行 每次启动都会有界面,对于想要模拟集群的我来说很麻烦~!
我经过查阅资料发现 可以只用 VBoxManage来启动!~
查看help

VBoxManage startvm |
[--type gui|sdl|headless]
可见他有三个启动模式 分别是 gui 界面
sdl 是什么?,启动就报错
资料说 headless启动没有界面
于是 试着运行headless模式,果然没有界面,只不过有个黑色的框框,恶心呀!~
以前有过VBS后台运行程序的经验
DIM objShell
set objShell=wscript.createObject("wscript.shell")
iReturn=objShell.Run("pldev.bat /start", 0, TRUE)
这样就 可以后台运行
那么我试着这样执行
DIM objShell
set objShell=wscript.createObject("wscript.shell")
iReturn=objShell.Run("VBoxManage startvm hadoop -type headless", 0, TRUE)

/* */
结果呢还是有个黑框框,为什么不能隐藏呢?
我多次实验发现原来VBoxManage 在使用headless模式启动的时候实际上是弹出了另一个程序,是弹出!~
所以我的VBS隐藏了VBoxManage 没有隐藏他的弹出程序!~
我试着直接调用他的弹出程序VBoxHeadless.exe,然后我运行help
内容来自dedecms

C:\Users\IXR>VBoxHeadless
Oracle VM VirtualBox Headless Interface 4.0.8
(C) 2008-2011 Oracle Corporation
All rights reserved.
Usage:
-s, -startvm, --startvm Start given VM (required argument)
-v, -vrde, --vrde on|off|config Enable (default) or disable the VRDE
server or don't change the setting
-e, -vrdeproperty, --vrdeproperty Set a VRDE property:
"TCP/Ports" - comma-separated list of p
orts
the VRDE server can bind to. Use a dash
between
two port numbers to specify a range
"TCP/Address" - interface IP the VRDE s
erver
will bind to
-c, -capture, --capture Record the VM screen output to a file
-w, --width Frame width when recording
-h, --height Frame height when recording
-r, --bitrate Recording bit rate when recording
-f, --filename File name when recording. The codec
used will be chosen based on the
file extension
没错 他和 VBoxManage 一样有 startvm 这样可以理解了!~哈哈
于是我修改VBS
DIM objShell
set objShell=wscript.createObject("wscript.shell")
内容来自dedecms

iReturn=objShell.Run "VBoxHeadless -startvm hadoop", 0, TRUE
(win7中Run后不用括号)
保存,运行start.vbs 哇!~ 没有任何反映 看进程 有了 VBoxHeadless
ping 虚拟机
C:\Users\IXR>ping 10.0.0.100
正在 Ping 10.0.0.100 具有 32 字节的数据:
来自 10.0.0.100 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.100 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.100 的回复: 字节=32 时间<1ms TTL=64
启动了,呵呵 ssh连接上吧!~


___________________________________________

VirtualBox 虚拟机后台运行方法2010年08月31日 20:29KVM默认将虚拟机

放入后台运行,即使关闭窗口也不会关闭虚拟机,这个特性非常好,而virtualbox 默认却不能,有时候我们可能会重启X,这时不得不关闭虚拟机,如果能让virtualbox也放入后台运行,将会方便不少,下面简单介绍下 VBoxManage的简单命令来实现这一功能
首先用图形创建一个虚拟机,当然使用VBoxManage也可以创建,只不过相对繁琐,不建议么操 作.
创建完毕后使用如下命令启动虚拟机即可
代码:VBoxManage startvm -type vrdp
如果要连接虚拟机,只需要输入
代码:rdesktop 127.0.0.1:3389
即可
如果要指定分辨率并且打开声 音,输入
代码:rdesktop 127.0.0.1:3389 -g 800x600 -r sound:remote
下面列举一些 VBoxManage常用的的操作:
代码:查看有哪些虚拟机
VBoxManage list vms

查看虚拟的详细信息
VBoxManage list vms --long

查看运行着的虚拟机
VBoxManage list runningvms

开 启虚拟机并开启远程桌面连接的支持
VBoxManage startvm -type vrdp

改 变虚拟机的远程连接端口,用于多个vbox虚拟机同时运行
VBoxManage controlvm vrdpprot

关闭虚拟机
VBoxManage controlvm acpipowerbutton

强制关闭虚拟机
VBoxManage controlvm poweroff
更多VBoxManage用法请参考VBoxMange --help

____________________________________________________________


让VirtualBox虚拟机实现开机自动后台运行 2011-01-26 03:07:35| 分类: Software | 标签: |字号大中小 订阅 .

本文链接:https://www.360docs.net/doc/48636144.html,/blog/static/12303947120110263735981/

测试环境:
Host OS: Windows 7 x64

Guest OS: Ubuntu、Windows XP
开启远程登录,并设置用户密码,XP用control userpasswords2设置自动登录(取消“要使
用本机,用户必需输入服务器密码”)


虚拟机软件:VirtualBox-4.0.2-69518-Win


目的:开机后自动后台运行虚拟机,只有进程,不显示GUI界面。


由于VMware Server 2只支持到Windows 2008 Server系统,Windows 7系统不便使用,即使
能安装也可能会有问题。VMware Workstation不免费,本身也没有后台运行虚拟机的功能,
只能通过第三方软件把启动虚拟机做成系统服务,或者设置了“在关闭后在后台运行电源
已打开的虚拟机”用批处理启动虚拟机再杀进程,或者用计划任务。因此选择使用免费的
VirtualBox。


后台启动VirtualBox虚拟机的命令有2个:
VBoxHeadless -s|--startvm | [--vrde=on|off|config]
VirtualBox 1.6后的版本里,VBoxVRDP只是VBoxHeadless的快捷方式,不再是单独的命令。
防止VRDP端口(虚拟机设置里的远程桌面)被外界访问到,用参数--vrde=off,虚拟机用桥接
网络时,虚拟机系统自带的远程桌面不受此参数影响。


VBoxManage [-q|--nologo] startvm | [--type gui|sdl|headless]
The following values

are allowed:
gui - Starts a VM showing a GUI window. This is the default.
headless - Starts a VM without a window for remote display only.


启动虚拟机的脚本(虚拟机的名称为XP):
@echo off
:: by oicu
cd /d "D:\Program Files\Oracle\VirtualBox"
VBoxHeadless --startvm "XP"
:: VBoxManage startvm "XP" --type headless


直接启动批处理脚本的话(包括脚本放到“启动”里),无论用哪条命令启动虚拟机都会有
一个headless的cmd窗口,用start ""也不能消去,关闭了该cmd窗口后虚拟机也退出了,而
且属于不正常关闭。可以一次启动多个虚拟机系统。


关闭虚拟机的脚本:
@echo off
:: by oicu
cd /d "D:\Program Files\Oracle\VirtualBox"
VBoxManage controlvm "XP" acpipowerbutton
:: send {Enter} to VM, for Windows Guest OS only.
VBoxManage controlvm "XP" keyboardputscancode 1c


打开gpedit.msc组策略,在用户的登录/注销脚本里,分别添加上面2个脚本。这里不能使用
计算机的启动/关机脚本,测试过是不能启动虚拟机的,可能和SYSTEM用户执行的脚本不能
访问网络等权限有关。使用登录脚本启动虚拟机不会显示headless的cmd窗口(系统组策略
里默认是隐藏运行脚本),未测试计划任务的方式。


远程登录Windows系统的虚拟机后,如果远程未注销,用关闭虚拟机的脚本就无法关闭虚拟
机,原因是关闭计算机时会提示“其他用户登录到这台计算机,关闭WINDOWS会使他们丢失
数据,您要继续关机吗?”造成acpi关机方式失败。在Guest系统里设置关机/注销脚本,用
shutdown -s -t 0也无效。解决方法是向虚拟机发送回车键,模拟“确定”操作,当然也可
以用shutdown远程关闭系统,但设置和操作更麻烦了。


虚拟机是Linux时,避免用VboxHeadless.exe和VirtualBox.exe交替登录,两者的不同步可
能会造成虚拟机的filesystem损坏。


______________________________________________

start "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm us --type headless


________________________________________________

用vbs脚本,不要用bat。
我的gentoo.vbs脚本,你参考改一下就能满足你的要求。

代码:

Dim WshShell

Set WshShell = wscript.createobject("wscript.shell")
WshShell.Exec("C:\Program Files\Sun\VirtualBox\vboxmanage.exe startvm Gentoo")

__________________________________________________________




相关文档
最新文档