This is written for Ubuntu hardy 8.04 and virtualbox 1.6.2
- Download the deb package from virtualbox/sun. Or install with apt
deb http://download.virtualbox.org/virtualbox/debian hardy non-free
wget -q http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc -O- | sudo apt-key add –
- Install the package: dpkg -i package name, or apt-get install virtualbox-2.0 bridge-utils uml-utilities
- create any machines you want and make any customizations you would like.
- add a few lines to rc.local
# change permissions for vbox
chmod 0666 /dev/net/tun
- add the following to /etc/network/interfaces “that will get you 2 tap devices, enough for two machines”
auto tap1 tap2
iface tap1 inet manual
tunctl_user desktop
iface tap2 inet manual
tunctl_user desktop
auto br0
iface br0 inet dhcp
bridge_ports eth0 tap1 tap2
bridge_maxwait 0
- create /etc/vbox
- nano /etc/vbox/machines_enabled
- put a list of all virtual machines you want started and stopped at boot and shutdown/reboot
- nano /etc/init.d/virtualbox
contents of above file
#! /bin/sh ### BEGIN INIT INFO # Provides: virtualbox_vms # Required-Start: $local_fs $syslog $remote_fs # Required-Stop: $local_fs $syslog $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: S 0 1 6 # Short-Description: Control VirtualBox Virtual Machine instances ### END INIT INFO # # Version 20080531-0 AR # ################################################################################ # INITIAL CONFIGURATION VBOXDIR="/etc/vbox" RUNAS_USER=desktop SU="su $RUNAS_USER -c" VBoxMDAEMON="VBoxManage" VBoxSDAEMON="VBoxHeadless" . /lib/lsb/init-functions # Are we running from init? run_by_init() { ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ] } ################################################################################ # RUN case "$1" in start) cat $VBOXDIR/machines_enabled | while read VM; do log_action_msg "Starting VM: $VM ..." # su $RUNAS_USER -c "$VBoxSDAEMON startvm \"$VM\" -type vrdp &" su $RUNAS_USER -c "$VBoxSDAEMON --startvm \"$VM\" &" done ;; stop) # NOTE: this stops all running VM's. Not just the ones listed in the # config cat $VBOXDIR/machines_enabled | while read VM; do log_action_msg "Shutting down VM: $VM ..." su $RUNAS_USER -c "$VBoxMDAEMON controlvm \"$VM\" savestate" done ;; start-vm) log_action_msg "Starting VM: $2 ..." su $RUNAS_USER -c "$VBoxSDAEMON --startvm \"$2\" > /dev/null 2 >&1" ;; stop-vm) log_action_msg "Stopping VM: $2 ..." su $RUNAS_USER -c "$VBoxMDAEMON controlvm \"$2\" savestate" ;; poweroff-vm) log_action_msg "Powering off VM: $2 ..." $VBoxMDAEMON "controlvm \"$2\" poweroff" ;; status) log_action_msg "The following virtual machines are currently running:" echo "Still thinking about what to do here." #$VBoxMDAEMON "list runningvms" | while read VM; do #echo -n "$VM (" # not yet figured this out #echo -n `"$VBoxMDAEMON showvminfo $VM|grep Name:|sed -e 's/^Name:\s*//g'"` #echo ')' #done ;; *) log_failure_msg "Usage: $0 {start|stop|status|start-vm <VM name>|stop-vm <VM name>|poweroff-vm" exit 3 esac exit 0
- chmod 755 /etc/init.d/virtualbox
- update-rc.d virtualbox defaults
- one last adjustment to make sure there is enough time between the vboxdrv and vboxnet starting and virtualbox: mv /etc/rc2.d/S20virtualbox /etc/rc2/d/S99virtualbox
- That should be it. Now when you shutdown the virtualmachines should be saved and when you boot the virtualmachines should start up.
Init script created by a great co-worker of mine. Could not have done this without his help. It works great, think I like this setup better than vmware.
Recent Comments