Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [SOLVED] Starting Vmware Workstation Modules at Boot (Read 2368 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[SOLVED] Starting Vmware Workstation Modules at Boot

Hello Artix Friends,

Some time ago, I had a little help writing a script to start a vpn daemon that I then put in my /etc/init.d and made executable, added to default runlevel, and it worked like a charm.  My current project is something similar.

Without TPM passthrough on Virtualbox available yet, the system became useless, so I installed Windows 11 as a VM in VM Workstation Player.  However, when I try to launch it, I receive notification error that the modules are not loaded: vmmon and vmnet.

In my /etc/init.d there is a file named vmware that initializes those services and loads the modules.  However, just adding it to a runlevel does no good because it requires an argument after (start | stop | status | restart | stoppable).  If I run it by executing:

Code: [Select]
sudo /etc/init.d/vmware start

The kernel modules load and I can run my VM.  However, just having it added to the runlevel does not provide the start argument.

Do I need to write a separate script or create a symlink to start this on boot, or do you think it would be better to locate the modules and load them another way independent of this script?

The modules are unsigned, and I have already followed VMware's directions on signing them with a private key so that they load automatically with secure boot enabled, but receive no MOK enrollment approval request on reboot.

I can always add the command as a run once in rc.local, but I have been advised against that in the past.  What do you think the best way to go about configuring these modules to load at boot would be?

Note:  I have consulted the how-tos, and followed recommended solutions from VMware and previous forum posts.  I also looked at the OpenRC manual for where to put .conf files listing the modules to be loaded, but creating the vmware_workstation.conf file does not cause a change on reboot.

Could anyone point me  in the right direction on where to go next with this?

Thank you friends

Re: Starting Vmware Workstation Modules at Boot

Reply #1
OpenRC should load any modules listed in /etc/modules-load.d/*.conf. Also, adding a service to a runlevel implies the 'start' argument.

If for some reason that doesn't work, you can try editing your vmware init script and adding the following lines, keep '2>&1' out on the first run for debugging:
Code: [Select]
start_pre() {
        einfo "Loading kernel modules"
        /usr/bin/modprobe vmmon 2>&1
        /usr/bin/modprobe vmnet 2>&1
}

stop_post() {
        einfo "Removing kernel modules"
        /usr/bin/modprobe -r vmmon 2>&1
        /usr/bin/modprobe -r vmnet 2>&1
}

What runlevel did you add vmware to?

Re: Starting Vmware Workstation Modules at Boot

Reply #2
First, thank you for responding!  It can be overwhelming navigating init alone.

this is the /etc/init.d/vmware file:
Code: [Select]
#!/usr/bin/env bash
#
# Copyright 1998-2020 VMware, Inc.  All rights reserved.
#
# This script manages the services needed to run VMware software.
#

# VMWARE_INIT_INFO

ETCDIR=/etc/vmware

. $ETCDIR/bootstrap
libdir="$LIBDIR"/vmware

. "$libdir"/scripts/util.sh

load_settings "$libdir" || exit 1

VNETLIB_LOG=/var/log/vnetlib
PRODUCT_NAME="vmware-vmx"
COMPONENT_NAME="vmware-vmx"

# This comment is a hack to prevent RedHat distributions from outputing
# "Starting <basename of this script>" when running this startup script.
# We just need to write the word daemon followed by a space

# This defines echo_success() and echo_failure() on RedHat
if [ -r "$INITSCRIPTDIR"'/functions' ]; then
   . "$INITSCRIPTDIR"'/functions'
fi

# This defines $rc_done and $rc_failed on S.u.S.E.
if [ -f /etc/rc.config ]; then
   # Don't include the entire file: there could be conflicts
   rc_done=`(. /etc/rc.config; echo "$rc_done")`
   rc_failed=`(. /etc/rc.config; echo "$rc_failed")`
else
   # Make sure the ESC byte is literal: Ash does not support echo -e
   rc_done='                                                           done'
   rc_failed='                                                        failed'
fi

subsys=vmware
driver=vmmon
vnet=vmnet
vmci=vmci
vmci_alias='pci:v000015ADd00000740sv*sd*bc*sc*i*'
vmhgfs=vmhgfs
vsock=vsock
vsock_alias=vmware_vsock

# SHM settings
shmmaxPath=/proc/sys/kernel/shmmax
shmmaxMinValue=268435456 # 256MB

#
# Are we running in a VM?
#
vmwareInVM() {
   "$BINDIR"/checkvm >/dev/null 2>&1
}

#
# Report a positive number if there are any VMs running.
# May not be the actual vmmon reference count.
#
vmmonUseCount() {
   local count
   # Beware of module dependencies here. An exact match is important
   count=`/sbin/lsmod | awk 'BEGIN {n = 0} {if ($1 == "'"$driver"'") n = $3} END {print n}'`
   # If CONFIG_MODULE_UNLOAD is not set in the kernel, lsmod prints '-' instead of the
   # reference count, so ask vmrun, or if we don't have vmrun, look for running vmx processes
   if [ x${count} = "x-" ]
   then
      type vmrun > /dev/null 2>&1
      if [ $? -eq 0 ]
      then
         count=`vmrun list | awk 'BEGIN {n=0} /^Total running VMs:/ {n = $4} END {print n}'`
      else
         count=`ps -afe | grep "/bin/vmware-vmx" | grep -v grep | wc -l`
      fi
   fi
   echo $count
}

# Is a given module loaded?
isLoaded() {
   local module="$1"

   /sbin/lsmod | awk 'BEGIN {n = "no";} {if ($1 == "'"$module"'") n = "yes";} END {print n;}'
}

vmwareLoadModule() {
   /sbin/modprobe "$1" || exit 1
}

vmwareUnloadModule() {
   [ "`isLoaded "$1"`" = 'no' ] && return 0
   # if we ran depmod after removing the modules modprobe -r will not work:
   /sbin/modprobe -r "$1" || /sbin/rmmod $1 || exit 1
}

# Start the virtual machine monitor kernel service
vmwareStartVmmon() {
   vmwareLoadModule $driver
}

# Stop the virtual machine monitor kernel service
vmwareStopVmmon() {
   vmwareUnloadModule $driver
}

# Start the virtual ethernet kernel service
vmwareStartVmnet() {
   vmwareLoadModule $vnet
   "$BINDIR"/vmware-networks --start >> $VNETLIB_LOG 2>&1
}

# Stop the virtual ethernet kernel service
vmwareStopVmnet() {
   "$BINDIR"/vmware-networks --stop >> $VNETLIB_LOG 2>&1
   vmwareUnloadModule $vnet
}

# Returns 0 if networking is enabled, otherwise 1
vmwareIsNetworkingEnabled() {
  [ "$vmdb_NETWORKING" = 'yes' ]
  return
}

vmwareRealModName() {
   # modprobe might be old and not understand the -R option, or
   # there might not be an alias. In both cases we assume
   # that the module is not upstreamed.
   mod=$1
   mod_alias=$2
   alias_file="/lib/modules/$(uname -r)/modules.alias"

   modname=$(/sbin/modprobe -R ${mod_alias} 2>/dev/null)
   if [ $? = 0 -a "$modname" != "" ] ; then
      echo $modname
   elif grep -F ${mod_alias} ${alias_file} >/dev/null 2>&1 ; then
      echo $(grep -F ${mod_alias} ${alias_file} | awk '{print $3}')
   else
      echo $mod
   fi
}

# Ensure the virtual machine communication interface kernel service is present.
vmwareProbeVmci() {
   mod=$(vmwareRealModName $vmci $vmci_alias)

   # only load vmci if it's not already loaded
   if [ "`isLoaded "$mod"`" = 'no' ]; then
      vmwareLoadModule "$mod"
   fi

   return 0
}

# Make sure the system has enough shared memory available to cover shmmaxMinValue.
vmwareCheckSharedMemory() {
   if [ -f "$shmmaxPath" ]; then
      shmmax=`cat $shmmaxPath`
      # If the following arithmetic evaluation overflows, shmmax will certainly
      # be high enough for our needs.
      if [ "$shmmax" == $((shmmax)) ] ; then
         if [ "$shmmax" -lt "$shmmaxMinValue" ] ; then
            echo ""
            echo "Setting the max shared memory the system will allow to $shmmaxMinValue."
            echo ""
            echo "$shmmaxMinValue" > "$shmmaxPath"
         fi
      fi
   fi
   return 0
}


# Probe after vmci is loaded
vmwareProbeVsock() {
   mod=$(vmwareRealModName $vsock $vsock_alias)
   # only load vsock if it's not already loaded
   if [ "`isLoaded "$mod"`" = 'no' ]; then
      vmwareLoadModule "$mod"
   fi

   return 0
}

vmware_start_authdlauncher() {
   vmware_bg_exec "`vmware_product_name` Authentication Daemon" \
      "$SBINDIR/vmware-authdlauncher"
}

vmware_stop_authdlauncher() {
   local launcherpid=`pidof vmware-authdlauncher`
   if [ -n "$launcherpid" ]; then
      vmware_synchrone_kill $launcherpid "TERM"
   fi
}

vmwareService() {
   case "$1" in
      start)
         if vmwareInVM; then
            # Refuse to start services in a VM: they are useless
            exit 1
         fi

         echo 'Starting VMware services:'
         exitcode='0'

         vmware_exec 'Virtual machine monitor' vmwareStartVmmon
         exitcode=$(($exitcode + $?))

         vmware_exec 'Virtual machine communication interface' vmwareProbeVmci
         exitcode=$(($exitcode + $?))

         # vsock needs vmci started first
         vmware_exec 'VM communication interface socket family' vmwareProbeVsock
         # a vsock failure to load shouldn't cause the init to fail completely.

         if [ "`is_vmblock_needed`" = 'yes' ] ; then
            vmware_exec 'Blocking file system' vmware_start_vmblock
            exitcode=$(($exitcode + $?))
         fi

         # Try to load parport_pc.
         /sbin/modprobe parport_pc >/dev/null 2>&1

         if vmwareIsNetworkingEnabled; then
            vmware_exec 'Virtual ethernet' vmwareStartVmnet
            exitcode=$(($exitcode + $?))
         fi

         vmware_exec 'VMware Authentication Daemon' vmware_start_authdlauncher

         if [ "$exitcode" -gt 0 ]; then
            exit 1
         fi

         [ -d /var/lock/subsys ] || mkdir -p /var/lock/subsys
         touch /var/lock/subsys/"$subsys"

         vmware_exec "Shared Memory Available"  vmwareCheckSharedMemory
      ;;

      stop)
         echo 'Stopping VMware services:'
         exitcode='0'

         vmware_exec 'VMware Authentication Daemon' vmware_stop_authdlauncher

         # If the 'K' version of this script is running, the system is
         # stoping services not because the user is running vmware-config.pl
         # or running the initscript directly but because the user wants to
         # shutdown.  Suspend all VMs.
         if [ "`echo $BASENAME | sed -ne '/^K[0-9].vmware/p'`" ] ; then
            if [ -x "$BINDIR"/vmrun ] ; then
               for i in `pidof vmware-vmx` ; do
                  "$BINDIR"/vmrun suspend `ps -p $i -f | \
                       sed -ne '/vmware/s/.* \(\/.*\.vmx\)/\1/p'` 2> /dev/null
               done
            fi

         fi

         if [ "`vmmonUseCount`" -gt 0 ]; then
            echo 'At least one instance of '"$PRODUCT_NAME"' is still running.' 1>&2
            echo 'Please stop all running instances of '"$PRODUCT_NAME"' first.' 1>&2
            echo " " >&2

            # Since we stopped authdlauncher to prevent new connections before disabling
            # any vmxs, need to restart it here to restore the environment back to
            # what it was before this init script ran.
            vmware_exec 'VMware Authentication Daemon' vmware_start_authdlauncher

            # The unconfigurator handle this exit code differently
            exit 2
         fi

         vmware_exec 'Virtual machine monitor' vmwareStopVmmon
         exitcode=$(($exitcode + $?))

         if [ "`is_vmblock_needed`" = 'yes' ] ; then
            vmware_exec 'Blocking file system' vmware_stop_vmblock
            exitcode=$(($exitcode + $?))
         fi

         # Try to unload parport_pc. Failure is allowed as it does not
         # exist on kernels 2.0, and some other process could be using
         # it.
         /sbin/modprobe -r parport_pc >/dev/null 2>&1

         if vmwareIsNetworkingEnabled; then
            vmwareStopVmnet
         fi

         # The vmware and vmware-tray processes don't terminate automatically
         # when the other services are shutdown.  They persist after calling
         # 'init.d/vmware stop' and will happily keep going through an init
         # start command, continuing to minimally function, blissfully ignorant.
         # Time for a buzzkill.
         for i in `pidof vmware vmware-tray` ; do
            vmware_synchrone_kill $i "INT"
         done

         if [ "$exitcode" -gt 0 ]; then
            exit 1
         fi

         rm -f /var/lock/subsys/"$subsys"
      ;;

      status)
         if [ "`vmmonUseCount`" -gt 0 ]; then
            echo 'At least one instance of '"$PRODUCT_NAME"' is still running.'
            echo
            if [ "$2" = "vmcount" ]; then
               exit 2
            fi
         fi
         if [ "$2" = "vmcount" ]; then
               exit 0
         fi

         exitcode='0'

         echo -n "Module $driver "
         [ "`isLoaded "$driver"`" = 'yes' ] && echo loaded || echo "not loaded"
         if vmwareIsNetworkingEnabled; then
            echo -n "Module $vnet "
            [ "`isLoaded "$vnet"`" = 'yes' ] && echo loaded || echo "not loaded"
         fi

         if [ "$exitcode" -gt 0 ]; then
            exit 1
         fi
      ;;

      restart)
         "$SCRIPTNAME" stop && "$SCRIPTNAME" start
      ;;

      # Called to make sure script is in a runnable state.
      validate)
         exit 100
      ;;

      stoppable)
         [ "`vmmonUseCount`" -lt 1 ]
         exit
      ;;

      *)
         echo "Usage: "$BASENAME" {start|stop|status|restart|stoppable}"
         exit 1
   esac
}

SCRIPTNAME="$0"
BASENAME=`basename "$SCRIPTNAME"`

# Check permissions
if [ "`id -ur`" != '0' ]; then
   echo 'Error: you must be root.'
   echo
   exit 1
fi

vmwareService "$1"

exit 0
I added it to the default run level with
Code: [Select]
rc-update add vmware default

After rebooting with this configuration,
Code: [Select]
lsmod |grep vm
vmnet                  73728  0
vmmon                 151552  0

Now, when I try to launch my VMWare workstation player vm, the program closes without launching the VM.

I reviewed /var/kernel.log
Code: [Select]
zaxartix:[zach]:/var/log$ less kernel.log|grep vmmon
Dec 12 17:10:20 zaxartix kernel: /dev/vmmon[8174]: Module vmmon: registered as misc device
Dec 12 17:10:20 zaxartix kernel: /dev/vmmon[8174]: Using tsc_khz as TSC frequency: 3693060
Dec 12 17:10:20 zaxartix kernel: /dev/vmmon[8174]: Module vmmon: initialized
Dec 12 17:35:32 zaxartix kernel: /dev/vmmon[4247]: PTSC: initialized at 3693061000 Hz using TSC, TSCs are synchronized.
Dec 12 17:35:32 zaxartix kernel: /dev/vmmon[4247]: Monitor IPI vector: 0
Dec 12 17:35:32 zaxartix kernel: /dev/vmmon[4247]: HV      IPI vector: 0
Dec 12 17:58:34 zaxartix kernel: /dev/vmmon[4340]: Module vmmon: registered as misc device
Dec 12 17:58:34 zaxartix kernel: /dev/vmmon[4340]: Using tsc_khz as TSC frequency: 3693061
Dec 12 17:58:34 zaxartix kernel: /dev/vmmon[4340]: Module vmmon: initialized
Dec 12 22:19:44 zaxartix kernel: /dev/vmmon[4369]: Module vmmon: registered as misc device
Dec 12 22:19:44 zaxartix kernel: /dev/vmmon[4369]: Using tsc_khz as TSC frequency: 3693060
Dec 12 22:19:44 zaxartix kernel: /dev/vmmon[4369]: Module vmmon: initialized
Dec 12 22:38:14 zaxartix kernel: /dev/vmmon[5275]: Module vmmon: registered as misc device
Dec 12 22:38:14 zaxartix kernel: /dev/vmmon[5275]: Using tsc_khz as TSC frequency: 3693061
Dec 12 22:38:14 zaxartix kernel: /dev/vmmon[5275]: Module vmmon: initialized
Dec 12 22:48:45 zaxartix kernel: /dev/vmmon[6186]: Module vmmon: unloaded
Dec 12 22:48:53 zaxartix kernel: /dev/vmmon[7248]: Module vmmon: registered as misc device
Dec 12 22:48:53 zaxartix kernel: /dev/vmmon[7248]: Using tsc_khz as TSC frequency: 3693061
Dec 12 22:48:53 zaxartix kernel: /dev/vmmon[7248]: Module vmmon: initialized
Dec 12 23:06:07 zaxartix kernel: /dev/vmmon[4470]: PTSC: initialized at 3693060000 Hz using TSC, TSCs are synchronized.
Dec 12 23:06:07 zaxartix kernel: /dev/vmmon[4470]: Monitor IPI vector: 0
Dec 12 23:06:07 zaxartix kernel: /dev/vmmon[4470]: HV      IPI vector: 0
Dec 13 09:49:29 zaxartix kernel: /dev/vmmon[5632]: PTSC: initialized at 3693061000 Hz using TSC, TSCs are synchronized.
Dec 13 09:49:29 zaxartix kernel: /dev/vmmon[5632]: Monitor IPI vector: 0
Dec 13 09:49:29 zaxartix kernel: /dev/vmmon[5632]: HV      IPI vector: 0
Dec 13 23:05:12 zaxartix kernel: /dev/vmmon[5111]: PTSC: initialized at 3693060000 Hz using TSC, TSCs are synchronized.
Dec 13 23:05:12 zaxartix kernel: /dev/vmmon[5111]: Monitor IPI vector: 0
Dec 13 23:05:12 zaxartix kernel: /dev/vmmon[5111]: HV      IPI vector: 0

running the same command but searching for vmnet returned nothing

At this point, I went back and ran
Code: [Select]
sudo /etc/init.d/vmware start

Now, the VM launches when I play it within Workstation.

I did not yet add the additional code to the vmware init file because it looks like it already has some similar instructions:
Code: [Select]
vmwareRealModName() {
   # modprobe might be old and not understand the -R option, or
   # there might not be an alias. In both cases we assume
   # that the module is not upstreamed.
   mod=$1
   mod_alias=$2
   alias_file="/lib/modules/$(uname -r)/modules.alias"

   modname=$(/sbin/modprobe -R ${mod_alias} 2>/dev/null)
   if [ $? = 0 -a "$modname" != "" ] ; then
      echo $modname
   elif grep -F ${mod_alias} ${alias_file} >/dev/null 2>&1 ; then
      echo $(grep -F ${mod_alias} ${alias_file} | awk '{print $3}')
   else
      echo $mod
   fi
}

could it be that there is an issue with how the modprobe command is written in this file?  Again, thank you for spending valuable time on this with me.

Re: Starting Vmware Workstation Modules at Boot

Reply #3
The service script you posted isn't an OpenRC script; it's a generic shell script (#!/usr/bin/env bash instead of #!/usr/sbin/openrc-run). This explains why it doesn't get launched at boot. Where did you get it? You can try vmware-openrc from the AUR instead, which I paste here and seems to do more or less the same things.

Code: [Select]
#!/sbin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
need localmount
use net
}

start() {
#start-stop-daemon --start --exec @@BINDIR@@/vmware-usbarbitrator
/usr/bin/vmware-usbarbitrator

# vmci might be:
# 1) built as external kernel module
# 2) built as internal kernel module (with name vmw_vmci)
# 3) embedded in the kernel
for mod in /lib/modules/$(uname -r)/misc/vmci.ko \
/lib/modules/$(uname -r)/kernel/drivers/misc/vmw_vmci/vmw_vmci.ko ;
do
if [[ -f "${mod}" ]] ; then
modprobe -v $(basename "${mod}" .ko)
eend $?
break
fi
done

# vsock might be:
# 1) built as external kernel module
# 2) built as internal kernel module (with name vmw_vsock_vmci_transport)
# 3) embedded in the kernel
for mod in /lib/modules/$(uname -r)/misc/vsock.ko \
/lib/modules/$(uname -r)/kernel/net/vmw_vsock/vmw_vsock_vmci_transport.ko ;
do
if [[ -f "${mod}" ]] ; then
modprobe -v $(basename "${mod}" .ko)
eend $?
break
fi
done

# vmci or vsock were already loaded by the previous modprobe,
# no need to do it here
modprobe -av vmmon vmnet
/usr/bin/vmware-networks --start
}

stop() {
#start-stop-daemon --stop --exec @@BINDIR@@/vmware-usbarbitrator
killall --wait /usr/bin/vmware-usbarbitrator
eend $?
/usr/bin/vmware-networks --stop
eend $?
ebegin Stopping VMware services
modprobe -rv vmmon vmnet

# vsock might be:
# 1) built as external kernel module
# 2) built as internal kernel module (with name vmw_vsock_vmci_transport)
# 3) embedded in the kernel
for mod in /lib/modules/$(uname -r)/misc/vsock.ko \
/lib/modules/$(uname -r)/kernel/net/vmw_vsock/vmw_vsock_vmci_transport.ko ;
do
if [[ -f "${mod}" ]] ; then
modprobe -rv $(basename "${mod}" .ko)
eend $?
break
fi
done

# vmci might be:
# 1) built as external kernel module
# 2) built as internal kernel module (with name vmw_vmci)
# 3) embedded in the kernel
for mod in /lib/modules/$(uname -r)/misc/vmci.ko \
/lib/modules/$(uname -r)/kernel/drivers/misc/vmw_vmci/vmw_vmci.ko ;
do
if [[ -f "${mod}" ]] ; then
modprobe -rv $(basename "${mod}" .ko)
eend $?
break
fi
done
}


 

Re: Starting Vmware Workstation Modules at Boot

Reply #4
@nous Thank you so much for your help.  I had downloaded workstation player from VMware (source of the vmware file).  TPM passthrough is not yet available on Virtualbox, so I needed something with a workaround for a virtual Windows 11 machine.  I just uninstalled Workstation and used the AUR's vmware-workstation-openrc, which is not free, but was easy to locate a key for.

I should have just consulted the AUR in the first place, although I have learned more about Open-RC just from these  steps.  Again, I appreciate all of your/the community's help.  I hope this will help other users as well.