How to use SD card and USB storage

Hi,

I want to save some data on SD card or USB storage. In SSH terminal I found that my SD card is in /media/SDCARD. When I write in text file from application, data is not stored on SD card - I remove SD card but still I can access to this file.

Could you please help me with saving data to SD card or USB storage?
Can I set write rights to SD card or USB from appconfig_0?

For testing I use:

  • Verdin development board ver 1.1B
  • Toradex Verdin iMX8M Plus WB
  • Visual Code with Torzin extension
  • .Net 5 Blazor application

In appconfig_0 in volumes I add

/media/SDCARD /SdCard

In container SSH terminal I run command

chmod -R 757 /SdCard

Code snippet for adding data in text file

            string[] lines = { "First line", "Second line", "Third line" };
            var file = Path.Combine("/SdCard", "test.txt");
            using (StreamWriter outputFile = new StreamWriter(file, true))
            {
                foreach (string line in lines)
                    outputFile.WriteLine(line);
            }

Regards

A few simple tests:

[1]
torizon_core# ls -la /media/SDCARD

[2]
torizon_core# ls -la > /media/SDCARD/test.txt

[3]
torizon_core# ls -la /media/SDCARD

this same from container

container# ls -la /SdCard
container# ls -la > /SdCard/test.txt
container# ls -la /SdCard

Greetings @MariusM,

Can you write to your SD card from the terminal outside of your application?

Also it sounds like you’re removing/re-inserting the SD card while the container is running. In such cases Docker needs special options to handle the propagation of these events to the container. Otherwise you end up with situations as you described where the SD card is removed but still “appears” in the container.

There’s a bit more detail on this post here: Automatic mounting of sdcard on boot

Please try the bind-propagation as described in the other post.

Best Regards,
Jeremias

Hi MariusM,

with ls -la commands I see that all time linux mout SD card with root user.

Thank you.

Regards

Hi @jeremias.tx,

Adding in fstab configuration for automatic mounting with torizon user solve my problem.

Thank you.

Regards

Glad I could help out.