Mount USB HDD - Balena OS

Hi everyone,

I’m literaly going mad as I can’t find the way to edit docker-compose.yml to insert
specific parameters I’ve found in forum regarding USB mount!

In my case, I have a container where Deluge is running and I connected a USB HDD but I don’t know
how to mount it into Balena OS… please help!

Thank you very much


Can you clarify on why can’t you edit the docker-compose.yml?
To add the external media, do check

Good morning,

Where do I have to insert those commands?

I have access through Balena Cloud CLI and Balena SSH, but I really don’t know actually how to proceed.


You’ll need to edit the dockerfile of the deluge container. once edited, you can push them via balena cli.

Ok, so if I understood correctly this are the steps:

  • locally edit dockerfile of deluge
    (I’m using Balena CLI in Windows environment)
  • push back the updated project through
    Balena CLI

Is this correct?


Yes the steps you mentioned are correct but needs some modification.
You’ll need to create a scripts file, which mounts the usb drive

mount -t <fstype> -o rw <device-name> <mount-point>
mount -t <fstype> -o rw -L <device-label> <mount-point>
mount -t <fstype> -o rw -U <device-uuid> <mount-point>

next you need to create a udev.rules file which will run when the container loads

ACTION=="add", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", RUN+="/bin/sh -c '/usr/src/scripts/'"
ACTION=="remove", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", RUN+="/bin/sh -c '/usr/src/scripts/'"

and then update the containers dockerfile to load the above created files

COPY usb.rules /etc/udev/rules.d/usb.rules
COPY scripts /usr/src/scripts

the above steps can be seen in detail here on os docs
To check a working project here

Fine, I will try. Is there somevideo tutorial to help tu understand better all steps?

I just tried to run the command cat /proc/filesystems but I did not find ntfs filesystemtype.

Can I use my external usb hdd in ntfs format?

Thanks in advance

Best regards

Hello, unfortunately there is no video resource on this, but let us know if anything is unclear and we should be able to improve it or provide support. As far as NTFS goes, I am afraid we do not support it at the moment, can you try reformatting the USB into some other filesystem (e.g. ext4)

Oh I see. I tried to read all docs you have sent me but being new to Balena OS (or Resin OS as well)

I need to follow concrete “steps” to learn from as there are many explanations which are difficult to

put them in practice.

In the meanwhile I can easily format in ext4 xD

I look forward in receiving further help for this project as I think it is a great way of trying to learn more about.

Thank you very much

No worries, it can be quite a bit overwhelming in the beginning, but its actually quite simple. This page has all the steps, but let me try and explain them in a way that is hopefully more clear.

So the first two sections (balenaOS kernel support and Preparing the container) ensure that everything is correctly setup for you to be able to mount your USB correctly. You have already made it past the first step by reformatting the USB stick, the next step would be to modify your local docker-compose.yml and Dockerfile as described in Preparing the container and then balena push your changes to your application.

Once this is setup you will be able to mount the USB stick in your container. You can run something like mount -t <fstype> -o rw -L <device-label> <mount-point> where fstype will be ext4, mount-point should be a folder you create for the stick and device-label is the label of you USB stick (you can find that out by running lsblk -f from the hostOS). Once you are done with the USB stick you can unmount it by simply running umount <mount-point>.

This should be all you need to get going. The issue with this method is that you have to manually mount and unmount the USB stick every time you plug it in and out. The idea described in the section called Automounting/unmounting with UDev rules is to setup the hostOS to automatically run your mount and unmount commands every time something is plugged or unplugged from the USB port. Let me know if you need any more help with that, the idea is to simply create these udev rules (contained in the usb.rules) that run some mount and unmount scripts (which should contain the commands you ran manually in the previous step) every time a device is connected/disconnected.

I tried but I can’t find docker-compose.yml in this project. Do I have to create It? Am I missing something? Where to find?

(Attachment is missing)

If you don’t have a docker-compose.yml in your project you can just create one with a single service (your Dockerfile). See here for the docs on that.

Oh I see. Well, actually I have a container(?) where a project named wifi-repeater-master is running.

Which are the first steps to do? I mean, I just have to simply create/add a new container for docker-deluge-master right?

Could you please guide me?

So you already have a wifi-repeater-master service (no docker-compose.yml, just a Dockerfile) and you want to add another container (docker-deluge-master) also without a docker-compose.yml. You want them both to run on your devices, correct?

Well, I just checked and I’ve found a docker-compose.yml in wifi-repeater-master service.

So at the end I need (and would like) to have multiple service, in this case:

  • wifi-repeater-master
  • docker-deluge-master (with external usb hdd mounted)

We have a blog post covering this case where you want to merge multiple projects into a single release: It’s an interesting read, but your case should be solvable by:

  • Put the docker-deluge-master directory and the wifi-repeater-master into the same folder with nothing else.
  • Remove wifi-repeater-master/docker-compose.yml
  • Add the following docker-compose.yml to the same directory as docker-deluge-master and wifi-repeater-master (I’m assuming the wifi repeater code is from here):
version: "2.1"

    build: ./wifi-repeater-master
    privileged: true
      io.balena.features.dbus: '1'
    build: ./docker-deluge-master
    privileged: true
  • Add the following at the end of docker-deluge-master/Dockerfile:

You should now be ok to follow the rest of

Great! I think I’m making it.

Where to create mountpoint of external usb hdd?

Anywhere you want. It’ll only be visible inside the container, so you don’t have to worry about it clashing with other services.

Great! For the configuration of automount? What do I have to set and how?

The document that @nazrhom linked to - our communicate outside the container docs covers this. There’s also the balena-storage project which demonstrates how it works.