Improve VirtualBox shared folders + support vboxdrv service
authorMichael Prokop <mika@grml.org>
Thu, 13 Aug 2020 07:55:45 +0000 (09:55 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 13 Aug 2020 07:55:45 +0000 (09:55 +0200)
The virtualbox shared folders code couldn't be skipped during runtime,
so add support boot option "novboxsf" to skip shared folders setup.

While at it reduce code complexity in config_virtualbox_shared_folders()
(by returning when not running under virtualbox).

Also do not hard code "grml" user to be added to vboxsf group, but rely
on $fstabuser instead.

If VirtualBox (not the guest additions, but the application itself) can
be started on Grml live system, then the /usr/bin/VBox exectuable is
present. The vboxdrv driver might not be loaded yet, take care of it via
vboxdrv.service. Also add user to vboxusers group. To be able to easily
skip it (via boot option "novbox") integrate in grml-autoconfig and not
into systemd presets.

This work was funded by Grml-Forensic.

autoconfig
autoconfig.functions
grml-autoconfig

index 88aa2ae..b98e4ca 100644 (file)
@@ -82,6 +82,7 @@ CONFIG_TESTCD='yes'           # CD checker
 CONFIG_TIME='yes'             # set clock, check for bootparam utc/gmt [only in live-mode]
 CONFIG_TIMEZONE='yes'         # get bootparam 'tz' and set it as /etc/localtime [only in live-mode]
 CONFIG_VIRTUALBOX_SHARED_FOLDERS='yes' # set up shared folders in VirtualBox environment
 CONFIG_TIME='yes'             # set clock, check for bootparam utc/gmt [only in live-mode]
 CONFIG_TIMEZONE='yes'         # get bootparam 'tz' and set it as /etc/localtime [only in live-mode]
 CONFIG_VIRTUALBOX_SHARED_FOLDERS='yes' # set up shared folders in VirtualBox environment
+CONFIG_VIRTUALBOX_SETUP='yes' # set up VirtuaBox service (iff present)
 CONFIG_VNC='yes'              # check for bootparam vnc
 CONFIG_XSTARTUP='yes'         # start X window system via grml-x [only in live-mode]
 
 CONFIG_VNC='yes'              # check for bootparam vnc
 CONFIG_XSTARTUP='yes'         # start X window system via grml-x [only in live-mode]
 
index 3aa9787..8b1c8af 100755 (executable)
@@ -1847,16 +1847,22 @@ fi # checkbootparam "BOOT_IMAGE=debian2hd
 
 # {{{ virtualbox shared folders
 config_virtualbox_shared_folders() {
 
 # {{{ virtualbox shared folders
 config_virtualbox_shared_folders() {
-if $VIRTUALBOX ; then
-  einfo "VirtualBox detected, trying to set up Shared Folders."
-  if ! modinfo vboxsf &>/dev/null ; then
-    ewarn "vboxsf driver not present, not setting up VirtualBox Shared Folders."
-    eend 0
-  elif ! [ -x /usr/sbin/VBoxService ] ; then
-    ewarn "virtualbox-guest-utils not installed, not setting up VirtualBox Shared Folders."
-    eend 0
+  if ! $VIRTUALBOX ; then
+    return
+  fi
+
+  if checkbootparam 'novboxsf' ; then
+    ewarn "Skipping VirtualBox Shared Folders setup as requested on boot commandline." ; eend 0
   else
   else
-    eindent
+    einfo "VirtualBox detected, trying to set up Shared Folders."
+    if ! modinfo vboxsf &>/dev/null ; then
+      ewarn "vboxsf driver not present, not setting up VirtualBox Shared Folders."
+      eend 0
+    elif ! [ -x /usr/sbin/VBoxService ] ; then
+      ewarn "virtualbox-guest-utils not installed, not setting up VirtualBox Shared Folders."
+      eend 0
+    else
+      eindent
 
       einfo "Loading vboxsf driver."
       lsmod | grep -q vboxsf || modprobe vboxsf
 
       einfo "Loading vboxsf driver."
       lsmod | grep -q vboxsf || modprobe vboxsf
@@ -1869,8 +1875,8 @@ if $VIRTUALBOX ; then
 
       config_userfstab
 
 
       config_userfstab
 
-      einfo "Adding $fstabuser to group vboxsf."
-      adduser grml vboxsf &>/dev/null
+      einfo "Adding user ${fstabuser:-grml} to group vboxsf."
+      adduser "${fstabuser:-grml}" vboxsf >>"${DEBUG}" 2>&1
       eend $?
 
       einfo "Starting VBoxService."
       eend $?
 
       einfo "Starting VBoxService."
@@ -1931,9 +1937,29 @@ if $VIRTUALBOX ; then
         fi
       fi
 
         fi
       fi
 
-    eoutdent
+      eoutdent
+    fi
+  fi
+}
+# }}}
+
+# {{{ VirtualBox application
+config_virtualbox_setup() {
+  if checkbootparam 'novbox' ; then
+    ewarn "Skipping VirtualBox setup as requested on boot commandline." ; eend 0
+    return
+  fi
+
+  if [ -x /usr/bin/VBox ] ; then
+    einfo "VirtualBox service detected, trying to set up."
+    service_wrapper vboxdrv restart >>"${DEBUG}" 2>&1 ; eend $?
+
+    config_userfstab
+
+    einfo "Adding user ${fstabuser:-grml} to group vboxusers."
+    adduser "${fstabuser:-grml}" vboxusers >>"${DEBUG}" 2>&1
+    eend $?
   fi
   fi
-fi
 }
 # }}}
 
 }
 # }}}
 
index a0d4a4c..6e71b4d 100755 (executable)
@@ -135,6 +135,8 @@ checkvalue $CONFIG_CONSOLE && config_console
 
 checkvalue $CONFIG_VIRTUALBOX_SHARED_FOLDERS && config_virtualbox_shared_folders
 
 
 checkvalue $CONFIG_VIRTUALBOX_SHARED_FOLDERS && config_virtualbox_shared_folders
 
+checkvalue $CONFIG_VIRTUALBOX_SETUP && config_virtualbox_setup
+
 checkvalue $CONFIG_MYPATH && config_mypath
 
 checkvalue $CONFIG_DISTRI && config_distri
 checkvalue $CONFIG_MYPATH && config_mypath
 
 checkvalue $CONFIG_DISTRI && config_distri