Index: trunk/src/VBox/Additions/solaris/Installer/makepackage.sh
===================================================================
--- trunk/src/VBox/Additions/solaris/Installer/makepackage.sh	(revision 39224)
+++ trunk/src/VBox/Additions/solaris/Installer/makepackage.sh	(revision 39235)
@@ -59,4 +59,9 @@
 }
 
+dirlist_fixup()
+{
+  "$VBOX_AWK" 'NF == 6 && $1 == "d" && '"$2"' { '"$3"' } { print }' "$1" > "tmp-$1"
+  mv -f "tmp-$1" "$1"
+}
 
 # Create relative hardlinks
@@ -81,5 +86,5 @@
 
 # Include opt/VirtualBoxAdditions and subdirectories as we want uninstall to clean up directory structure as well
-find . -type d | $VBOX_GGREP -E 'opt/VirtualBoxAdditions' | pkgproto >> prototype
+find . -type d | $VBOX_GGREP -E 'opt/VirtualBoxAdditions|var/svc/manifest/application/virtualbox' | pkgproto >> prototype
 
 # Include /etc/fs/vboxfs (as we need to create the subdirectory)
@@ -94,7 +99,14 @@
 filelist_fixup prototype '$3 == "opt/VirtualBoxAdditions/amd64/VBoxService"'                                 '$4 = "4755"'
 
+# Manifest class action scripts
+filelist_fixup prototype '$3 == "var/svc/manifest/application/virtualbox/vboxservice.xml"'                   '$2 = "manifest";$6 = "sys"'
+
 # vboxguest
 filelist_fixup prototype '$3 == "usr/kernel/drv/vboxguest"'                                                  '$6="sys"'
 filelist_fixup prototype '$3 == "usr/kernel/drv/amd64/vboxguest"'                                            '$6="sys"'
+
+# Use 'root' as group so as to match attributes with the previous installation and prevent a conflict. Otherwise pkgadd bails out thinking
+# we're violating directory attributes of another (non existing) package
+dirlist_fixup prototype  '$3 == "var/svc/manifest/application/virtualbox"'                                   '$6 = "root"'
 
 echo " --- start of prototype  ---"
Index: trunk/src/VBox/Additions/solaris/Installer/postinstall.sh
===================================================================
--- trunk/src/VBox/Additions/solaris/Installer/postinstall.sh	(revision 39224)
+++ trunk/src/VBox/Additions/solaris/Installer/postinstall.sh	(revision 39235)
@@ -77,4 +77,43 @@
 }
 
+abort()
+{
+    echo 1>&2 "## $1"
+    exit 1
+}
+
+get_sysinfo()
+{
+    BIN_PKG=`which pkg 2> /dev/null`
+    if test -x "$BIN_PKG"; then
+        PKGFMRI=`$BIN_PKG contents -H -t set -a name=pkg.fmri -o pkg.fmri pkg:/system/kernel 2> /dev/null`
+        if test ! -z "$PKGFMRI"; then
+            # The format is "pkg://solaris/system/kernel@0.5.11,5.11-0.161:20110315T070332Z"
+            #            or "pkg://solaris/system/kernel@0.5.11,5.11-0.175.0.0.0.1.0:20111012T032837Z"
+            STR_KERN=`echo "$PKGFMRI" | sed 's/^.*\@//;s/\:.*//;s/.*,//'`
+            if test ! -z "$STR_KERN"; then
+                # The format is "5.11-0.161" or "5.11-0.175.0.0.0.1.0"
+                HOST_OS_MAJORVERSION=`echo "$STR_KERN" | cut -f1 -d'-'`
+                HOST_OS_MINORVERSION=`echo "$STR_KERN" | cut -f2 -d'-' | cut -f2 -d '.'`
+            else
+                abort "Failed to parse the Solaris kernel version."
+            fi        
+        else
+            abort "Failed to detect the Solaris kernel version."
+        fi
+    else
+        HOST_OS_MAJORVERSION=`uname -r`
+        if test -z "$HOST_OS_MAJORVERSION" || test "$HOST_OS_MAJORVERSION" != "5.10";  then
+            # S11 without 'pkg' ?? Something's wrong... bail.
+            abort "Solaris $HOST_OS_MAJOR_VERSION detected without executable $BIN_PKG !? Confused."
+        fi
+        # Use uname to verify it's S10.
+        # Major version is S10, Minor version is no longer relevant (or used), use uname -v so it gets something
+        # like "Generic_blah" for purely cosmetic purposes
+        HOST_OS_MINORVERSION=`uname -v`
+    fi
+    echo "Detected Solaris $HOST_OS_MAJORVERSION version $HOST_OS_MINORVERSION"
+}
+
 solaris64dir="amd64"
 solaris32dir="i386"
