Virtualbox autostart vm linux

How to start Virtual box machines automatically when booting?

I have many Virtual box machines in my Ubuntu12.04, each time i shutdown or reboot i have to start them one by one. I wanna a help in writing script for automatically autostart the VBox machines when booting.

14 Answers 14

You can use the VirtualBox Auto-start service. A good tutorial describing how to do this is posted on the «Life of a Geek Admin» blog.

The following steps are adapted from the linked blog post:

    First you need to create the file /etc/default/virtualbox and add a few variables. VBOXAUTOSTART_DB which contains an absolute path to the autostart database directory and
    VBOXAUTOSTART_CONFIG which contains the location of the autostart config settings. The file should look similar to this:

# virtualbox defaults file VBOXAUTOSTART_DB=/etc/vbox VBOXAUTOSTART_CONFIG=/etc/vbox/vbox.cfg 
# Default policy is to deny starting a VM, the other option is "allow". default_policy = deny # Create an entry for each user allowed to run autostart myuserid =
sudo chgrp vboxusers /etc/vbox sudo chmod 1775 /etc/vbox 
sudo usermod -a -G vboxusers USERNAME 

NOTE: If you have changed group permissions for the current user, log out and back in again to refresh the permissions. (credit @kR105)

    Every user who wants to enable autostart for individual machines has to set the path to the autostart database directory with

VBoxManage setproperty autostartdbpath /etc/vbox 
VBoxManage modifyvm --autostart-enabled on 
sudo service vboxautostart-service restart 

@Arronical The OP and the instructions from which the answer was sourced were both for Ubuntu 12.04. YMMV with versions after that.

It turns out that it virtualbox 4.3.10 doesn’t download the init scripts on 14.04, but ndasuser’s answer below helped me fix that. +1s all round!

I was trying make this solution work on ubuntu 15.10 with no sucess.. I ended using this post freesoftwareservers.com/index.php/2015/10/24/… .. maybe not the correct approach, but it works

I had similar unhappy incidents trying this operation on the vanilla LTS.

~$ cat /etc/os-release NAME="Ubuntu" VERSION="14.04.1 LTS, Trusty Tahr" 

On this version, the key file /etc/init.d/vboxautostart-service was not installed.

As far as I know all the VitualBox and requirements were put in by apt-get, so I cannot say why the ‘vboxautostart-service’ file was not also provided. But to get over this here are my update to kdmurray’s post.

1) /etc/default/virtualbox file existed for me. So must add vars:

VBOXAUTOSTART_DB=/etc/vbox VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg 

2) Must create /etc/vbox/autostart.cfg as indicated by OP.

6b) Need to get a vboxautostart-service script and make it executable.

cd /etc/init.d/ sudo wget http://www.virtualbox.org/browser/vbox/trunk/src/VBox/Installer/linux/vboxautostart-service.sh?format=raw -O vboxautostart-service sudo chmod +x vboxautostart-service 

6c) Alert the rc.d controller, but I used 24 as the start time. Putting just 20 and it did not start up. Perhaps it ran even before virtualbox was working.

sudo update-rc.d vboxautostart-service defaults 24 24 

Then rebooting launched the VM correctly.

In version 5.2 you have to edit vboxautostart-service and replace vboxdrv in the # Required Start / # Required Stop lines by virtualbox . It seems that they renamed the service, so the OS cannot detect start/stop priorities correctly. I think you don’t need step 6c if you replaced those lines.

You can use vboxmanage startvm «my virtual machine» —type=headless|gui|sdl (one of those). Use «headless» if they’re servers that you connect to by other means than using the gui.

To actually run these commands at the right time during boot, you’ll want to read up on Upstart.

After many unhappy hours trying to get the procedures in from kdmurray above to work, without success I eventually found a method that worked simply.

First my Linux host (Mint 17) was set up at boot time to login automatically to my main account.

Second I used the facilities in VirtualBox GUI (v4.3.12) to create a shortcut for each Virtual Machine on the desktop.

Next: I had already found that bringing up Menu->Control Centre -> Startup Applications -> Add and adding the desktop shortcuts gave files that did not work, I spotted from other answer on this page that the location of the startups is /home/USERNAME/.config/autostart so I did a right-click on each of the desktop VM shortcuts and then pasted them into that folder, overwriting the earlier crap files. Now they developed the ‘pretty’ VirtualBox icons.

And sure enough on restarting the host computer, the 3 VMs started automagically.

PS: alas I still have something missing, because often the Virtual Machines will not start up on boot, instead they generate an error dialog box which says they are locked, even if I have told them to shutdown before the host was re-booted.

Источник

