Mounting USB on RPi4

Hi,

I’m trying to set up a USB to mount on my device. I’m following the instructions here and am using this as my mount file:

[Unit]
Description = External USB Stick Storage

[Mount]
What = LABEL=MSATDATA
Where = /mnt/storage
Type = fat32
Options = rw

[Install]
WantedBy = multi-user.target

My git directory looks like this:

.git
.versionbot
node-red
        app
               assets
               flows
               package.json
               settings.js
               start.sh
        dockerfile.template
        mnt-storage.mount
pigpiod
        dockerfile.template
        start.sh
dockercomose.yml

I’m looking to get my node-red application to write to the USB drive as a sort of data logging of sensor data.

Currently, if I use the command systemctl is-active mnt-storage.mount from within my node-red container I get this return:

I don’t know why it is not working for you (I haven’t used that approach).

In following repository I have manually mounted a USB stick in the influxdb service:

So the important changes are:

  1. Add a line like the following in your dockerfile.template:
# So the instruction below refers to a connected USB drive with label "influxdb" which should be in "ext4" format.
RUN echo "LABEL=influxdb /mnt/influxdb ext4 rw,relatime,discard,data=ordered 0 2"  >> /etc/fstab
  1. In your start script or entrypoint script you must put something like (in my case it has been put in file my_entrypoint.sh)
# JVA 2018-11-15 I have added following instructions to mount usbdrive and create subfolder influxdb
mkdir -p /mnt/influxdb
mount /mnt/influxdb

@gregorr1 It looks like you’re using the “Using systemd” method while not running systemd. You need to either:

Hi @zvin, I thought that systemd was the standard init system for the debian base images? Do I need to activate it to have it run?

Hello @gregorr1 we do not include systemd by default as it leads to a lot of issues. Have a look at https://www.balena.io/docs/reference/base-images/base-images/#installing-your-own-initsystem for instructions on how to activate it

@nazrhom Thanks for the reply - I notice that it suggests not to use an init system when using multi-containers so I’ll try doing it without an init system.

Thanks for sharing this.

If balena images by default are not starting any init system, then I would make this clear in the balena documentation that you have to activate the init system (with link to how this can be done).

If you have lots of issues with systemd will this also not mean that the other people might encounter those issues when activating systemd for mounting USB ? In that case, isn’t it better to remove this option from the documentation to prevent people going down that hole ?

@GregorR1 , FYI: the example I gave above corresponds to the balena instructions “Without the init system” you have found on page : https://www.balena.io/docs/learn/develop/runtime/#mounting-external-storage-media

Thanks for the response. I’ve set this up but I can’t seem to find the /mnt/storage in the terminal - how would I check that it has all mounted correctly?

Looking in my device logs I just noticed this line:

mount: /mnt/storage: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error

I then changed it from vfat to fat32 as that’s what my usb properties said and I got this error:

mount: /mnt/storage: unknown filesystem type ‘fat32’

My whole RUN line is:
RUN echo “LABEL=MSATDATA /mnt/storage fat32 rw,data=ordered” >> /etc/fstab

I took out the other options as they were for an ext4 device and I wasn’t sure if I needed them.

Any ideas what I need to change/add? I’ve never manually mounted a usb before - I’ve always been able to do it through the GUI on the Pi.

Hey @janvda thanks for the suggestions, our images did use systemd for some time and there are still some parts of the documentation that could be improved to reflect this is the default now. For example, https://www.balena.io/docs/learn/develop/runtime/#mounting-external-storage-media should make it more clear that, unless you manually activated the init system, you should really be looking at the “Without the init system”. I created an issue on the docs about this.

1 Like

once I removed the “data=ordered” it appears to be working now. Thanks for your help!

@gregorr1 I am glad to hear that :slight_smile: