• 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
  TOSILOCK for CONTAINER COswald 3 2,184 July-13th-2021, 11:32 AM
Last Post: Armin@netPI
  Access to RTC from my own container application tad 1 3,521 March-19th-2021, 02:58 PM
Last Post: Armin@netPI
  [SOLVED] Starting services/commands/scripts at startup of a container Jonas.Sellmann@outlook.de 9 6,016 March-9th-2021, 08:47 AM
Last Post: WalterSchaefer
  OpenVPN container Armin@netPI 0 1,615 January-3rd-2021, 12:13 PM
Last Post: Armin@netPI
  operating Console of a container on netPI connected to Wi-Fi tethering tad 3 2,612 December-3rd-2020, 12:32 PM
Last Post: tad
  NIOT-E-NPIX-4DI4DO with netpi-netx container WalterSchaefer 3 6,476 November-25th-2020, 01:06 PM
Last Post: zen89
  NPIX-4DI4DO and NetPi-Nodered container issues alhammi 4 7,584 November-16th-2020, 01:35 PM
Last Post: alhammi
  Get host MAC via REST API inside container bschandra 4 3,641 November-16th-2020, 09:26 AM
Last Post: bschandra
  Exporting and importing container images Armin@netPI 3 3,067 May-20th-2020, 11:24 AM
Last Post: COswald
Exclamation Creating a container Linnerz 6 4,430 March-6th-2020, 02:47 PM
Last Post: Armin@netPI

Forum Jump:


Users browsing this thread: 2 Guest(s)