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/18 08:55] – 172.26.0.166 | virtualbox [2010/02/18 12:37] – 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 | ||
- | ===Ubuntu:Debian=== | + | http://www.kernelhardware.org/ |
- | VBoxTool currently consist only of a set of scripts. With this scripts, virtual | + | |
- | 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 | + | # mkdir / |
+ | # touch / | ||
+ | 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 ” “: |
- | * Place the main script script/ | + | $ VBoxManage list vms |
+ | " | ||
+ | " | ||
+ | " | ||
+ | Add Guest VM’s to “machines_enabled” include one VM name per line | ||
- | * Make vboxtool executable: | + | # vi /etc/virtualbox/machines_enabled |
- | chmod +x /usr/local/bin/ | + | Centos_HDLES_x86_1 |
+ | Centos_HDLES_x86_3 | ||
+ | Centos_HDLES_LAMP | ||
+ | Add VirtualBox VM Service script | ||
- | * Place the init script script/ | + | Create new init.d |
- | * Make vboxtoolinit executable: | + | # touch / |
- | chmod +x / | + | # chmod 755 /etc/init.d/ |
- | + | Copy the following code into file “/etc/init.d/ | |
- | * Activate the init script vboxtoolinit: | + | |
- | update-rc.d vboxtoolinit defaults 99 10 | + | |
- | + | ||
- | * Create a folder | + | |
- | configuration section below, type ' | + | |
- | + | ||
- | Note. To remove vboxtoolinit from autostart: update-rc.d -f vboxtoolinit remove | + | |
- | CONFIGURATION | + | #! /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. | ||
+ | # | ||
- | Note. Configuration from vboxtool does *not* taking place on *running* sessions, | + | # Source function library. |
- | so save or stop all sessions before issueing the autostart command. | + | if [ -f /etc/init.d/functions ] ; then |
+ | . / | ||
+ | elif [ -f / | ||
+ | . / | ||
+ | else | ||
+ | exit 1 | ||
+ | fi | ||
- | * Create | + | ################################################################################ |
- | < | + | # INITIAL CONFIGURATION |
+ | VBOXDIR=" | ||
+ | VM_USER=" | ||
+ | USE_NAT=" | ||
- | The VRDP-port enables RDP-clients like rdesktop to connect. It may be left blank. | + | export PATH=" |
- | * Create | + | if [ -f $VBOXDIR/config ]; then |
- | | + | . $VBOXDIR/ |
+ | fi | ||
- | * Issue the following command: | + | SU="su $VM_USER -c" |
- | | + | VBOXMANAGE=" |
- | VBoxTool will configure sessions (VRDP-port). By now, session(s) should be up and | + | ################################################################################ |
- | | + | # FUNCTIONS |
- | * Check if sessions or running, with the assumed vrdp-port: | + | # Determine |
- | | + | use_nat() { |
+ | if [ " | ||
+ | return `true` | ||
+ | else | ||
+ | return `false` | ||
+ | fi | ||
+ | } | ||
- | Show only the running sessions: | + | log_failure_msg() { |
- | | + | echo $1 |
+ | } | ||
- | * Check if sessions configured in / | + | log_action_msg() { |
- | | + | echo $1 |
+ | } | ||
- | UPGRADING FROM 0.2 | + | # 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 | ||
+ | } | ||
- | Sorry for breaking things here, but it's all in the name of naming consistency... | + | ################################################################################ |
+ | # RUN | ||
+ | case " | ||
+ | start) | ||
+ | if [ -f / | ||
- | - Config folder is moved from /etc/vbox to /etc/ | + | cat /etc/virtualbox/machines_enabled | while read VM; do |
- | - Main script ' | + | 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 | ||
- | USAGE | + | ;; |
+ | 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 | ||
- | After installation, | + | exit 0 |
+ | Add vboxcontrol service to chkconfig registry | ||
- | KNOWN ISSUES | + | # chkconfig --add vboxcontrol |
+ | Tell chkconfig to create symlinks for runlevels and activate service vboxcontrol | ||
- | - Backup is not working as expected when using snapshots. When a snapshot is | + | # chkconfig vboxcontrol on |
- | present, the main vdi file is not copied, even if it's different from | + | |
- | previous backups. Problem is that once a snapshot is made, the main vdi | + | |
- | (according to info from ' | + | |
- | vdi instead of the expected, chained main vdi in the vdi folder. | + | |
- | (Tracker | + | |
- | MORE HELP | ||
- | - Type: ' | ||
- | - See http:// | ||
- | |||
- | === Fedora :Redhat : CentOS === | ||
- | --- |