Sie sind auf Seite 1von 10

virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 1 of 10

Ask Ubuntu is a question and answer site for Ubuntu users and
developers. Join them; it only takes a minute:

Sign up

Here's how it works:

Anybody can ask a question Anybody can answer The best answers are voted up
and rise to the top
Home

Questions

Tags

Users

Unanswered Start VBoxHeadless VM at startup Ask Question

I cannot seem to get my VM to run at


startup.
16 I tried the "startup applications" and
update-rc.d with no luck.

sudo update-rc.d startvms defaults 99 10

9 This created all the appropriate


symbolic links for the different run
levels but the VM still does not start.

Here's my startvms script:

#!/bin/bash
### BEGIN INIT INFO
# Provides: startvms
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start my VMs at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
case "$1" in
start)
echo "Starting"
nohup VBoxHeadless --startvm "UbuntuServer" &
;;
stop)
echo "Stopping $DESC"
VBoxManage controlvm "UbuntuServer" poweroff
;;

restart|force-reload)
echo "Restarting $DESC"
VBoxManage controlvm "UbuntuServer" poweroff
nohup VBoxHeadless --startvm "UbuntuServer" &
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

What am i doing wrong?


By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 2 of 10

virtualbox startup

asked Aug 15 '11 at 18:33


capdragon
617 2 15 25

7 Answers

THIS is what finally worked!


1) Create the startup


script file
Home in /etc/init.d - sudo
nano /etc/init.d/StartVM .
Questions
Copy Paste the following in the file
Tags
and replace "My VM Name" for
Users your vm name:

Unanswered #! /bin/sh
# /etc/init.d/StartVM
#

#Edit these variables!


VMUSER=spode
VMNAME="My VM Name"

case "$1" in
start)
echo "Starting VirtualBox VM..."
sudo -H -b -u $VMUSER /usr/bin/VBoxVRDP -s "$VMNAME"
;;
stop)
echo "Saving state of Virtualbox VM..."
sudo -H -u $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" savestate
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0

2) Give the script


executable permission

with sudo chmod


+x /etc/init.d/StartVM .

3) Tell script to run at


startup.

tell the script be the first to


shutdown and the last to startup.

sudo update-rc.d StartVM defaults


99 01

edited Mar 23 '14 at 3:07

answered Apr 16 '12 at 19:33


capdragon
By using our site, you acknowledge that you have read617
and understand 
2 15 25our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 3 of 10


FYI, This works on Opensuse



without nohup.

VBoxHeadless -s "OpenSuSE 11.4 64bit" &

answered Nov 7 '11 at 17:09


Bill
21 2

Home

Questions

Tags

Users

Unanswered


By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 4 of 10



Since you mention that

VBoxHeadless works fine if you
type it from the command line of a
terminal but does not start any VM
when launched from a init script,
my guess is that it is looking for
some environment variable which
is defined when you run a shell in
your terminal but undefined in the
init script environment (which is
basically empty, except for
parameters given on the kernel
command line).

Home Can you try replacing the


VBoxHeadless invocations in the
Questions script with this?
Tags
env USER=username HOME=/path/to/user/homedir VBoxHeadless ...same options as before...
Users
Here "username" and the home
Unanswered directory path should be changed
to match those of the user you use
to start the VM.

If that works, you might want to


use su -l to run VBoxHeadless
instead of this env hack.

answered Aug 15 '11 at 20:07


Riccardo Murri
13.5k 5 44 49


By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 5 of 10



This is working ok with Ubuntu

server 12.04 and VirtualBox
4.2.20.

