Hilscher Community Forum
Write to usb Drive from container - Printable Version

+- Hilscher Community Forum (https://forum.hilscher.com)
+-- Forum: netPI 3 - Docker featuring Industrial Raspberry Pi 3 platform (https://forum.hilscher.com/forum-1.html)
+--- Forum: Software (https://forum.hilscher.com/forum-5.html)
+--- Thread: Write to usb Drive from container (/thread-207.html)

Pages: 1 2


Answer - SebastianSoller - March-14th-2018

Hello,

i am writing on a python program to write on a usb stick plugged in one of the usb ports on the NetPi. The program is working as intended but i need to write to a csv outide the Pi on a usb drive. For this i have two questions.
1. Is there a way to find the path of plugged devices and view if there are any?
2. Is it possible to write to the desired path from inside a container with the Volume settings of the container start as with the -v option when using docker on raspberry pi3

Thanks in advance,
Sebastian


Answer - Armin@netPI - March-15th-2018

Hello Sebastian,

1.) 2.)what you need for your inquiry is the next system software version of netPI where are opening the function for mapping external devices such as USB. I hope it will be published end of next week.

With this new software version you are able to map the devives /dev/sda and /devb/sda1 ... sdb ... sdc and so on into a container. Then you can use the mount command in the container and then you can access it as usual.

See here: https://www.netiot.com/forum/?tx_typo3forum_pi1%5Btopic%5D=81&tx_typo3forum_pi1%5BshowForm%5D=0&tx_typo3forum_pi1%5Baction%5D=show&tx_typo3forum_pi1%5Bcontroller%5D=Topic&cHash=7dcfeb7013aaaffffa195457051955f2

And indeed you are not really able to read out to which device the USB sticks was mapped in the host linux. What I can tell you is that it will be the same as on your Raspberry Pi 3.





Answer - Armin@netPI - March-23rd-2018

Hello Sebastian,

the new firmware is now online.


Answer - SebastianSoller - March-27th-2018

Hello Armin,
Thanks for your answer.
I still have a problem of understanding how to mount the device on the netpi.

On my Test pi3 i can just run the container with:
docker run -i -t -v /media/usb:/path/in/container "container name"
which leads to the program saving the data to the uSB drive.
Can i do something similar with the netpi with the portainer Interface or ist there a possibility of executing the console command?




Answer - Armin@netPI - March-27th-2018

This is an easy one.

Insert the USB stick. On netPI the 1st stick will be mounted in netPIs host linux as /dev/sda and /dev/sda1. The device /dev/sda1 will the device drive that gives you the access to the file contents.

Now if you now start your container you have to start the container with privileged mode. This is the first point. Second is to add the device /dev/sda1:/dev/sda1 into the container when you start it.

If you now jump into the container and make a ls /dev you will now see the device /sda1. But it is not mounted yet. You can additional use the fdisk -l command to list you USB device.

Make sure you are root in the container. Then you can do the following:

* create a folder such as with mkdir /tmp/mydrive
* use the command mount /dev/sda1 /tmp/mydrive
* jump into the folder with cd /tmp/mydrive

and you are right in the USB stick.













Answer - SebastianSoller - March-27th-2018

I updated to the version 1.1.2 but still get the following error

'/dev/sda1:/app/test': invalid mount config for type "bind": Bind mount of /dev/sda1 not allowed for security reasons.


Answer - Armin@netPI - March-27th-2018

Please map as I wrote: option "add device" -> Host "/dev/sda1" and Container "/dev/sda1".

With this setting the device sda1 is mapped into the container. But then it is not mounted.

Then call mount /dev/sda1 /app/test and then it is mounted.


Answer - Armin@netPI - March-27th-2018

Oh hold on, I think you are using the wrong option in the Docker web GUI.

Please do not use the option "volumes". This option is not working. You have to use the option "Runtime/add devices/ ... "


Answer - SebastianSoller - April-17th-2018

This solution worked well for me until I ran into the problem that after saving to many files on to the mounted device the internal storage space of the NetPi got full, since it also seems to be stored in the container.
Is there a way to exclusively write to the external storage or a way to restart the container periodically?

Made a mistake there, everything is working as intended. Thank you for the help.


Answer - Armin@netPI - April-17th-2018

324 Wrote:Made a mistake there, everything is working as intended. Thank you for the help.

Good to hear that everything is working fine then.

Thx
Armin