vboxdrv.sh.in revision 3fc17454dc709b89e326d2cbe0ec35a607154f08
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Oracle VM VirtualBox
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Linux kernel module init script
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Copyright (C) 2006-2010 Oracle Corporation
c58f1213e628a545081c70e26c6b67a841cff880vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# available from http://www.virtualbox.org. This file is free software;
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# you can redistribute it and/or modify it under the terms of the GNU
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# General Public License (GPL) as published by the Free Software
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# chkconfig: 35 20 80
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# description: VirtualBox Linux kernel module
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync### BEGIN INIT INFO
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Provides: vboxdrv
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Required-Start: $syslog
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Required-Stop:
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Default-Start: 2 3 4 5
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Default-Stop: 0 1 6
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# Short-Description: VirtualBox Linux kernel module
0fc8a97f9a19a44f1ad4670454edf26d80c42281vboxsync### END INIT INFO
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsyncif $MODPROBE -c | grep -q '^allow_unsupported_modules *0'; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsyncif [ -n "$INSTALL_DIR" ]; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync BUILDVBOXDRV="$INSTALL_DIR/src/vboxhost/vboxdrv/build_in_tmp"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync BUILDVBOXNETFLT="$INSTALL_DIR/src/vboxhost/vboxnetflt/build_in_tmp"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync BUILDVBOXNETADP="$INSTALL_DIR/src/vboxhost/vboxnetadp/build_in_tmp"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync BUILDVBOXPCI="$INSTALL_DIR/src/vboxhost/vboxpci/build_in_tmp"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync BUILDVBOXDRV="/usr/share/%PACKAGE%/src/vboxhost/vboxdrv/build_in_tmp"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync BUILDVBOXNETFLT="/usr/share/%PACKAGE%/src/vboxhost/vboxnetflt/build_in_tmp"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync BUILDVBOXNETADP="/usr/share/%PACKAGE%/src/vboxhost/vboxnetadp/build_in_tmp"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync BUILDVBOXPCI="/usr/share/%PACKAGE%/src/vboxhost/vboxpci/build_in_tmp"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# silently exit if the package was uninstalled but not purged,
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# applies to Debian packages only
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync[ -z "$DEBIAN" -o -x $VBOXMANAGE -a -x $BUILDVBOXDRV ] || exit 0
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsyncif [ -n "$NOLSB" ]; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync[ -r /etc/default/%PACKAGE% ] && . /etc/default/%PACKAGE%
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsyncif [ -z "$NOLSB" ]; then
dc959f60f6d3e0cba86f7da4d39aa475913a7e10vboxsync if [ -d /proc/xen ]; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync failure "Running VirtualBox in a Xen environment is not supported"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if ! rm -f $DEVICE; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if [ ! -c $DEVICE ]; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync failure "Cannot change group %GROUP% for device $DEVICE"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if ! $MODPROBE vboxnetflt > /dev/null 2>&1; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if ! $MODPROBE vboxnetadp > /dev/null 2>&1; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync failure "modprobe vboxpci failed. Please use 'dmesg' to find out why"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync # Create the /dev/vboxusb directory if the host supports that method
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync # of USB access. The USB code checks for the existance of that path.
dc959f60f6d3e0cba86f7da4d39aa475913a7e10vboxsync if ! rmmod vboxnetadp 2>/dev/null; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if ! rmmod vboxnetflt 2>/dev/null; then
97803398b9554900b4dd45f88b2eb2056e2c606bvboxsync if ! rm -f $DEVICE; then
97803398b9554900b4dd45f88b2eb2056e2c606bvboxsync# enter the following variables in /etc/default/%PACKAGE%:
97803398b9554900b4dd45f88b2eb2056e2c606bvboxsync# SHUTDOWN_USERS="foo bar"
97803398b9554900b4dd45f88b2eb2056e2c606bvboxsync# check for running VMs of user foo and user bar
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# SHUTDOWN=poweroff
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# SHUTDOWN=acpibutton
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# SHUTDOWN=savestate
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# select one of these shutdown methods for running VMs
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync # don't create the ipcd directory with wrong permissions!
dc959f60f6d3e0cba86f7da4d39aa475913a7e10vboxsync if [ -d /tmp/.vbox-$i-ipc ]; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync begin_msg "Sending ACPI power button event to remaining VMs"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync begin_msg "Waiting for $wait seconds for VM shutdown"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync# setup_script
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync begin_msg "Uninstalling old VirtualBox DKMS kernel modules"
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync if find /lib/modules/`uname -r` -name "vboxpci\.*" 2>/dev/null|grep -q vboxpci; then
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync begin_msg "Removing old VirtualBox pci kernel module"
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync find /lib/modules/`uname -r` -name "vboxpci\.*" 2>/dev/null|xargs rm -f 2>/dev/null
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync if find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|grep -q vboxnetadp; then
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync begin_msg "Removing old VirtualBox netadp kernel module"
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|xargs rm -f 2>/dev/null
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync if find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|grep -q vboxnetflt; then
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync begin_msg "Removing old VirtualBox netflt kernel module"
25be0b1daccd180b98ac7bd0a81e2acb75db6146vboxsync find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|xargs rm -f 2>/dev/null
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync begin_msg "Trying to register the VirtualBox kernel modules using DKMS"
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if ! $DODKMS install >> $LOG; then
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync --save-module-symvers /tmp/vboxdrv-Module.symvers \
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync echo "VirtualBox kernel modules ($str) are loaded."
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync # don't create the ipcd directory with wrong permissions!
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync if [ -d /tmp/.vbox-$i-ipc ]; then
54d13d84f69d613c39bf7672d4095c8d863176efvboxsync VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null`
74fdb8a41a8fdc04e44a1ecaeefb70ed9a7a1e47vboxsync echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}"