Index: /trunk/src/VBox/Installer/linux/prerm-common.sh
===================================================================
--- /trunk/src/VBox/Installer/linux/prerm-common.sh	(revision 57867)
+++ /trunk/src/VBox/Installer/linux/prerm-common.sh	(revision 57868)
@@ -31,4 +31,27 @@
 . "./routines.sh"
 
+DO_DKMS=
+VERSION=
+while true
+do
+    test -z "${1}" && break
+    case "${1}" in
+        --dkms)
+            DO_DKMS=true
+            shift
+            VERSION="${1}"
+            if test -z "${VERSION}"; then
+                echo "--dkms requires a version"
+                exit 1
+            fi
+            ;;
+        *)
+            echo "Bad argument ${1}" >&2
+            exit 1
+            ;;
+    esac
+    shift
+done
+
 # Stop the ballon control service
 stop_init_script vboxballoonctrl-service 2>/dev/null
@@ -37,5 +60,6 @@
 # Stop the web service
 stop_init_script vboxweb-service 2>/dev/null
-# Do this check here after we terminated the web service
+# Do this check here after we terminated the web service: check whether VBoxSVC
+# is running and exit if it can't be stopped.
 check_running
 # Terminate VBoxNetDHCP if running
@@ -49,4 +73,11 @@
 delrunlevel vboxweb-service
 remove_init_script vboxweb-service
+DKMS=`which dkms 2>/dev/null`
+if test "$DO_DKMS" = true && test -n "$DKMS"; then
+  $DKMS remove -m vboxhost -v "${VERSION}" --all > /dev/null 2>&1
+  $DKMS remove -m vboxdrv -v "${VERSION}" --all > /dev/null 2>&1
+  $DKMS remove -m vboxnetflt -v "${VERSION}" --all > /dev/null 2>&1
+  $DKMS remove -m vboxnetadp -v "${VERSION}" --all > /dev/null 2>&1
+fi
 # Stop kernel module and uninstall runlevel script
 stop_init_script vboxdrv 2>/dev/null
Index: /trunk/src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec
===================================================================
--- /trunk/src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec	(revision 57867)
+++ /trunk/src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec	(revision 57868)
@@ -321,31 +321,25 @@
     /sbin/rcvboxdrv stop || true
   fi
-  if [ $REGISTER_MODULES -eq 1 ]; then
-    DKMS=`which dkms 2>/dev/null`
-    if [ -n "$DKMS" ]; then
-      $DKMS remove -m vboxhost -v %VER% --all > /dev/null 2>&1 || true
-    fi
-  fi
 fi
 # Install and start the new service scripts.
-/usr/lib/virtualbox/prerm-common.sh
-/usr/lib/virtualbox/postinst-common.sh /usr/lib/virtualbox --start > /dev/null
+PRERM_DKMS=
+test "${REGISTER_MODULES}" = 1 && PRERM_DKMS="--dkms %VER%"
+POSTINST_START=--start
+test "${INSTALL_NO_VBOXDRV}" = 1 && POSTINST_START=
+/usr/lib/virtualbox/prerm-common.sh ${PRERM_DKMS} || true
+/usr/lib/virtualbox/postinst-common.sh /usr/lib/virtualbox "${POSTINST_START}" > /dev/null || true
 
 
 %preun
+# Called before the package is removed, or during upgrade after (not before)
+# the new version's "post" scriptlet. 
 # $1==0: remove the last version of the package
-# $1==1: install the first time
-# $1>=2: upgrade
+# $1>=1: upgrade
 if [ "$1" = 0 ]; then
-  /usr/lib/virtualbox/prerm-common.sh || exit 1
+  /usr/lib/virtualbox/prerm-common.sh --dkms || exit 1
   rm -f /etc/udev/rules.d/60-vboxdrv.rules
   rm -f /etc/vbox/license_agreed
   rm -f /etc/vbox/module_not_compiled
 fi
-DKMS=`which dkms 2>/dev/null`
-if [ -n "$DKMS" ]; then
-  $DKMS remove -m vboxhost -v %VER% --all > /dev/null 2>&1 || true
-fi
-
 
 %postun
