DKMS, systemd & Virtual Box - How to get Dynamic Kernel Module Support to work in openSUSE 12.2/12.3

I was trying to get **Dynamic Kernel Module Support **(DKMS) in openSUSE 12.1 to automatically run, reinstalling kernel modules each time you change the Linux kernel and could not get it to work properly. I have found out that in openSUSE 12.1 & 12.2 & 12.3, some startup scripts do not operate due to the usage of systemd. systemd really speeds up system startup by running the many startup processes in parallel and avoids the usage of shell scripts altogether. That is is good for speed, but not good if you are in need of running something in openSUSE as root when the system is restarted. You need to consider using this procedure if the following are true:

  1. You have installed openSUSE 12.1 or higher and use systemd, the default.
  2. You have installed VirtualBox, any present version.
  3. You have (or want to) installed DKMS to auto update the VirtualBox kernel Modules.
  4. DKMS does not seem to be working for you when you reboot your PC after loading a new kernel.

DKMS should work with VirtualBox. reinstalling its kernel modules each time you update your kernel version and this works well in openSUSE 11.4. DKMS can be setup to work with other programs that also need to compile a kernel module against the present running kernel. You can install DKMS from YaST if you have added in the Packman repository. The problem with using DKMS in openSUSE 12.1, is that after it has been installed, the dkms_autoinstaller service is not being run at startup, apparently due to the usage of systemd. The dkms_autoinstaller bash script normally resides in the /etc/init.d folder and from the YaST / System / Run Level services, symbolic links are created in rcx folders, that represent the different run levels you want the service to use. However, DKMS was just not working, at least for me, so I have come up with a new plan of attack to get DKMS running properly in openSUSE 12.1 and the basics are as follows:

  1. I Disabled the /etc/init.d/dkms_autoinstaller in the system runlevel control (removes all symbolic links)
  2. Moved the dkms_autoinstaller bash script file to the /usr/sbin folder where the dkms binary file is located.
  3. Created a systemd service file called run_dkms.service in the folder /usr/lib/systemd/system/
  4. Ran the command systemctl enable /usr/lib/systemd/system/run_dkms.service (which puts a symbolic link in /etc/systemd/system/multi-user.target.wants/ to the real service file)

So, if it sounds like you need to get DKMS working because it is installed and you are using VirtualBox, then continue reading on…

  1. First, we need to disable the dkms_autoinstaller runlevel service. Open up terminal and run the following command:
**sudo /sbin/chkconfig -d dkms_autoinstaller**
  1. Second, we need to move the dkms_autoinstaller script to its new location were the dkms binary file gets installed:
**sudo mv /etc/init.d/dkms_autoinstaller /usr/sbin/dkms_autoinstaller**
  1. Third we need to create the text file run_dkms.service (shown below) in the folder /usr/lib/systemd/system/ as root:
 In KDE Alt-F2: **kdesu kwrite /usr/lib/systemd/system/run_dkms.service**

OR

 In GNOME Alt-F2: **gnomesu gedit /usr/lib/systemd/system/run_dkms.service**

This is what you put into this file and save it:


#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.

[Unit]
Description=Update kernel modules
DefaultDependencies=no
After=local-fs.target
Conflicts=shutdown.target
Before=basic.target shutdown.target

[Service]
ExecStartPre=/usr/local/bin/userfix
ExecStart=/usr/sbin/dkms_autoinstaller start
Type=oneshot
TimeoutSec=0
StandardInput=tty

[Install]
WantedBy=multi-user.target


  1. Forth, we need to add the run_dkms.service to systemd. Open up a terminal session and run the following command:
**sudo systemctl enable /usr/lib/systemd/system/run_dkms.service**
  1. Fifth, I have written the run_dkms.service file to look for and run a second bash script first, before the dkms_autoinstaller gets ran. I called this script userfix and placed it in the folder /usr/local/bin. To create this file, do the following:
 In KDE Alt-F2: **kdesu kwrite /usr/local/bin/userfix**