@@ -83,4 +122,6 @@
 vboxadditions64_path=$vboxadditions_path/$solaris64dir
 
+# get OS details
+get_sysinfo
 # get the current zone
 currentzone=`zonename`
@@ -393,11 +434,9 @@
 
 if test "$currentzone" = "global"; then
-    # Setup our VBoxService SMF service
+    /usr/sbin/devfsadm -i vboxguest
+
+    # Setup our VBoxService SMF service (needs the full FMRI here)
     echo "Configuring service..."
-
-    /usr/sbin/svccfg import /var/svc/manifest/system/virtualbox/vboxservice.xml
-    /usr/sbin/svcadm enable svc:/system/virtualbox/vboxservice
-
-    /usr/sbin/devfsadm -i vboxguest
+    /usr/sbin/svcadm enable -s svc:/application/virtualbox/vboxservice
 
     # Update boot archive
Index: trunk/src/VBox/Additions/solaris/Installer/preremove.sh
===================================================================
--- trunk/src/VBox/Additions/solaris/Installer/preremove.sh	(revision 39224)
+++ trunk/src/VBox/Additions/solaris/Installer/preremove.sh	(revision 39235)
@@ -23,16 +23,18 @@
 #
 
-echo "VirtualBox Guest Additions - preremove script"
-echo "This script will unload the VirtualBox Guest kernel module..."
+echo "Removing VirtualBox service..."
 
 # stop and unregister VBoxService daemon
-/usr/sbin/svcadm disable -s svc:/system/virtualbox/vboxservice:default
-/usr/sbin/svccfg delete svc:/system/virtualbox/vboxservice:default
+/usr/sbin/svcadm disable -s virtualbox/vboxservice:default
+# Don't need to delete, taken care of by the manifest action
+# /usr/sbin/svccfg delete svc:/application/virtualbox/vboxservice:default
 
 # stop VBoxClient
 pkill -INT VBoxClient
 
+echo "Removing VirtualBox kernel modules..."
+
 # vboxguest.sh would've been installed, we just need to call it.
-/opt/VirtualBoxAdditions/vboxguest.sh stopall
+/opt/VirtualBoxAdditions/vboxguest.sh stopall silentunload
 
 # remove devlink.tab entry for vboxguest
Index: trunk/src/VBox/Additions/solaris/Installer/vboxguest.pkginfo
===================================================================
--- trunk/src/VBox/Additions/solaris/Installer/vboxguest.pkginfo	(revision 39224)
+++ trunk/src/VBox/Additions/solaris/Installer/vboxguest.pkginfo	(revision 39235)
@@ -11,5 +11,5 @@
 HOTLINE="Please contact your local service provider"
 BASEDIR="/"
-CLASSES=none sed
+CLASSES=none manifest
 DESC="@VBOX_PRODUCT@ Guest Additions for Solaris guests"
 
Index: trunk/src/VBox/Additions/solaris/Installer/vboxguest.sh
===================================================================
--- trunk/src/VBox/Additions/solaris/Installer/vboxguest.sh	(revision 39224)
+++ trunk/src/VBox/Additions/solaris/Installer/vboxguest.sh	(revision 39235)
@@ -27,5 +27,5 @@
 VFSMODNAME="vboxfs"
 MODDIR32="/usr/kernel/drv"
-MODDIR64=$MODDIR32/amd64
+MODDIR64="/usr/kernel/drv/amd64"
 VFSDIR32="/usr/kernel/fs"
 VFSDIR64="/usr/kernel/fs/amd64"
@@ -114,5 +114,5 @@
 {
     if vboxguest_loaded; then
-        /usr/sbin/rem_drv $MODNAME || abort "## Failed to unload VirtualBox guest kernel module."
+        /usr/sbin/rem_drv $MODNAME || abort "Failed to unload VirtualBox guest kernel module."
         info "VirtualBox guest kernel module unloaded."
     elif test -z "$SILENTUNLOAD"; then
@@ -148,20 +148,4 @@
 }
 
