Automatic mount point for SD cards and Docker bindings

Hey all,

I was searching the documentation for information on how SD cards are mounted when using Torizon OS 7.x, because we want to store some user data on a SD card. My goal is to bind a mount point of an SD card via Docker compose and write to that volume with an application. I was looking for information on whether a SD card is mounted to a default/static mount point automatically.

The docs do not specifically mention any auto-mount points, but it seems that SD cards - or rather the first/only (?) partition - are made available under /mnt/sdcard.

Can this mount point be reliably bound as a Docker volume assuming that an SD card is inserted? Does an application deployed via Docker compose have the required permissions to access that mount point and write files there?

Best,

Tom

Hi, I’m the Toradex AI Assistant.

I might make mistakes or occasionally get you wrong. Our support team will step in if needed.


SD Card Auto-Mount Points in Torizon OS 7.x

In Torizon OS, external storage devices like SD cards are automatically mounted under /media directory, not /mnt/sdcard (1). The documentation shows that when an external storage device is inserted, it gets automatically mounted at /media (1).

Automatic Mounting Behavior

When you insert an SD card, the system automatically creates mount points based on the device’s label or UUID under /media (1). For example, if your SD card has a label, it would appear as /media/<label> (1).

Docker Volume Binding

To bind an SD card mount point as a Docker volume, you have several options:

Option 1: Bind Mount with Propagation

For dynamic mounting scenarios where the SD card might be inserted after the container starts, you should use bind mount propagation (2):

volumes:
  - type: bind
    source: /media
    target: /media
    bind:
      propagation: shared

(2)

This configuration allows the container to see new mounts that appear under /media after the container has started (2).

Option 2: Static Mount Point

If you know the SD card will be present at container startup, you can mount it directly:

volumes:
  - /media/<your-sd-label>:/app/data

Permissions and Access

User Permissions

The default torizon user in Toradex containers is mapped to several groups that provide hardware access (3). However, for SD card write access, you may need to ensure proper permissions (2).

File System Permissions

By default, USB/SD devices mount with specific permissions (2). For write access from containers, you may need to:

  1. Use the torizon user: Run your application as the torizon user rather than root when possible (3)

  2. Configure mount options: For FAT32 filesystems, you might need to set proper uid and gid options in /etc/fstab to ensure the torizon user can write to the device (2):

/dev/sda1 /media/card auto defaults,sync,auto,nofail,uid=1000,gid=1000 0 0

(2)

Best Practices

  1. Avoid privileged mode: Don’t run containers in privileged mode just for storage access (3)
  2. Use specific mount points: Rather than mounting entire /dev directory, mount only what you need (3)
  3. Consider reliability: Ensure your application handles cases where the SD card might be removed (1)

Security Considerations

Be aware that storing application data on removable media has security implications, as anyone with physical access can remove and examine the SD card (1).

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

So the recommendation is to bind the /media path and dynamically check for available SD cards within the application?

Is it possible to alternatively mount to a static path like /media/sdcard? That would probably require /etc/fstab modifications?

To properly answer your question about SD card mounting options in Torizon OS, I’d be glad to help! Could you let me know which OS and version you are using? Also, please run the tdx-info command to get your hardware information and share the output - you can find more details about this command at Getting Device Information with Tdx-Info | Toradex Developer Center

This will help me provide the most accurate guidance for your specific platform configuration.

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

Ah, I just figured out that the SD card’s partition label is used in the /media/<label> path. That works for us. We’ll give all used SD cards the same partitioning and names, so that they’ll be interchangable.

Greetings @trunner,

Did you have any further questions related to this topic?

Best Regards,
Jeremias

Thanks for asking, but we currently don’t have any follow-up questions. For anyone interested, we added the SD card as a volume to the Docker Compose file like this:

services:
  SERVICE_NAME:
    ...: ...
    volumes:
      - sd_card_data:/media/DATA

volumes:
  sd_card_data:
    driver: local
    driver_opts:
      type: none
      device: /media/DATA
      o: bind,uid=1000,gid=1000

Thanks for sharing your solution as it could be useful for other users.

Best Regards,
Jeremias