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/07/04 20:05] – 172.26.14.218 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== VirtualBox ===== | + | ====== VirtualBox |
VirtualBox is a free/ | VirtualBox is a free/ | ||
* [[http:// | * [[http:// | ||
+ | * [[http:// | ||
===== Create a VM ===== | ===== Create a VM ===== | ||
Copy an ISO to your home directory: | Copy an ISO to your home directory: | ||
Line 51: | Line 52: | ||
---- | ---- | ||
- | 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 | + | ---- |
- | function | + | Create Config File for vboxcontrol service script |
+ | |||
+ | < | ||
+ | < | ||
+ | The file “machines_enabled” located in “/ | ||
+ | |||
+ | To get a list of your current Guest VM names execute the following command | ||
+ | < | ||
+ | $ 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 | ||
+ | |||
+ | Create new init.d service script file and give execute permissions | ||
+ | |||
+ | < | ||
+ | < | ||
+ | Copy the following code into file “/ | ||
+ | |||
+ | <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 <jochem.kossen@gmail.com> | ||
+ | # http:// | ||
+ | # | ||
+ | # Released in the public domain | ||
+ | # | ||
+ | # This file came with a README file containing the instructions on how | ||
+ | # to use this script. | ||
+ | # | ||
+ | |||
+ | # Source | ||
+ | if [ -f /etc/init.d/functions ] ; then | ||
+ | . / | ||
+ | elif [ -f / | ||
+ | . / | ||
+ | else | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | ################################################################################ | ||
+ | # INITIAL CONFIGURATION | ||
+ | VBOXDIR="/ | ||
+ | VM_USER=" | ||
+ | USE_NAT=" | ||
+ | |||
+ | export PATH=" | ||
+ | |||
+ | if [ -f $VBOXDIR/ | ||
+ | . $VBOXDIR/ | ||
+ | fi | ||
- | INSTALLATION | + | SU="su $VM_USER -c" |
+ | VBOXMANAGE=" | ||
- | Note. Precede commands with ' | + | ################################################################################ |
+ | # FUNCTIONS | ||
- | * Place the main script script/ | + | # Determine if USE_NAT is set to " |
+ | use_nat() { | ||
+ | if [ " | ||
+ | return `true` | ||
+ | else | ||
+ | return `false` | ||
+ | fi | ||
+ | } | ||
- | * Make vboxtool executable: | + | log_failure_msg() { |
- | chmod +x / | + | echo $1 |
+ | } | ||
- | * Place the init script script/ | + | log_action_msg() { |
+ | echo $1 | ||
+ | } | ||
- | * Make vboxtoolinit executable: | + | # Check for running machines every few seconds; return when all machines are |
- | chmod +x / | + | # down |
- | + | wait_for_closing_machines() { | |
- | * Activate the init script vboxtoolinit: | + | RUNNING_MACHINES=`$SU " |
- | update-rc.d vboxtoolinit defaults 99 10 | + | if [ $RUNNING_MACHINES != 0 ]; then |
- | + | sleep 5 | |
- | * Create a folder / | + | wait_for_closing_machines |
- | | + | fi |
- | + | } | |
- | Note. To remove vboxtoolinit from autostart: update-rc.d -f vboxtoolinit remove | + | |
- | CONFIGURATION | + | ################################################################################ |
+ | # RUN | ||
+ | case " | ||
+ | start) | ||
+ | if [ -f / | ||
- | Note. Configuration from vboxtool does *not* taking place on *running* sessions, | + | cat / |
- | so save or stop all sessions before issueing | + | 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 | ||
- | * Create | + | ;; |
- | <session | + | 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>|stop-vm | ||
+ | exit 3 | ||
+ | esac | ||
+ | exit 0 | ||
+ | </ | ||
+ | Add vboxcontrol service to chkconfig registry | ||
+ | < | ||
+ | Tell chkconfig to create symlinks for runlevels and activate service vboxcontrol | ||
+ | < | ||