-restart_module()
-{
-    stop_module
-    sync
-    start_module
-    return 0
-}
-
-restart_all()
-{
-    stop_module
-    sync
-    start_module
-    return 0
-}
-
 status_module()
 {
@@ -180,4 +164,12 @@
 }
 
+restart_all()
+{
+    stop_all
+    start_module
+    start_vboxfs
+    return 0
+}
+
 check_root
 check_if_installed
@@ -199,7 +191,4 @@
 stop)
     stop_module
-    ;;
-restart)
-    restart_module
     ;;
 status)
Index: trunk/src/VBox/Additions/solaris/Installer/vboxservice.xml
===================================================================
--- trunk/src/VBox/Additions/solaris/Installer/vboxservice.xml	(revision 39224)
+++ trunk/src/VBox/Additions/solaris/Installer/vboxservice.xml	(revision 39235)
@@ -25,8 +25,8 @@
 <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
 
-<service_bundle type='manifest' name='export'>
+<service_bundle type='manifest' name='SUNWvboxguest:vboxservice'>
 
 <service
-    name='system/virtualbox/vboxservice'
+    name='application/virtualbox/vboxservice'
     type='service'
     version='1'>
Index: trunk/src/VBox/Additions/solaris/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/solaris/Makefile.kmk	(revision 39224)
+++ trunk/src/VBox/Additions/solaris/Makefile.kmk	(revision 39235)
@@ -69,5 +69,5 @@
 SOLARIS_ADD_USRBIN_DIR                  := $(SOLARIS_ADDINST_OUT_DIR)/usr/bin
 SOLARIS_ADD_ETCFS_DIR                   := $(SOLARIS_ADDINST_OUT_DIR)/etc/fs/vboxfs
-SOLARIS_ADD_SERVICESINST_DIR            := $(SOLARIS_ADDINST_OUT_DIR)/var/svc/manifest/system/virtualbox
+SOLARIS_ADD_SERVICESINST_DIR            := $(SOLARIS_ADDINST_OUT_DIR)/var/svc/manifest/application/virtualbox
 
 ifeq ($(KBUILD_TARGET_ARCH),x86)
@@ -149,6 +149,6 @@
 	var/svc \
 	var/svc/manifest \
-	var/svc/manifest/system \
-	var/svc/manifest/system/virtualbox \
+	var/svc/manifest/application \
+	var/svc/manifest/application/virtualbox \
 	)
 
@@ -302,4 +302,5 @@
 	$(call MSG_L1,Creating install package: $@)
 	$(QUIET)$(MKDIR) -p $(SOLARIS_ADD_ETCFS_DIR)
+	$(QUIET)$(MKDIR) -p $(VBOX_PATH_SOLARIS_ADDITION_INSTALLER)
 	$(QUIET)$(LN_SYMLINK) -f ../..$(SOLARIS_VBOXADDINST_SUBDIR)/1099.vboxclient                           $(SOLARIS_ADD_USRBIN_DIR)/VBoxClient-all
 ifdef VBOX_WITH_COMBINED_SOLARIS_GUEST_PACKAGE
@@ -315,4 +316,5 @@
 	$(LN_SYMLINK) -f ../../..$(SOLARIS_VBOXADDINST_SUBDIR)/$(SOLARIS_ADDDIR_NAME_ISA)/vboxfsmount         $(SOLARIS_ADD_ETCFS_DIR)/mount
 endif
+	$(QUIET)$(INSTALL) -m 0644 $(VBOX_PATH_SOLARIS_ADDITION_INSTALLER)/vboxservice.xml                    $(SOLARIS_ADD_SERVICESINST_DIR)/vboxservice.xml
 	$(QUIET)$(SOLARIS_ADDINST_OUT_DIR)/makepackage.sh $(SOLARIS_ADDINST_OUT_DIR) $(PKGFILENAME) $(VBOX_SVN_REV)
 	$(QUIET)$(INSTALL) -m 0644 $(SOLARIS_ADDINST_OUT_DIR)/$(PKGFILENAME) $(PATH_STAGE_BIN)/additions/$(PKGFILENAME)
