3
# Linux kernel module init script
6
# Copyright (C) 2006-2009 Sun Microsystems, Inc.
8
# This file is part of VirtualBox Open Source Edition (OSE), as
9
# available from http://www.virtualbox.org. This file is free software;
10
# you can redistribute it and/or modify it under the terms of the GNU
11
# General Public License (GPL) as published by the Free Software
12
# Foundation, in version 2 as it comes in the "COPYING" file of the
13
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18
# description: VirtualBox Linux kernel module
21
# Provides: vboxdrv virtualbox-ose
22
# Required-Start: $remote_fs $network
23
# Required-Stop: $remote_fs
24
# Default-Start: 2 3 4 5
26
# Short-Description: VirtualBox Linux kernel module
29
. /lib/lsb/init-functions
31
test -d /usr/share/doc/virtualbox-ose -a -x /usr/bin/VBoxHeadless || exit 0
33
# Include virtualbox-ose defaults if available
34
[ -r /etc/default/virtualbox-ose ] && . /etc/default/virtualbox-ose
36
# set list of all active users if asked to do so
37
if [ "$SHUTDOWN_USERS" = "all" ]; then
39
for i in /tmp/.vbox-*-ipc; do
40
SHUTDOWN_USERS="$SHUTDOWN_USERS $(echo $i|cut -d'-' -f2)"
44
if [ "$LOAD_VBOXDRV_MODULE" != 1 ]; then
45
log_success_msg "virtualbox-ose disabled; edit /etc/default/virtualbox-ose"
51
lsmod | grep -q "$1[^_-]"
56
log_begin_msg "Starting VirtualBox kernel modules"
58
if ! running vboxdrv; then
59
# HACK: disable the hardware performance counter framework
60
if [ -e /proc/sys/kernel/perf_counter_paranoid ]; then
61
if [ $(cat /proc/sys/kernel/perf_counter_paranoid) -ne 2 ]; then
62
log_warning_msg "Disabling the hardware performance counter framework"
63
echo 2 > /proc/sys/kernel/perf_counter_paranoid
67
if ! modprobe vboxdrv > /dev/null 2>&1; then
68
if ! find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
69
log_failure_msg "No suitable module for running kernel found"
71
log_failure_msg "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
78
if ! running vboxnetadp; then
79
if ! modprobe vboxnetadp > /dev/null 2>&1; then
80
if ! find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|grep -q vboxnetadp; then
81
log_failure_msg "No suitable vboxnetflt module for running kernel found"
83
log_failure_msg "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
90
if ! running vboxnetflt; then
91
if ! modprobe vboxnetflt > /dev/null 2>&1; then
92
if ! find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|grep -q vboxnetflt; then
93
log_failure_msg "No suitable vboxnetadp module for running kernel found"
95
log_failure_msg "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
107
log_begin_msg "Stopping VirtualBox kernel modules"
109
if running vboxnetadp; then
110
if ! rmmod vboxnetadp 2>/dev/null; then
111
log_failure_msg "Cannot unload module vboxnetadp"
117
if running vboxdrv; then
118
if running vboxnetflt; then
119
if ! rmmod vboxnetflt 2>/dev/null; then
120
log_failure_msg "Cannot unload module vboxnetflt"
126
if ! rmmod vboxdrv 2>/dev/null; then
127
log_failure_msg "Cannot unload module vboxdrv"
136
# enter the following variables in /etc/default/virtualbox-ose:
137
# SHUTDOWN_USERS="foo bar"
138
# check for running VMs of user foo and user bar
140
# SHUTDOWN=acpibutton
142
# select one of these shutdown methods for running VMs
145
if ! pidof VBoxSVC > /dev/null; then
151
for i in $SHUTDOWN_USERS; do
152
if [ -d /tmp/.vbox-$i-ipc ]; then
153
export VBOX_IPC_SOCKETID="$i"
154
VMS=`VBoxManage --nologo list runningvms 2>/dev/null`
155
if [ $? -eq 0 -a -n "$VMS" ]; then
156
VMS=`echo "$VMS" | sed -e 's/^".*".*{\(.*\)}/\1/'`
157
if [ "$SHUTDOWN" = "poweroff" ]; then
158
log_action_msg "Powering off remaining VMs from user $i"
160
VBoxManage --nologo controlvm $v poweroff
163
elif [ "$SHUTDOWN" = "acpibutton" ]; then
164
log_action_msg "Sending ACPI power button event to remaining VMs from user $i"
166
VBoxManage --nologo controlvm $v acpipowerbutton
169
elif [ "$SHUTDOWN" = "savestate" ]; then
170
log_action_msg "Saving state of remaining VMs from user $i"
172
VBoxManage --nologo controlvm $v savestate
180
# wait for some seconds when doing ACPI shutdown
181
if [ "$wait" -ne 0 ]; then
182
log_action_begin_msg "Waiting for $wait seconds for VM shutdown"
191
if running vboxdrv; then
192
if running vboxnetflt; then
193
if running vboxnetadp; then
194
echo "VirtualBox kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are loaded."
196
echo "VirtualBox kernel modules (vboxdrv and vboxnetflt) are loaded."
199
echo "VirtualBox kernel module is loaded."
202
for i in $SHUTDOWN_USERS; do
203
if [ -d /tmp/.vbox-$i-ipc ]; then
204
export VBOX_IPC_SOCKETID="$i"
205
VMS=`VBoxManage --nologo list runningvms 2>/dev/null`
206
if [ $? -eq 0 -a -n "$VMS" ]; then
207
VMS=`echo "$VMS" | sed -e 's/^".*".*{\(.*\)}/\1/'`
208
echo "The following VMs are currently running:"
217
echo "VirtualBox kernel module is not loaded."
232
restart|force-reload)
233
stop_vms && stop && start
239
echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status}"