System fails to start custom service and load custom module

Hello all,
I need start program after system booted as root user.
Don’t understand why i am getting error and how to resolve it.
Here is the steps that i followed:

Created service file in /etc/systemd/system/muxponder.serivice as root.
In side file i have :

[Unit]
Description=MuxPonder

[Service]
Type=simple
User=root
ExecStart=/etc/systemd/system/hello.exe

[Install]
WantedBy=multi-user.target

I placed simple hello world programm:

[root@fedora system]# file /etc/systemd/system/hello.exe
/etc/systemd/system/hello.exe: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=6d20c1dae246141d2c174808094619dc5bd6cb0f, for GNU/Linux 3.2.0, not stripped

I follow following commands:
systemctl enable my.service

After boot status for this service:

[root@fedora system]# systemctl status muxponder.service
× muxponder.service - MuxPonder
     Loaded: loaded (/etc/systemd/system/muxponder.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf
     Active: failed (Result: exit-code) since Sat 2024-04-13 14:34:20 PDT; 59s ago
   Duration: 89ms
    Process: 750 ExecStart=/etc/systemd/system/hello.exe (code=exited, status=203/EXEC)
   Main PID: 750 (code=exited, status=203/EXEC)
        CPU: 1ms

Apr 13 14:34:20 fedora systemd[1]: Started muxponder.service - MuxPonder.
Apr 13 14:34:20 fedora (ello.exe)[750]: muxponder.service: Failed to locate executable /etc/systemd/system/hello.exe: Permission denied
Apr 13 14:34:20 fedora (ello.exe)[750]: muxponder.service: Failed at step EXEC spawning /etc/systemd/system/hello.exe: Permission denied
Apr 13 14:34:20 fedora systemd[1]: muxponder.service: Main process exited, code=exited, status=203/EXEC
Apr 13 14:34:20 fedora systemd[1]: muxponder.service: Failed with result 'exit-code'.
[root@fedora system]#

Use FHS compliant locations to avoid SELinux related issues:

sudo mv -f /etc/systemd/system/hello.exe /usr/local/bin/hello.exe
sudo chmod +x /usr/local/bin/hello.exe
sudo restorecon -F -R /usr/local/bin/hello.exe
sudo SYSTEMD_EDITOR="sed -i -e s:/etc/systemd/system/:/usr/local/bin/:" \
    systemctl edit --full muxponder.service
1 Like

Hello Vladislav.
Большое спасибо it works.
Albert.

Hi Vladislav,
Let me ask your help again.
Actually i am trying install kernel driver using this flow.
I create executable file in /usr/local/bin/SeaLight.cmd with following context:


#!/bin/sh
echo "Start"
new_cmd='/usr/local/bin/gendrv.ko devices=1 base=00000000 irq=-1 description=digi0:pci?(1.0.0.0)+0:7ffffff:32:2 shared_mem_start=0x040000000'
echo "DBG 1:>${new_cmd}<"
/sbin/insmod ${new_cmd} || exit 1
/usr/bin/mknod /dev/digi0.S c 235 0
echo "Done"

I also placed our driver gendrv.ko in side same directory, and run restorecon on it.
When i executing this command all works, but after boot status that i am getting is bellow, looks like /sbin/insmod can’t access /usr/local/bin/gendrv.ko.
Can you suggest how solve this?
Thanks in advance.


[root@fedora system]# systemctl status muxponder.service
× muxponder.service - Muxponder
     Loaded: loaded (/etc/systemd/system/muxponder.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf
     Active: failed (Result: exit-code) since Mon 2024-04-15 20:18:20 PDT; 37s ago
   Duration: 71ms
    Process: 748 ExecStart=/usr/local/bin/SeaLight.cmd (code=exited, status=1/FAILURE)
   Main PID: 748 (code=exited, status=1/FAILURE)
        CPU: 6ms

Apr 15 20:18:20 fedora systemd[1]: Started muxponder.service - Muxponder.
Apr 15 20:18:20 fedora SeaLight.cmd[748]: Start
Apr 15 20:18:20 fedora SeaLight.cmd[748]: DBG 1:>/usr/local/bin/gendrv.ko devices=1 base=00000000 irq=-1 description=digi0:pci?(1.0.0.0)+0:7ffffff:32:2 shared_mem_start=0x040000>
Apr 15 20:18:20 fedora SeaLight.cmd[750]: insmod: ERROR: could not insert module /usr/local/bin/gendrv.ko: Permission denied
Apr 15 20:18:20 fedora systemd[1]: muxponder.service: Main process exited, code=exited, status=1/FAILURE
Apr 15 20:18:20 fedora systemd[1]: muxponder.service: Failed with result 'exit-code'.

The correct method for loading custom modules typically involves DKMS to automate building and signing procedure for the current kernel.

Loading kernel modules and creating character files is recommended to perform like this:

sudo tee /etc/modprobe.d/muxponder.conf << EOF > /dev/null
options gendrv \
devices=1 \
base=00000000 \
irq=-1 \
description=digi0:pci?(1.0.0.0)+0:7ffffff:32:2 \
shared_mem_start=0x040000000
EOF
sudo tee /etc/modules-load.d/muxponder.conf << EOF > /dev/null
gendrv
EOF
sudo tee /etc/tmpfiles.d/muxponder.conf << EOF > /dev/null
c /dev/digi0.S - - - - 235:0
EOF
sudo systemctl restart systemd-modules-load.service
sudo systemctl restart systemd-tmpfiles-setup-dev.service

We can provide more specific instructions if you post a link to the driver source code.

Hi Vladislav,
Looks like i can’t share the code as it’s a 3 party code.
Let me look into DKMS mentioned by you.
Thanks,

Here’s an example of using DKMS to build, sign, and load modules:
How to update drivers of a USB WiFi dongle - #6 by vgaetera

1 Like

Thanks for example.
You mention that it requires updating the kernel to the latest, but in our case we can’t compile the driver with the latest release of the kernel, and we have to stay with the 6.5.6 (I need to confirm this) release.
Does this still work?
I still hope to find a way at boot time to load the driver by running a script from systemd as I can do from terminal.
Thanks,

Hello Vladislav, let me ask you why this way it’s not working.
Hope you can help.
Thanks again.

I am trying install kernel driver at boot time using systemd-modules-load.
I create configuration file:
/etc/modules-load.d/gendrv.conf

In side file i tried all different ways to load drver with parameters and with out as following

gendrv devices=1 base=00000000 irq=-1 description=digi0:pci?(1.0.0.0)+0:7ffffff:32:2 shared_mem_start=0x04000000
gendrv.ko devices=1 base=00000000 irq=-1 description=digi0:pci?(1.0.0.0)+0:7ffffff:32:2 shared_mem_start=0x04000000
gendrv
gendrv.ko

I placed driver in
/lib/modules/6.5.6-300.fc39.x86_64/gendrv.ko

For all of them after boot status shows:

Apr 18 22:57:44 fedora systemd-modules-load[558]: Failed to find module 'gendrv devices=1 base=00000000 irq=-1 description=digi0:pci?(1.0.0.0)+0:7ffffff:32:2 shared_mem_start=0x0400>
Apr 18 22:57:44 fedora systemd-modules-load[558]: Failed to find module 'gendrv.ko devices=1 base=00000000 irq=-1 description=digi0:pci?(1.0.0.0)+0:7ffffff:32:2 shared_mem_start=0x0>
Apr 18 22:57:44 fedora systemd-modules-load[558]: Failed to find module 'gendrv'
Apr 18 22:57:44 fedora systemd-modules-load[558]: Failed to find module 'gendrv.ko'

What i am doing wrong?
Thanks,

sudo restorecon -F -R /usr/lib/modules
sudo depmod -a

Have you tried loading that module with sudo modprobe gendrv to see if it will even load?
If not then make sure it can be loaded manually before you attempt to create a file in /etc/modprobe.d to automatically load it.

Once you can load it and test it with manually loading it and are sure it works then add the entries to the file in /etc/modprobe.d.

You would also likely need to load the module, make the entry in /etc/modprobe.d, then also generate a new initramfs image with that module included to be sure it would load at boot time.

Thanks Jeff,
I can load this module using insmod and it works. This is so far what we are doing.
Can you please elaborate on how to generate a new initramfs image.
Also when I load with insmod we are passing arguments as you saw.
Can you comment if I have correctly created the gendrv.conf file and placed gendrv.ko in the correct place.
Thanks a lot.

The information in the gendrv.conf file probably should look much like the command line used with insmod, though I am not certain about differences between using modprobe and insmod. Check the man pages for more details. I suspect that testing with modprobe should be used to confirm the command line structure since modprobe is used during boot with the content of /etc/modprobe.d/. According to the man page modprobe has many more options than insmod.

The man page for modprobe.d shows several ways to use the .conf file. I see this as an example.

       options modulename option...
           This command allows you to add options to the module modulename (which might be an alias) every time it is inserted into the kernel: whether directly (using modprobe
           modulename) or because the module being inserted depends on this module.

The initramfs image is created or replaced with the dracut command.
sudo dracut --force in its normal form but according to the man page that can also identify a specific kernel for which the image is to be created.

Thanks Vladislav.
Just to confirm, I placed gendrv.ko in the correct location and which line in gendrv.conf should I use?

And all arguments following in the same line?
Thanks,

Looks to me that it should be
options gendrv options... all on one line if I am reading the docs properly
Or you may break the line by ending each line to be continued with a \ at the end – so multiple lines are read as a single line by modprobe).
This would result in

options gendrv option option \
option option

which would then appear as one line to modprobe (man modprobe.d shows this)

To be clear, you need 3 different configs as explained above.

2 Likes

Hi Jeff again.

I am having a problem again loading the same module at boot time on new builded fedora system.

I was able to load module manually:
/sbin/insmod gendrv.ko

I checked all application works after I loaded.
I created the file gendrv.conf in /etc/modules-load.d directory with the line gendrv.
I cp gendrv.ko in to
/usr/lib/modules/6.5.6-300.fc39.x86_64/gendrv.ko

After boot systemd-modules-load.service gives me following error:

Sep 26 17:00:03 vedge systemd-modules-load[558]: Failed to find module 'gendrv'

Not sure how to fix this.
Hope you can help me one more time.
Thank you.

Repeat the steps listed above.
If the issue persists, check the output:

ls -l -Z /usr/lib/modules/$(uname -r)/*.ko

Thanks again for your help.
Yes this was a problem.
I don’t remember that i did this last time, and i don’t have this in my record.
Will look into it to get more clearance.
Albert,