网上很多介绍windows下开机启动virtual box虚拟的文章,都是通过将命令放在启动目录,或者作为开机计划任务来启动;这里介绍将virtual box 虚拟机作为系统服务器进行启动,即使用户未登录,也会启动虚拟机。
-
环境变量path添加 vb 的路径
path
C:\Program Files\Oracle\VirtualBox -
创建一个配置文件
如: d:\vb_work\cfg\autostart.cfg
内容如下:
# Default policy is to deny starting a VM, the other option is "allow". default_policy = allow # Bob is allowed to start virtual machines but starting them # will be delayed for 10 seconds window系统用户名称 = { allow = true startup_delay = 10 }
-
添加一个环境变量
VBOXAUTOSTART_CONFIG
值为上面文件的路径 d:\vb_work\cfg\autostart.cfg -
添加 vbox 的 windows 服务
VBoxAutostartSvc install --user=window系统用户名称 # delete VBoxAutostartSvc delete --user=window系统用户名称
-
运行 services.msc
查看 virtual box 的 auto 服务,启动看看,密码有没有错;如果没有错误,服务应该可以启动成功。
-
指定自动启动的 vm
VBoxManage modifyvm "vb虚拟机名称" --autostart-enabled on # close VBoxManage modifyvm “vb虚拟机名称” --autostart-enabled off
参考 vb 的帮助文件如下小节
9.21.4. Windows: Starting the Autostart Service