Virtualbox for Users

From UVOO Tech Wiki
Revision as of 00:31, 8 February 2019 by imported>Jeremy-busk
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Start VMs Automatically on boot

Probably create a service via systemd that looks for uuids in users vbox-autostart.cfg file and run them in the system it's own way.

nano /etc/systemd/system/virtualbox-guest-run-vmname.service

[Unit]
Description=Unifi VM service
After=network.target vboxdrv.service
[Service]
ExecStart=/usr/bin/vboxheadless -s unifi
ExecStop=/usr/bin/vboxmanage controlvm unifi acpipowerbutton
[Install]
WantedBy=multi-user.target

You can always do it manually and use crontab -e @reboot but virtualbox service might not be available so you would need to test until it was available.

@reboot <username> /home/busk/myscript.sh
@reboot <username> vboxmanage startvm <vmname> --type headless

Or the doc way https://askubuntu.com/questions/404665/how-to-start-virtual-box-machines-automatically-when-booting

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
Now we need to create the /etc/vbox/vbox.cfg file and add

# 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 = {
allow = true
}
Note: If the filename vbox.cfg doesn't work above, try naming it autostart.cfg.

If you are the only user you can just add the line default_policy = allow to the vbox.cfg file.

Set permissions on directory to the vboxuser group and make sure users can write to the directory as well as sticky bit.

sudo chgrp vboxusers /etc/vbox
sudo chmod 1775 /etc/vbox
Add each of the users to the vboxusers group.

sudo usermod -a -G vboxusers USERNAME
(replace USERNAME with the 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
and enable autostart for an individual VM with

VBoxManage modifyvm <uuid|vmname> --autostart-enabled on
This will create a myuserid.start file in /etc/vbox directory

Now restart the vboxautostart-service to read in the changes.

sudo service vboxautostart-service restart
Reboot your system and your VM should start

References