Configuring VirtualBox autostart on Linux

It is often useful to configure VirtualBox virtual machines to automatically start and stop on startup and shutdown. The official documentation was a bit unclear, so I’ve made a short tutorial about it.

1. Configuration files

/etc/default/virtualbox

VBOXAUTOSTART_DB=/etc/vbox VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg 

/etc/vbox/autostart.cfg

default_policy = deny # Create an entry for each user allowed to use autostart myusername =  allow = true > 
  • sudo chgrp vboxusers /etc/vbox
  • sudo chmod 1775 /etc/vbox
  • Then, for each allowed username: sudo usermod -aG vboxusers USERNAME , then log out and in for it to apply.

2. Choose VMs to automatically start and stop

  • The first time a user configures autostart, the command: VBoxManage setproperty autostartdbpath /etc/vbox needs to be run.
  • Note: The autostart options are stored in the /etc/vbox file, and the VM itself. If moving the vm, the options may need to be set again.
  • VBoxManage modifyvm —autostart-enabled
  • You can also: VBoxManage modifyvm —autostop-type

3. Restart VirtualBox autostart service

Источник

AutoStart VirtualBox VMs on System Boot on Linux

In this guide, we are going to learn how to autostart VirtualBox VMs on system boot on Linux. On a Linux system with VirtualBox installed, you can start VMs automatically during system boot.

Table of Contents

AutoStart VirtualBox VMs on System Boot on Linux

There are multiple ways in which you can configure your VirtualBox vms to automatically start on system boot.

A few of these ways that we will discuss in this guide include;

Using VirtualBox Autostart Service

VirtualBox comes with a service called vboxautostart-service that makes it easy to automatically start virtual machines during system reboot.

  • VBOXAUTOSTART_DB – which defines the absolute path to the autostart database directory, usually the /etc/vbox.
  • VBOXAUTOSTART_CONFIG – defines the path to the virtual machine autostart configuration.

These variables can be defined as;

VBOXAUTOSTART_DB=/etc/vbox VBOXAUTOSTART_CONFIG=/etc/vbox/autostartvm.cfg

To place these variables in the /etc/default/virtualbox, run the command below;

echo -e "VBOXAUTOSTART_DB=/etc/vbox\nVBOXAUTOSTART_CONFIG=/etc/vbox/autostartvm.cfg" | sudo tee /etc/default/virtualbox

Define the virtual machine autostart configuration settings. The autostart configuration file contains options that controls how the virtual machine is auto started.

sudo vim /etc/vbox/autostartvm.cfg
 default_policy = deny kifarunix =
  • default_policy – defines whether to allow or deny the virtual machine autostart by default. In our example above, we denied any one from auto-starting the VM and explicitly allow one user, amos.
  • username (kifarunix) – with the default deny policy, you can define the specific users that are allowed to autostart the virtual machine (allow = trues). You can also define how long to delay the VM startup. 10 seconds is used in this demo.

Set Ownership of Database directory

The database directory, /etc/vbox, should be writable by the user to be used to start VMs automatically. To make it easy, you can simply add your user to vboxusers group and set the group ownership of the database directory to vboxusers group. After that, set the write permissions for the group. In this case, amos user is to be used to automatically start the virtual machine.

sudo usermod -aG vboxusers kifarunix
sudo chgrp vboxusers /etc/vbox

Assign the group write permissions on the autostart database directory.

To shield the directory from being modified or deleted by other users except the owner or the root user, set sticky bit.

Enable Virtual Machine Autostart

As a user, you can enable autostart for individual machines. This requires that you define the path to the database directory first.

VBoxManage setproperty autostartdbpath /etc/vbox/

Once that is done, you can now setup the virtual machine to automatically start on system boot.

vboxmanage modifyvm fedora30 --autostart-enabled on

Where fedora30 is the name of your virtual machine. You can also use UUID instead.

You can get the names/UUIDs of the vms by running the command below;

Restart vboxautostart-service

The configuration is now done. To effect the settings, you need to restart the vboxautostart-service.

sudo systemctl restart vboxautostart-service

Testing the Virtual Machine autostart

To test that your virtual machine can actually autostart on system boot, reboot you system and check. When system boots, your VM should now be running.

If you which to disable the virtual machine autostart;

vboxmanage modifyvm fedora30 --autostart-enabled off

Using Systemd service unit

Similarly, you can auto-start a VirtualBox by a creating a systemd service that starts the respective VM when system reboots.

To use this approach, just create the systemd unit service as follows (replace the name of the vm accordingly);

Источник

Читайте также:  Application logs in linux
Оцените статью
Adblock
detector