#! /bin/sh
# /etc/init.d/StartVM
#
#Edit these variables!
VMUSER=username
case "$1" in
start)
echo "Starting VirtualBox VM SMARTHOST ..."
sudo -u $VMUSER VBoxManage startvm SMARTHOST --type headless
echo "Starting VirtualBox VM wxp-acceso ..."
sudo -u $VMUSER VBoxManage startvm wxp-acceso --type headless
echo "Starting VirtualBox VM wmmaq_edi ..."
sudo -u $VMUSER VBoxManage startvm vmmaq_edi --type headless
Home ;;
stop)
Questions echo "Saving state of Virtualbox VM SMARTHOST ..."
sudo -u $VMUSER VBoxManage controlvm SMARTHOST savestate
Tags echo "Saving state of Virtualbox VM wxp-acceso ..."
sudo -u $VMUSER VBoxManage controlvm wxp-acceso savestate
Users echo "Saving state of Virtualbox VM vmmaq_edi ..."
sudo -u $VMUSER VBoxManage controlvm vmmaq_edi savestate
Unanswered ;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0

And

sudo chmod +x /etc/init.d/StartVM

and

sudo update-rc.d StartVM defaults 99 01

as indicated at a previous answer.

edited Dec 17 '13 at 0:11


chaos
19.1k 8 56 67

answered Dec 16 '13 at 22:57


user224910
11 1


By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 6 of 10



one might also want to set directly

the port when using vrdp .. comment
to the top answer, which
compartmentalizes well to use
different scripts for different vms

VBoxVRDP -startvm "myVM" -vrdpport 3391 &

edited Sep 30 '15 at 7:17


muru
1

answered Mar 9 '15 at 11:36


ebricca
Home 151 4

Questions

Tags

Users

Unanswered


By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 7 of 10

Wow.. I am seeing all these solutions,



which seem a bit complex, but this is
my third laptop on which I ended up
simply writing:

VBoxHeadless -s "Ubuntu Server"

in my rc.local file in the /etc/ directory


and that worked pretty well. Runs the
virtual machine automatically on a
reboot.

answered Jun 19 '17 at 0:37


Home Muhammad bin Yusrat
253 2 9
Questions

Tags

Users

Unanswered


By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 8 of 10

On recent versions of Virtualbox



(4.2.0 onwards) you don't need to
roll your own script to autostart a
VM but it does take some
configuration. See section 9.24 of
the Virtualbox Manual "Starting
virtual machines during system
boot"

Unfortunately the manual only


gives outline instructions and
hasn't been updated in ages. I
found this post on the virtualbox
Home forums with some extra detail.

Questions You could just put a line in rc.local


to start your server but if you want
Tags
to do it the "offical" way read on..
Users
Add these lines
Unanswered to /etc/default/virtualbox:

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

Edit /etc/vbox/vboxautostart.cfg
(this example denies autostart
permission for all users except
user "Bob":

# Default policy is to deny starting a VM, the other option is "allow".


default_policy = deny

# Bob is allowed to start virtual machines but starting them


# will be delayed for 10 seconds
bob = {
allow = true
startup_delay = 10
}

# Alice is not allowed to start virtual machines, useful to exclude certain users
# if the default policy is set to allow.
alice = {
allow = false
}

Add vboxusers group to /etc/vbox


and sticky bit:

# chgrp vboxusers /etc/vbox


# chmod 1775 /etc/vbox

Add all users who will use


virtualbox to the "vboxusers"
group, e.g:

# adduser Bob vboxusers

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

Users can then set VMs to


autostart and configure how they
will have
stop read
(e.g and
savestate,
By using our site, you acknowledge that you
acpishutdown) with:
Policy, Privacy Policy, and our Terms of Service.
understand our Cookie

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 9 of 10

$ VBoxManage modifyvm <vmname> --autostart-enabled on


$ VBoxManage modifyvm <vmname> --autostop-type acpishutdown

The above worked for me with


Virtualbox 5, installed from the
virtualbox.org repository.

answered Jul 28 '17 at 17:37


Jules
1

 

Home

Questions

Tags

Users

Unanswered

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019
virtualbox - Start VBoxHeadless VM at startup - Ask Ubuntu Page 10 of 10

Home

Questions

Tags

Users

Unanswered

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup 01/01/2019

Das könnte Ihnen auch gefallen