OR

 In GNOME Alt-F2: **gnomesu gedit /usr/local/bin/userfix**

This is what you put into this file and save it:


#!/bin/bash

#: Title       : /usr/local/bin/userfix
#: Date Created: 2-22-12
#: Last Edit   : 2-22-12
#: Author      : James D. McDaniel
#: Version     : 1.00
#: Description : Run User Pre-dkms Compile Commands
#: Options     : None

echo
echo "User Fix File was Executed ..." 
echo

# Place your user code here, to be run before dkms is run

exit 0

# End Of Script

  1. You need to make the /usr/local/bin/userfix bash script executable. Open up terminal and run the following command:
**sudo chmod +x /usr/local/bin/userfix**

The text editor commands shown here assume you are using either KDE, which is the default in openSUSE, or the GNOME desktop. The rest are assumed to be run in a terminal session. The sudo command is required to edit or create text files owned by root. You may not need to enter the root password every time depending on how quickly you proceed. Please let me know if you have any questions about using this procedure.

I Have incorporated my run_dkms & userfix scripts into the SASI (SuSE Automated Script Installer) which will automatically install the run_dkms & userfix scripts for you. Just copy and paste the following command into a terminal session:

wget -nc http://paste.opensuse.org/view/download/71295014 -O ~/bin/make-dkms-installer ; chmod +x ~/bin/make-dkms-installer ; make-dkms-installer

You can run the make-dkms-installer once and you will need to enter the root user password once as well. All steps listed above will be performed for you.

So who might want to install DKMS in openSUSE 12.1 and why? Again, DKMS is used to reinstall kernel modules, that must be compiled against the present running kernel. VirtualBox is one such example. Without DKMS or other such means, if you upgrade or replace your working kernel, VirtualBox will stop running until you run the command: sudo /etc/init.d/vboxdrv setup, but this step is not required if you have installed DKMS and of course my DKMS fix here.

This documentation and the make-dkms-installer bash script has been updated to place the run_dkms.service in the folder location of /usr/lib/systemd/system/ to keep in line with how service files are placed in openSUSE 12.3 but it still works in its old location, for now.

For more help with systemd, have a look here: SysdCmd - systemd Command Help/Config Editor - Blogs - openSUSE Forums

Please let me know if you have any questions or problems.

Thank You,

My procedure to get DKMS working with systemd and openSUSE 12.1 for use with VirtualBox has been updated. If you have this combination, you need to read my blog on the subject Now!

Thank You,

These are the comments of please_try_again, posted on his behalf…

I’m still not using DKMS on openSUSE. I might when I get some time … I know, I said that couple months ago already. But for now modautocompile is still working fine for me.

Here’s some info from Fedora, where dkms is installed by default. However it seems to be one of the rare services that isn’t systemd native on Fedora 16. It is installed as a sysvinit service and get started “transparently”, since systemctl automatically calls chkconfig when dealing with sysv init files. Maybe that’s what doesn’t work as expected under openSUSE (?) and therefore you needed to write a systemd service (which looks like a better solution IMO).

# systemctl -t service | grep dkms
dkms_autoinstaller.service loaded active exited LSB: Automatically install DKMS modules for new kernels

