• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write to usb Drive from container
#1
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
  Reply
#2
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_typo3fo...57051955f2

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.


You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#3
Hello Sebastian,

the new firmware is now online.
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#4
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?

  Reply
#5
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.










You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#6
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.
  Reply
#7
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.
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#8
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/ ... "
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#9
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.
  Reply
#10
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
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  [SOLVED] activate LED1/2 with Node-RED + fieldbus nodes container Christian_Rau 6 84 Yesterday, 10:30 AM
Last Post: Armin@netPI
  Cannot start container Magnus 7 31 October-16th-2019, 01:00 PM
Last Post: Armin@netPI
  Generate VLAN interfaces in container FrankJacob 7 44 September-26th-2019, 03:19 PM
Last Post: Armin@netPI
  create container in Portainer v1.12.4 dcatteeu 2 23 September-9th-2019, 12:12 PM
Last Post: dcatteeu
  UMTS/LTE support via USB router/modem sticks in a container Armin@netPI 3 153 September-5th-2019, 02:07 PM
Last Post: Armin@netPI
  Exporting and importing container images Armin@netPI 0 22 August-23rd-2019, 10:39 AM
Last Post: Armin@netPI
  Ready-to-deploy: full featured Node-RED container Armin@netPI 5 73 July-25th-2019, 06:16 AM
Last Post: Armin@netPI
  New Container example "OPC UA server" Armin@netPI 0 17 April-12th-2019, 11:51 AM
Last Post: Armin@netPI
  Official Node-RED container Armin@netPI 0 18 April-5th-2019, 10:39 AM
Last Post: Armin@netPI
  Multi-stage builds for slim container images Armin@netPI 0 10 February-7th-2019, 04:14 PM
Last Post: Armin@netPI

Forum Jump:


Users browsing this thread: 1 Guest(s)