Professional Documents
Culture Documents
Ask Ubuntu is a question and answer site for Ubuntu users and
developers. Join them; it only takes a minute:
Sign up
Anybody can ask a question Anybody can answer The best answers are voted up
and rise to the top
Home
Questions
Tags
Users
#!/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
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
7 Answers
Unanswered #! /bin/sh
# /etc/init.d/StartVM
#
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
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
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).
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
and
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
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
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
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":
# Alice is not allowed to start virtual machines, useful to exclude certain users
# if the default policy is set to allow.
alice = {
allow = false
}
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
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