# systemctl status dkms_autoinstaller.service
dkms_autoinstaller.service - LSB: Automatically install DKMS modules for new kernels
Loaded: loaded (/etc/rc.d/init.d/dkms_autoinstaller)
Active: active (exited) since Fri, 24 Feb 2012 07:29:39 -0800
Process: 1227 ExecStart=/etc/rc.d/init.d/dkms_autoinstaller start (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/dkms_autoinstaller.service

**# dkms status **
vboxhost, 4.1.8, 3.2.6-3.fc16.x86_64, x86_64: installed
vboxhost, 4.1.8, 3.2.7-1.fc16.x86_64, x86_64: installed

# yum info dkms
Loaded plugins: langpacks, presto, refresh-packagekit, security
Installed Packages
Name : dkms
Arch : noarch
Version : 2.2.0.3
Release : 1.fc16
Size : 210 k
Repo : installed
From repo : updates
Summary : Dynamic Kernel Module Support Framework
URL : Redirecting to GitHub
License : GPLv2+
Description : This package contains the framework for the Dynamic
: Kernel Module Support (DKMS) method for installing
: module RPMS as originally developed by Dell.

  • yum is a Fedora specific command (equivalent zypper)

# rpm -ql dkms
/etc/bash_completion.d/dkms
/etc/dkms
/etc/dkms/framework.conf
/etc/dkms/template-dkms-mkrpm.spec
/etc/dkms/template-dkms-redhat-kmod.spec
/etc/kernel/postinst.d/dkms
/etc/kernel/prerm.d/dkms
/etc/rc.d/init.d/dkms_autoinstaller
/usr/lib/dkms
/usr/lib/dkms/common.postinst
/usr/lib/dkms/dkms_autoinstaller
/usr/lib/dkms/find-provides
/usr/lib/dkms/lsb_release
/usr/lib/dkms/mkkerneldoth
/usr/sbin/dkms
/usr/share/doc/dkms-2.2.0.3
/usr/share/doc/dkms-2.2.0.3/AUTHORS
/usr/share/doc/dkms-2.2.0.3/COPYING
/usr/share/doc/dkms-2.2.0.3/README.dkms
/usr/share/doc/dkms-2.2.0.3/sample-suse-10-mkkmp.spec
/usr/share/doc/dkms-2.2.0.3/sample-suse-9-mkkmp.spec
/usr/share/doc/dkms-2.2.0.3/sample.conf
/usr/share/doc/dkms-2.2.0.3/sample.spec
/usr/share/man/man8/dkms.8.gz
/var/lib/dkms
/var/lib/dkms/dkms_dbversion

On initial install, the system V service is enabled:

# rpm -q --scripts dkms
postinstall scriptlet (using /bin/sh):
-e /sbin/dkms ] && mv -f /sbin/dkms /sbin/dkms.old 2>/dev/null

enable on initial install

$1 -lt 2 ] && /sbin/chkconfig dkms_autoinstaller on ||:
preuninstall scriptlet (using /bin/sh):

remove on uninstall

$1 -lt 1 ] && /sbin/chkconfig dkms_autoinstaller off ||:

# chkconfig --list dkms_autoinstaller

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

dkms_autoinstaller 0:off 1:off 2:on 3:on 4:on 5:on 6:off

The making dkms work with systemd documentation and the make-dkms-installer bash script have been updated to place the run_dkms.service in the folder location of /usr/lib/systemd/system/ to keep in line with how service files are placed in openSUSE 12.3.

For more help with systemd, have a look here: SysdCmd - systemd Command Help/Config Editor - Blogs - openSUSE Forums

Thank You,

I have virtualbox and came across this page searching for way to update the kernel with virtualbox installed.

It does allow DKMS to work in openSUSE 12.3 using systemd and where the “dkms” package is installed from Packman and you then run my bash script posted here. Then you need to run the VirtualBox setup command to place VirtualBox into dkms. It gets installed for you into dkms when found. From then on, if VirtualBox supports the new kernel version you just loaded, VirtualBox will be automatically recompiled for you after a short delay on openSUSE restart.

Thank You,

[QUOTE=jdmcdaniel3;bt901]It does allow DKMS to work in openSUSE 12.3 using systemd and where the “dkms” package is installed from Packman and you then run my bash script posted here. Then you need to run the VirtualBox setup command to place VirtualBox into dkms. It gets installed for you into dkms when found. From then on, if VirtualBox supports the new kernel version you just loaded, VirtualBox will be automatically recompiled for you after a short delay on openSUSE restart.

Thank You,[/QUOTE]

Worked as advertised. Thanks!