# Installing a driver on balenaOS

**URL:** <https://forums.balena.io/t/installing-a-driver-on-balenaos/350160>\
**Category:** Product support\
**Tags:** raspberrypi4\
**Created:** [November 17, 2021, 10:13pm UTC](https://forums.balena.io/t/installing-a-driver-on-balenaos/350160 "2021-11-17T22:13:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![n42](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/n42/32/5009_2.png) [@n42](https://forums.balena.io/u/n42)\
**Post date:** [November 17, 2021, 10:13pm UTC](https://forums.balena.io/t/installing-a-driver-on-balenaos/350160/1 "2021-11-17T22:13:55Z")

</div>

Hi,

We need to replace the rtl8188eu driver due to a problem with the original driver supplied with balena (it does not allow setting regdomain/country).

We already compiled and tested the replacement driver.

What would be the best way to ‘install’ the new driver?  
On a newly created image?  
On an existing image (already at customer site)?  
Is there a way to ensure the driver will be maintained if/when we do an OS upgrade? (I assume it will be kept with regular app/container upgrades)

Thank you 😉

---

<div class="post-metadata">

**Author:** ![n42](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/n42/32/5009_2.png) [@n42](https://forums.balena.io/u/n42)\
**Post date:** [November 22, 2021, 7:54pm UTC](https://forums.balena.io/t/installing-a-driver-on-balenaos/350160/2 "2021-11-22T19:54:44Z")

</div>

I would appreciate any help on this. Thank you.

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [November 23, 2021, 8:18am UTC](https://forums.balena.io/t/installing-a-driver-on-balenaos/350160/3 "2021-11-23T08:18:13Z")

</div>

Hi,

I haven’t tried it yet myself, but there is [this post](https://forums.balena.io/t/custom-kernel-modules-firmware-best-practices/166994/6) from a while back that suggests adding it from your own container.

I would expect your fix would look something like:

1. Add module (ex. `/usr/src/rtl8188eu.ko`) and labels to your container;
2. On start up:  
2.a. Unload the old driver: `modprobe --remove rtl8188eu`;  
2.b. Load the new driver: `insmod /usr/src/rtl8188eu.ko`;
3. Enjoy your wifi.

If this works, you can roll it out to the existing devices simply by updating them normally.  
Of course, this assumes you have some connection other than your broken wifi.

I’m not sure how this would work with HostOS updates, you might need specific builds of your module for the different versions.

If you’re building your own OS image, you might be able to patch it with a `.bbappend` file, but updating custom OS images isn’t really supported at the moment I think.

---

<div class="post-metadata">

**Author:** ![n42](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/n42/32/5009_2.png) [@n42](https://forums.balena.io/u/n42)\
**Post date:** [December 15, 2021, 6:00pm UTC](https://forums.balena.io/t/installing-a-driver-on-balenaos/350160/5 "2021-12-15T18:00:55Z")

</div>

Hi TJvV,

I assume the change needs to be on Host OS and cannot be made inside a container.

Also, what would be your recommendation as to how to automatically replace driver on startup? use /etc/init.d script? something else?

Thank you 😉

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [December 16, 2021, 8:18am UTC](https://forums.balena.io/t/installing-a-driver-on-balenaos/350160/6 "2021-12-16T08:18:39Z")

</div>

Hi @n42,

The post I linked in my previous answer suggests it can be done from container.

I would run the driver update in your `CMD` script.  
For example if your `Dockerfile` is something like

```auto
FROM balenalib/raspberrypi3

RUN mkdir -p /usr/src
COPY rtl8188eu.ko /usr/src
COPY run.sh /usr/src
COPY actual_script.sh /usr/src

CMD ["/bin/bash", "/usr/src/run.sh"]

```

Then `run.sh` would look something like:

```auto
#!/bin/sh
modprobe --remove rtl8188eu
insmod /usr/src/rtl8188eu.ko

/usr/src/actual_script.sh

```

Where `actual_script.sh` is whatever you would normally run in the container.

I’m quite busy at the moment, but might have some time to test things over the weekend.
