Jho*_*re- 13 virtualbox windows-xp
我在 Windows XP 主机上有一台装有 Windows XP 的 VirtualBox 机器。
我如何将 VirtualBox 作为服务启动,以便我可以在引擎盖下获得一个虚拟机,而且我不必启动 VirtualBox 来访问我的虚拟机(通过网络中的 VNC)?
我发现 VirtualBox Manage 可能是要走的路,但由于我是初学者,我不知道从哪里开始。
有任何想法吗?
Joh*_*art 10
请注意,当前接受的答案 (Molly7244) 实际上是在您登录时启动 VM - 而不是在您启动机器时。换句话说,它不是一种服务。
对于在机器启动时运行的实际服务,我将两个脚本(最初来自此处)与 cygwin (cygrunsrv) 结合使用。使用本页其他地方提到的 VBoxHeadless 模式。
第一个脚本通过 VBoxHeadless 运行您的 VM;它从环境变量中获取要运行的正确 VM 的名称(以及其他信息,例如您的 VBOX 主目录)。第二个脚本为特定 VM 安装服务(通过使用 cygrunsrv 调用具有正确 env.vars 集的第一个脚本)。最后是包含常用功能的第三个文件。如果你把所有这些放在一个目录中,你可以像这样安装一个新的虚拟机:
$ VBOX_USER_HOME="/path/to/.VirtualBox/" vboxd-install MyVMName 3333
Run Code Online (Sandbox Code Playgroud)
然后使用“net start vboxd-MyVMName”或“cygrunsrv -S vboxd-MyVMName”启动服务。
这是 VM 运行脚本“vboxd”:
#!/bin/bash
# from http://forums.virtualbox.org/viewtopic.php?f=1&t=23536
##
## Manages start / stop of VirtualBox virtual machines
##
## load common functions
basedir="$(readlink -f $(dirname $0))"
source "$basedir/.libcommon" || exit 1
## parse arguments
parseArg vmName "$1" "$VBOXD_VM_NAME"
parseArg vmPort "$2" "$VBOXD_VM_PORT"
VBOX_INSTALL_PATH="$(cygpath "$VBOX_MSI_INSTALL_PATH")"
## define signal handler
function onHalt {
warn "Stopping virtual machine '$vmName'"
"$VBOX_INSTALL_PATH/VBoxManage" controlvm "$vmName" savestate
exit 0
}
## install signal handler; cygrunsrv uses SIGTERM by default
trap 'onHalt' TERM
## hardcode this path if you like; it's required for VBox* utils to
## find the correct VirtualBox.xml config file and is usually set
## during a call to vboxd-install.
#export VBOX_USER_HOME="$USERPROFILE\\.VirtualBox"
## default VBoxHeadless port specification
portSpec="-e \"TCP/Ports=$vmPort\""
## determine vm state
info "Querying virtual machine '$vmName' state"
vmState=$( \
"$VBOX_INSTALL_PATH/VBoxManage" showvminfo "$vmName" \
| grep '^State:' \
| sed 's/State: *//' )
info "Virtual machine '$vmName' is $vmState"
## if vm state is saved, we can't specify port without an exception,
## as port spec requires modification of the (immutable) saved machine
## state. See http://www.virtualbox.de/ticket/3609
if [ "${vmState##saved}" != "$vmState" ]; then
## state is saved; clear port specification
warn "Port specification is not allowed for saved vms"
portSpec=""
fi
## start the VM
info "Starting virtual machine '$vmName' on port $vmPort"
"$VBOX_INSTALL_PATH/VBoxHeadless" -s "$vmName" $portSpec &
## record pid of VBoxHeadless child process and wait on it
pid="$!"
info "Waiting on VBoxHeadless child process $pid"
wait "$pid"
Run Code Online (Sandbox Code Playgroud)
这是安装程序脚本“vboxd-install”:
#!/bin/bash
# http://forums.virtualbox.org/viewtopic.php?f=1&t=23536
##
## Registers a VirtualBox virtual machine to start as a service via cygrunsrv
##
## load common functions
basedir="$(readlink -f $(dirname $0))"
source "$basedir/.libcommon" || exit 1
## test for presence of cygrunsrv utility
if [ ! -x "$(which cygrunsrv)" ]; then
die "Utility 'cygrunsrv' is not in path"
fi
## test VirtualBox configuration
if [ -z "$VBOX_USER_HOME" ]; then
die "Required environment variable 'VBOX_USER_HOME' is undefined. " \
"Please ensure this variable is set to point to the directory " \
"containing your VirtualBox.xml configuration file."
fi
configFile=$(cygpath -u "$VBOX_USER_HOME\\VirtualBox.xml")
if [ ! -e "$configFile" ]; then
die "VirtualBox configuration file '$(cygpath -w $configFile)' not found"
fi
## parse arguments
parseArg vmName "$1"
parseArg vmPort "$2"
parseArg vmUser "$3" "SYSTEM"
## if vmUser is not SYSTEM, update userSpec
userSpec="--interactive"
if [ "$vmUser" != "SYSTEM" ]; then
## "interactive" option disallowed when user is specified
userSpec="--user \"$vmUser\""
fi
## install the service
cygrunsrv \
--install "vboxd-$vmName" \
--path "$basedir/vboxd" \
--env "VBOXD_VM_NAME=$vmName" \
--env "VBOXD_VM_PORT=$vmPort" \
--env "VBOX_USER_HOME=$VBOX_USER_HOME" \
--desc "VirtualBox virtual machine '$vmName' on port $vmPort" \
$userSpec \
--type auto \
--termsig TERM \
--shutsig TERM \
--neverexits \
--preshutdown \
|| die "Failed to install service"
Run Code Online (Sandbox Code Playgroud)
最后,这里是这两个引用的“.libcommon”脚本:
# -*-shell-script-*-
# from http://forums.virtualbox.org/viewtopic.php?f=1&t=23536
SCRIPT="$(basename $0)"
BASEDIR="$(readlink -f $(dirname $0))"
[ -z "$LOGLEVEL" ] && LOGLEVEL=2
[ -z "$LOGDATEFORMAT" ] && LOGDATEFORMAT="%Y-%m-%d %H:%M:%S "
function log {
local now=""
[ -n "$LOGDATEFORMAT" ] && now=$(date +"$LOGDATEFORMAT")
echo "$SCRIPT $now$@" >&2
}
function debug {
[ "$LOGLEVEL" -lt 3 ] && return
log "[DEBUG] $@"
}
function info {
[ "$LOGLEVEL" -lt 2 ] && return
log "[INFO] $@"
}
function warn {
[ "$LOGLEVEL" -lt 1 ] && return
log "[WARN] $@"
}
function error {
log "[ERROR] $@"
}
function die {
error "$@"
exit 1
}
function parseArg {
local _name="$1"
local _value="$2"
local _default="$3"
if [ -z "$_value" ]; then
if [ -z "$_default" ]; then
die "Required argument '$_name' is undefined"
fi
if [ "$_default" = "*EMPTY*" ]; then
_value=""
else
_value="$_default"
fi
fi
debug "$_name=\"$_value\""
eval "$_name=\"$_value\""
}
Run Code Online (Sandbox Code Playgroud)
这个解决方案对我很有用;希望你也有类似的运气。
小智 8
在这一点上看起来最简单的答案是VBoxVMService。我还没有尝试过,如果/当我尝试时,我会尽量记住来这里并更新答案。
小智 0
创建快捷方式C:\\Program Files\\innotek VirtualBox\\VBoxManage.exe
引号后输入:startvm <your virtual machine name>
例子:
\n\n\xe2\x80\x9cC:\\Program Files\\innotek VirtualBox\\VBoxManage.exe\xe2\x80\x9d startvm XP\n
Run Code Online (Sandbox Code Playgroud)\n\n将快捷方式复制/移动到启动文件夹。
\n\nps:如果您想延迟虚拟机直到系统完全启动,您可以在 XP 中通过Startup Delayer执行此操作。
\n 归档时间: |
|
查看次数: |
18900 次 |
最近记录: |