Execute command before Kodi

So, I have an Odroid C4 with the Hardkernel Wifi module 5B.
This is the one wifi dongle that by default, acts as a USB drive containing the Windows driver.
To switch it to NIC mode and work properly in CE, the following command needs to be issued (after installing the “System Tools” addon:

usb_modeswitch -KW -v 0bda -p 1a2b

For convinience, I included this command in the autostart.sh, which works fine, except for the fact that autostart.sh runs pretty late into the boot process, namely, after Kodi has started.
This is a problem because I use a MySQL database on my NAS for my CEs. Kodi tries to read the database before the Wifi connection can be established, so if the CE is powered off, at next boot I need to do a soft reboot of Kodi, because then the Wifi dongle stays on.

I tried writing a systemd service, but it didn’t work:


ExecStart=usb_modeswitch -KW -v 0bda -p 1a2b

Is there a way to run the above command before Kodi starts waiting for network connection?

autostart.sh is run BEFORE Kodi is started - here is the systemd file CoreELEC/kodi-autostart.service at coreelec-20 · CoreELEC/CoreELEC · GitHub

I think your issue is that usb_modeswitch is called but it takes some time to get network connection. Some hardcoded sleep after usb_modeswitch would probably help.

And in systemd file you need to use full path like


Well sh**, I thought CE would wait for the autostart.sh to exit before running others.

I added a

sleep 90s

at the end of the script, and now it works like a charm.

Thank you!

1 Like

It does wait. But as usb_modeswitch is finished the script ends and Kodi starts.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.