美文网首页
【转载】Windows开机自动启动Virtual Box虚拟机(

【转载】Windows开机自动启动Virtual Box虚拟机(

作者: 阿群1986 | 来源:发表于2020-09-21 11:48 被阅读0次

转载自CSDN博客:https://blog.csdn.net/martinloyee/article/details/108747033
原作者:martinloyee

网上很多介绍windows下开机启动virtual box虚拟的文章,都是通过将命令放在启动目录,或者作为开机计划任务来启动;这里介绍将virtual box 虚拟机作为系统服务器进行启动,即使用户未登录,也会启动虚拟机。

环境变量PATH添加 vbbox 的路径

C:\Program Files\Oracle\VirtualBox

创建一个配置文件

如: D:\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
Administrator= {
   allow = true
   startup_delay = 10
}

添加一个环境变量VBOXAUTOSTART_CONFIG
值为上面文件的路径 D:\autostart.cfg

添加 vbox 的 windows 服务

VBoxAutostartSvc install --user=Administrator
VBoxAutostartSvc delete --user=Administrator

运行 services.msc

查看 virtual box 的 auto 服务,启动看看,密码有没有错;如果没有错误,服务应该可以启动成功。

指定自动启动的 vm

VBoxManage modifyvm "vb虚拟机名称" --autostart-enabled on

close

VBoxManage modifyvm “vb虚拟机名称” --autostart-enabled off

参考 Virtual Box 6.1的帮助手册如下章节

9.21.4. Windows: Starting the Autostart Service

网址: https://www.virtualbox.org/manual/ch09.html#autostart-windows

9.21.4. Windows: Starting the Autostart Service

On Windows, autostart functionality consist of two components. First one is configuration file where the administrator can both set delayed start of the VMs and temporary disable autostarting for the particular user. The configuration file should be located in the folder accessible by all required users but it should have permissions allowing the only reading by everyone but administrators. The configuration file contains several options. One is default_policy which controls whether the autostart service allows or denies to start a VM for users which are not in the exception list. The exception list starts with exception_list and contains a comma separated list with usernames. Furthermore a separate startup delay can be configured for every user to avoid overloading the host. A sample configuration is given below:

# Default policy is to deny starting a VM, the other option is "allow".
default_policy = deny

# Bob is allowed to start virtual machines but starting them
# will be delayed for 10 seconds
bob = {
    allow = true
    startup_delay = 10
}

# Alice is not allowed to start virtual machines, useful to exclude certain users
# if the default policy is set to allow.
alice = {
    allow = false
}

The user name can be specified using the following forms: "user", "domain\user", ".\user" and "user@domain". Administrator must add the VBOXAUTOSTART_CONFIG environment variable into system variables containing the path to the configuration file described above. The environment variable tells the autostart services what configuration file is used.

Second component of autostart functionality is Windows service, every instance of it works on behalf of particular user using its own credentials.

To enable autostarting for a particular user, a member of the administrators group must run the following command:

VBoxAutostartSvc install --user=user [--password-file=password_file]

The password file should contain the password followed by a line break. The rest of the file is ignored. The user will be asked for a password if the password file is not specified.

To disable autostarting for particular user, a member of the administrators group must run the following command:

VBoxAutostartSvc delete --user=user

If a user has changed their password then a member of the administrators group must either reinstall the service or change the service credentials using Windows Service Manager. Due to Windows security policies, the autostart service cannot be installed for users with empty passwords.

Finally, the particular user should define which VM should be started at boot or not. The user should run the following command for every VM it desired to start at boot:

VBoxManage modifyvm VM name or UUID --autostart-enabled on

The user can remove the particular VM from the VMs starting at boot by running the following command:

VBoxManage modifyvm VM name or UUID --autostart-enabled off

相关文章

网友评论

      本文标题:【转载】Windows开机自动启动Virtual Box虚拟机(

      本文链接:https://www.haomeiwen.com/subject/srkvyktx.html