virtualbox
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
virtualbox [2010/02/17 08:58] – 172.26.0.166 | virtualbox [2010/02/18 12:48] – 172.26.0.166 | ||
---|---|---|---|
Line 51: | Line 51: | ||
---- | ---- | ||
- | Two Methods: | + | How do I get my VirtualBox Guest VM’s to start and stop when the host system reboots, shutdown, or starts. |
- | 1 VBoxTool http:// | + | Solution / Answer: |
- | 2 Script from http://www.kernelhardware.org/ | + | Create an init.d script so that VirtualBox Guest VM are controlled as a system service. |
+ | VBoxTool | ||
- | VBoxTool currently consist only of a set of scripts. With this scripts, virtual | + | http://www.kernelhardware.org/ |
- | machines of VirtualBox in a Linux headless server can be controlled. Start, stop, | + | |
- | save, backup and show status of sessions in batch mode from the command line. | + | |
- | Usage and installation is tested only on Ubuntu. Please report if a specific | + | ---- |
- | function is not working in another environment, | + | Create Config File for vboxcontrol service script |
- | INSTALLATION | + | < |
+ | < | ||
+ | The file “machines_enabled” located in “/ | ||
- | Note. Precede commands with ' | + | To get a list of your current Guest VM names execute the following command and notice the name is in ” “: |
+ | < | ||
+ | $ VBoxManage list vms | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | Add Guest VM’s to “machines_enabled” include one VM name per line | ||
+ | < | ||
+ | # vi / | ||
+ | Centos_HDLES_x86_1 | ||
+ | Centos_HDLES_x86_3 | ||
+ | Centos_HDLES_LAMP</ | ||
+ | Add VirtualBox VM Service script | ||
- | * Place the main script | + | Create new init.d service |
- | * Make vboxtool executable: | + | < |
- | chmod +x /usr/local/bin/vboxtool | + | < |
+ | Copy the following code into file “/etc/init.d/vboxcontrol” | ||
- | * Place the init script | + | <code bash> |
+ | #! /bin/sh | ||
+ | # vboxcontrol | ||
+ | # | ||
+ | # chkconfig: 345 98 02 | ||
+ | # description: | ||
+ | # processname: | ||
+ | # | ||
+ | # pidfile: | ||
+ | # | ||
+ | ### BEGIN INIT INFO | ||
+ | # | ||
+ | ### END INIT INFO | ||
+ | # | ||
+ | # Version 20090301 by Kevin Swanson < | ||
+ | # Version 2008051100 by Jochem Kossen < | ||
+ | # http:// | ||
+ | # | ||
+ | # Released in the public domain | ||
+ | # | ||
+ | # This file came with a README file containing the instructions on how | ||
+ | # to use this script. | ||
+ | # | ||
- | * Make vboxtoolinit executable: | + | # Source function library. |
- | chmod +x / | + | if [ -f / |
- | + | . /etc/init.d/functions | |
- | * Activate the init script vboxtoolinit: | + | elif [ -f /etc/rc.d/init.d/functions ] ; then |
- | update-rc.d vboxtoolinit defaults 99 10 | + | . /etc/rc.d/ |
- | + | else | |
- | * Create a folder | + | exit 1 |
- | configuration section below, type ' | + | fi |
- | + | ||
- | Note. To remove vboxtoolinit from autostart: update-rc.d -f vboxtoolinit remove | + | |
- | CONFIGURATION | + | ################################################################################ |
+ | # INITIAL | ||
+ | VBOXDIR="/ | ||
+ | VM_USER=" | ||
+ | USE_NAT=" | ||
- | Note. Configuration from vboxtool does *not* taking place on *running* sessions, | + | export PATH=" |
- | so save or stop all sessions before issueing the autostart command. | + | |
- | * Create | + | if [ -f $VBOXDIR/config ]; then |
- | < | + | . $VBOXDIR/ |
+ | fi | ||
+ | SU="su $VM_USER -c" | ||
+ | VBOXMANAGE=" | ||
+ | ################################################################################ | ||
+ | # FUNCTIONS | ||
+ | # Determine if USE_NAT is set to " | ||
+ | use_nat() { | ||
+ | if [ " | ||
+ | return `true` | ||
+ | else | ||
+ | return `false` | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | log_failure_msg() { | ||
+ | echo $1 | ||
+ | } | ||
+ | |||
+ | log_action_msg() { | ||
+ | echo $1 | ||
+ | } | ||
+ | |||
+ | # Check for running machines every few seconds; return when all machines are | ||
+ | # down | ||
+ | wait_for_closing_machines() { | ||
+ | RUNNING_MACHINES=`$SU " | ||
+ | if [ $RUNNING_MACHINES != 0 ]; then | ||
+ | sleep 5 | ||
+ | wait_for_closing_machines | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | ################################################################################ | ||
+ | # RUN | ||
+ | case " | ||
+ | start) | ||
+ | if [ -f / | ||
+ | |||
+ | cat / | ||
+ | log_action_msg " | ||
+ | $SU " | ||
+ | RETVAL=$? | ||
+ | done | ||
+ | touch / | ||
+ | fi | ||
+ | ;; | ||
+ | stop) | ||
+ | # NOTE: this stops all running VM's. Not just the ones listed in the | ||
+ | # config | ||
+ | $SU " | ||
+ | log_action_msg " | ||
+ | $SU " | ||
+ | done | ||
+ | rm -f / | ||
+ | wait_for_closing_machines | ||
+ | |||
+ | ;; | ||
+ | start-vm) | ||
+ | log_action_msg " | ||
+ | $SU " | ||
+ | ;; | ||
+ | stop-vm) | ||
+ | log_action_msg " | ||
+ | $SU " | ||
+ | ;; | ||
+ | poweroff-vm) | ||
+ | log_action_msg " | ||
+ | $SU " | ||
+ | ;; | ||
+ | status) | ||
+ | echo "The following virtual machines are currently running:" | ||
+ | $SU " | ||
+ | echo -n "$VM (" | ||
+ | echo -n `$SU " | ||
+ | echo ' | ||
+ | done | ||
+ | ;; | ||
+ | *) | ||
+ | echo " | ||
+ | name> | ||
+ | exit 3 | ||
+ | esac | ||
+ | |||
+ | exit 0 | ||
+ | </ | ||
+ | Add vboxcontrol service to chkconfig registry | ||
+ | |||
+ | < | ||
+ | Tell chkconfig to create symlinks for runlevels and activate service vboxcontrol | ||
+ | |||
+ | < | ||