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:
- You have installed openSUSE 12.1 or higher and use systemd, the default.
- You have installed VirtualBox, any present version.
- You have (or want to) installed DKMS to auto update the VirtualBox kernel Modules.
- 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:
- I Disabled the /etc/init.d/dkms_autoinstaller in the system runlevel control (removes all symbolic links)
- Moved the dkms_autoinstaller bash script file to the /usr/sbin folder where the dkms binary file is located.
- Created a systemd service file called run_dkms.service in the folder /usr/lib/systemd/system/
- 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…
- First, we need to disable the dkms_autoinstaller runlevel service. Open up terminal and run the following command:
**sudo /sbin/chkconfig -d dkms_autoinstaller**
- 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**
- 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
- 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**
- 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
- 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,