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.
|
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. |
|||||||||
|
|
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:
NOTE: If you have changed group permissions for the current user, log out and back in again to refresh the permissions. (credit @kR105)
|
|||||||||||||||||||||
|
|
I had similar unhappy incidents trying this operation on the vanilla LTS.
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:
2) Must create /etc/vbox/autostart.cfg as indicated by OP. 6b) Need to get a vboxautostart-service script and make it executable.
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.
Then rebooting launched the VM correctly. |
|||
|
|
|
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. {right-click the VM in left column & select "Create Shortcut on 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. :-) Bill Williams 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. |
|||||
|
|
You can use To actually run these commands at the right time during boot, you'll want to read up on Upstart. |
|||
|
|
|
In addition to the good description of the vboxautostart-service above, you can do
to automatically stop the guest at shutdown. For Ubuntu 14.04 I had to add a sleep 30 to the vboxautostart-service stop section, so that it waits until guest has been saved completely. |
|||
|
|
|
This can be done using VirtualBox Command Line Management Interface. Just run the following script at start up.
There is a nice tutorial for more info. |
|||||
|
|
Addon to @kdmurray answer. If you get error on:
To solve this, I had to manually create files "username".start and "username".stop with:
And change owner with:
rerun:
then restart service:
check is all is ok with:
and you should see "VBox..." process in a list, if virtual machine is running |
|||
|
|
|
You could also get the gnome session manager described here. Gnome Session Manager
It is in the sofware center or you could just go to a terminal and type
Next you can create a little script to run and use the gnome session manager to start it. Here is a little sample script to get you going...
|
||||
|
|
|
To start a VM on logging in to our session we may want to define a .desktop file: When this file was copied or moved to our autostart directory it will then be executed after we log in: Running Virtual Box in user space may help to avoid unwanted side effects of starting them during boot (e.g. the VM runs as root, boot time increases incredibly, ...). |
||||
|
|
|
This is how i start my Centos (name of my virtual machine) when my host machine reboots. I use crontab for that job. Here is my crontab entry:
|
||||
|
|
|
For Ubuntu server 16.04.1 LTS I solved this by doing: First activate the rc-local.service
Add the following line in
|