d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#!/bin/bash
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# $Id$
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync## @file
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# For development.
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
5ac633771fea62a5236149adb3353126380945f6vboxsync# Copyright (C) 2006-2015 Oracle Corporation
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# available from http://www.virtualbox.org. This file is free software;
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# you can redistribute it and/or modify it under the terms of the GNU
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# General Public License (GPL) as published by the Free Software
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# The contents of this file may alternatively be used under the terms
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# of the Common Development and Distribution License Version 1.0
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# VirtualBox OSE distribution, in which case the provisions of the
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# CDDL are applicable instead of those of the GPL.
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# You may elect to license modified versions of this file under the
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# terms and conditions of either the GPL or the CDDL or both.
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncDRVNAME="vboxdrv"
c7cd98a3e0c214e3bb1adf79883105c008ec317avboxsyncDRIVERS_USING_IT="vboxusb vboxusbmon vboxnet vboxflt vboxbow"
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncDRVFILE=`dirname "$0"`
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncDRVFILE=`cd "$DRVFILE" && pwd`
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncDRVFILE="$DRVFILE/$DRVNAME"
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncif [ ! -f "$DRVFILE" ]; then
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync echo "load.sh: Cannot find $DRVFILE or it's not a file..."
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync exit 1;
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncfi
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncif [ ! -f "$DRVFILE.conf" ]; then
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync echo "load.sh: Cannot find $DRVFILE.conf or it's not a file..."
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync exit 1;
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncfi
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncSUDO=sudo
d08609455264c7fe04bc68ed3ffeeae2f8c36e72vboxsync#set -x
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
c7cd98a3e0c214e3bb1adf79883105c008ec317avboxsync# Disable the zone access service.
5ac633771fea62a5236149adb3353126380945f6vboxsyncservicefound=`svcs -H "virtualbox/zoneaccess" 2>/dev/null | grep '^online'`
5ac633771fea62a5236149adb3353126380945f6vboxsyncif test ! -z "$servicefound"; then
5ac633771fea62a5236149adb3353126380945f6vboxsync $SUDO svcadm disable svc:/application/virtualbox/zoneaccess:default
5ac633771fea62a5236149adb3353126380945f6vboxsyncfi
c7cd98a3e0c214e3bb1adf79883105c008ec317avboxsync
99a5f7beff5f7bbf1f73923087d60070ddb717d4vboxsync# Unload driver that may depend on the driver we're going to (re-)load
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# as well as the driver itself.
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncfor drv in $DRIVERS_USING_IT $DRVNAME;
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncdo
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync LOADED=`modinfo | grep -w "$drv"`
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync if test -n "$LOADED"; then
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync MODID=`echo "$LOADED" | cut -d ' ' -f 1`
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync $SUDO modunload -i $MODID;
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync LOADED=`modinfo | grep -w "$drv"`;
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync if test -n "$LOADED"; then
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync echo "load.sh: failed to unload $drv";
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync dmesg | tail
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync exit 1;
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync fi
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync fi
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncdone
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# Reconfigure the driver so it get a major number.
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# Note! We have to copy the driver and config files to somewhere the kernel can
99a5f7beff5f7bbf1f73923087d60070ddb717d4vboxsync# find them. It is searched for as drv/${DRVNAME}.conf in
99a5f7beff5f7bbf1f73923087d60070ddb717d4vboxsync# kobj_module_path, which is usually:
99a5f7beff5f7bbf1f73923087d60070ddb717d4vboxsync# /platform/i86pc/kernel /kernel /usr/kernel
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# To try prevent bad drivers from being loaded on the next boot, we remove
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync# always the files.
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync#
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncMY_RC=1
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncset -e
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync$SUDO rm -f \
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync "/platform/i86pc/kernel/drv/${DRVNAME}.conf" \
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync "/platform/i86pc/kernel/drv/${DRVNAME}" \
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync "/platform/i86pc/kernel/drv/amd64/${DRVNAME}"
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync$SUDO cp "${DRVFILE}" /platform/i86pc/kernel/drv/amd64/
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync$SUDO cp "${DRVFILE}.conf" /platform/i86pc/kernel/drv/
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncset +e
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync$SUDO rem_drv $DRVNAME
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncif $SUDO add_drv -v $DRVNAME; then
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync sync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync if $SUDO modload "/platform/i86pc/kernel/drv/amd64/${DRVNAME}"; then
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync echo "load.sh: successfully loaded the driver"
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync modinfo | grep -w "$DRVNAME"
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync MY_RC=0
5ac633771fea62a5236149adb3353126380945f6vboxsync if test ! -h "/dev/vboxdrv"; then
5ac633771fea62a5236149adb3353126380945f6vboxsync $SUDO ln -sf "/devices/pseudo/vboxdrv@0:vboxdrv" /dev/vboxdrv
5ac633771fea62a5236149adb3353126380945f6vboxsync $SUDO chmod 0666 /dev/vboxdrv
5ac633771fea62a5236149adb3353126380945f6vboxsync fi
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync else
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync dmesg | tail
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync echo "load.sh: modload failed"
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync fi
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncelse
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync dmesg | tail
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync echo "load.sh: add_drv failed."
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncfi
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync$SUDO rm -f \
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync "/platform/i86pc/kernel/drv/${DRVNAME}.conf" \
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync "/platform/i86pc/kernel/drv/${DRVNAME}" \
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync "/platform/i86pc/kernel/drv/amd64/${DRVNAME}"
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync
d318c6184dca5599e44f8c67a7983b30065448f9vboxsyncexit $MY_RC;
d318c6184dca5599e44f8c67a7983b30065448f9vboxsync