vboxdrv.sh.in revision 2915a0b5ad777707014e05b15f65d309d95eabd3
# Oracle VM VirtualBox
# Linux kernel module init script
#
# Copyright (C) 2006-2010 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#
# chkconfig: 35 30 70
# description: VirtualBox Linux kernel module
#
### BEGIN INIT INFO
# Provides: vboxdrv
# Required-Start: $syslog
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: VirtualBox Linux kernel module
### END INIT INFO
fi
if [ -n "$INSTALL_DIR" ]; then
VBOXMANAGE="$INSTALL_DIR/VBoxManage"
else
VBOXMANAGE="/usr/lib/%PACKAGE%/VBoxManage"
BUILDVBOXDRV="/usr/share/%PACKAGE%/src/vboxhost/vboxdrv/build_in_tmp"
BUILDVBOXNETFLT="/usr/share/%PACKAGE%/src/vboxhost/vboxnetflt/build_in_tmp"
BUILDVBOXNETADP="/usr/share/%PACKAGE%/src/vboxhost/vboxnetadp/build_in_tmp"
fi
# silently exit if the package was uninstalled but not purged,
# applies to Debian packages only
if [ -n "$NOLSB" ]; then
if [ -f /etc/redhat-release ]; then
elif [ -f /etc/SuSE-release ]; then
elif [ -f /etc/gentoo-release ]; then
fi
fi
if [ -z "$NOLSB" ]; then
echo ""
log_failure_msg "$1"
}
}
log_daemon_msg "$@"
}
else
if [ "$system" = "redhat" ]; then
echo -n " "
echo
echo " ($1)"
}
echo -n " "
echo
}
elif [ "$system" = "suse" ]; then
rc_status -v
echo " ($1)"
}
rc_status -v
}
elif [ "$system" = "gentoo" ]; then
if [ -f /sbin/functions.sh ]; then
. /sbin/functions.sh
fi
eerror "$1"
}
eend "$?"
}
ebegin "$1"
}
shift
fi
else
echo " ...failed!"
echo " ($1)"
}
echo " ...done."
}
fi
if [ "$system" != "gentoo" ]; then
[ -z "${1:-}" ] && return 1
if [ -z "${2:-}" ]; then
echo -n "$1"
else
echo -n "$1: $2"
fi
}
fi
fi
failure()
{
fail_msg "$1"
exit 0
}
running()
{
}
start()
{
begin_msg "Starting VirtualBox kernel modules"
failure "Running VirtualBox in a Xen environment is not supported"
fi
fi
failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
fi
sleep .2
fi
# ensure the character special exists
if [ ! -c $DEVICE ]; then
MINOR=0
else
MAJOR=10
fi
fi
failure "Cannot locate the VirtualBox device"
fi
fi
fi
# ensure permissions
rmmod vboxnetadp 2>/dev/null
rmmod vboxnetflt 2>/dev/null
fi
if ! $MODPROBE vboxnetflt > /dev/null 2>&1; then
failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
fi
if ! $MODPROBE vboxnetadp > /dev/null 2>&1; then
failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
fi
# of USB access. The USB code checks for the existance of that path.
if grep -q usb_device /proc/devices; then
fi
}
stop()
{
begin_msg "Stopping VirtualBox kernel modules"
if running vboxnetadp; then
if ! rmmod vboxnetadp 2>/dev/null; then
failure "Cannot unload module vboxnetadp"
fi
fi
if running vboxnetflt; then
if ! rmmod vboxnetflt 2>/dev/null; then
failure "Cannot unload module vboxnetflt"
fi
fi
failure "Cannot unload module vboxdrv"
fi
fi
fi
}
# SHUTDOWN_USERS="foo bar"
# check for running VMs of user foo and user bar
# SHUTDOWN=poweroff
# SHUTDOWN=acpibutton
# SHUTDOWN=savestate
# select one of these shutdown methods for running VMs
stop_vms()
{
wait=0
for i in $SHUTDOWN_USERS; do
# don't create the ipcd directory with wrong permissions!
export VBOX_IPC_SOCKETID="$i"
begin_msg "Powering off remaining VMs"
done
begin_msg "Sending ACPI power button event to remaining VMs"
wait=30
done
begin_msg "Saving state of remaining VMs"
done
fi
fi
fi
done
# wait for some seconds when doing ACPI shutdown
fi
}
# setup_script
setup()
{
stop
begin_msg "Uninstalling old VirtualBox DKMS kernel modules"
begin_msg "Removing old VirtualBox netadp kernel module"
fi
begin_msg "Removing old VirtualBox netflt kernel module"
fi
begin_msg "Removing old VirtualBox kernel module"
fi
begin_msg "Trying to register the VirtualBox kernel modules using DKMS"
fail_msg "Failed, trying without DKMS"
begin_msg "Recompiling VirtualBox kernel modules"
if ! $BUILDVBOXDRV \
fi
if ! $BUILDVBOXNETFLT \
--use-module-symvers /tmp/vboxdrv-Module.symvers \
fi
if ! $BUILDVBOXNETADP \
--use-module-symvers /tmp/vboxdrv-Module.symvers \
fi
fi
rm -f /etc/vbox/module_not_compiled
}
{
if running vboxnetflt; then
if running vboxnetadp; then
echo "VirtualBox kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are loaded."
else
echo "VirtualBox kernel modules (vboxdrv and vboxnetflt) are loaded."
fi
else
echo "VirtualBox kernel module is loaded."
fi
for i in $SHUTDOWN_USERS; do
# don't create the ipcd directory with wrong permissions!
export VBOX_IPC_SOCKETID="$i"
echo "The following VMs are currently running:"
echo " $v"
done
fi
fi
done
else
echo "VirtualBox kernel module is not loaded."
fi
}
case "$1" in
;;
stop)
stop
;;
;;
stop && start
;;
stop
;;
;;
;;
*)
echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}"
exit 1
esac
exit 0