Skip to main content

Virtualbox - Autostart all your virtual machines

In the last blog i said about a script to auto-start and stop your virtual machines with easy, you can download the script and find out more about it VBox Tool

Its very easy to install and setup, here's how i did it (same as the readme basically)

Download the script and as "root" do the following

Upload the main script "script/vboxtool" to "/usr/local/bin"
make vboxtool executable

chmod +x /usr/local/bin/vboxtool

Then upload the init script "script/vboxtoolinit" to "/etc/init.d"
and make vboxtoolinit executable

chmod +x /etc/init.d/vboxtoolinit

at this point i had to edit the file "/etc/init.d/vboxtoolinit" to get it to work properly with centos, i just added (see below) just above "### BEGIN INIT INFO"

# chkconfig: - 50 10
# description: Start or stop vbox virtual machines

Then activate the script

chkconfig --levels 235 vboxtoolinit on

Now create a new folder called "vboxtool" in the "etc" folder

cd /etc
mkdir vboxtool


This folder will contain the two config files which control which user runs the virtual machines and what virtual machines start.

so now we create a new file "/etc/vboxtool/machines.conf" and in that file we list what virtual machines we want to control and what RDP port to use.
here is what mine looks like

Windows XP,4545
centos 5,4646

and now we create a new file "/etc/vboxtool/vboxtool.conf" and in that file we put

vbox_user='virtualboxuser'


There are other config options you can use in both files but ill let you read about them yourself, the above is enough to get you up and running.

Now make sure all virtual machines are currently stopped, then we can start them using the script. Again the commands we use for centos is different to that in the readme.

service vboxtoolinit start


and to stop

service vboxtoolinit stop

Now whenever your server is shutdown or rebooted your virtual machines will do the same safely and then autostart again on bootup.