Autostarting VirtualBox Virtual Machines
I created an Ubuntu Apt Cache Proxy Virtual Machine (VM). I want the VM available whenever Ubuntu client workstations are running. For me that means any time my LAN server is running.
VirtualBox is designed to support autostarting VMs. While there are a few online tutorials about the topic, I found a few details missing.
On my various computers I use Slackware and Ubuntu MATE.
All of my VMs are stored on my office desktop. I dual boot the office desktop between Slackware and Ubuntu MATE. The dual booting does not affect the VMs because I keep the two distros synced to the same version of VirtualBox and use the same configurations.
The office desktop is not always powered on. Ideally then I wanted to move the proxy server to my LAN server, which is always on when any client workstations are on.
While I use Ubuntu MATE as a desktop operating system, my LAN server runs Slackware.
On the office desktop I do not store my VMs in $HOME
. I store them in /var/vm-images/
, which is a separate disk partition. To prepare for running VMs on the LAN server, I configured the LAN server similarly.
Some online tutorials mention adding the user account to the vboxusers
group, but this should already be done otherwise running VirtualBox VMs is impossible.
As noted in the VirtualBox user manual and online tutorials, there are a few steps to support autostarting. First is updating /etc/default/virtualbox
to include the following variables:
VBOXAUTOSTART_DB=/etc/vbox VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg
Ensure /etc/vbox
is writable by members of the vboxusers
group:
chmod 1775 /etc/vbox chgrp vboxusers /etc/vbox
Create an autostart configuration file for the affected user:
touch /etc/vbox/autostart.cfg
The contents of /etc/vbox/autostart.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 username = { allow = true }
Where username
is the actual login name of the affected user.
Provide appropriate file permissions:
chown username:vboxusers /etc/vbox/autostart.cfg
As the new proxy server VM files were on my office desktop, I copied the files to my LAN server. Then I registered the files on the server. The trick is to specify the full file path to the xml/vbox
config file of the copied VM.
vboxmanage registervm "/var/vm-images/Ubuntu Apt Proxy/Ubuntu Apt Proxy.vbox"
The vboxmanage
is robust. If there are no error messages after registering then the command likely succeeded. To be sure run the following command:
vboxmanage list vms
Ensure the vboxautostart-service
is configured to start at boot. For Slackware this is the /etc/rc.d/rc.vboxautostart-service
file. An entry in rc.local
is sufficient:
if [ -x /etc/rc.d/rc.vboxautostart-service ]; then /etc/rc.d/rc.vboxautostart-service start fi
After logging in as the affected user, run the following commands:
vboxmanage setproperty autostartdbpath /etc/vbox
vboxmanage modifyvm "Ubuntu Apt Proxy" --autostart-enabled=on
To run the VM without rebooting, as root start the vboxautostart-service
.
As non-root, run the following:
vboxmanage list runningvms
The affected VM should be running.
I have the apt caching proxy server configured to use bridged networking and is a member of the LAN subnet. Another test to verify the VM is running is to ping the IP address or hostname of the VM.
A final acid test was to reboot the LAN server. The new proxy VM started just fine.
For safely powering down the VM on the LAN server, I use a vbox-shutdown
script. I run the script from the Slackware shutdown scripts.
I have had two update sessions since moving the proxy VM to the LAN server. No hiccups or problems. As the apt-cacher-ng cache is actually outside the VM directly on the LAN server drive, I need not worry about the size of the VM disk growing.
I am pleased with the results.
With respect to creating an apt caching proxy server, there are many online tutorials.
Posted: Tutorial Tagged: Slackware, Ubuntu, Virtual Machines
Category:Next: Updating the Slackware Kernel 3.10.17
Previous: Apt Cache Proxy