Writing to a Flash Drive located on a Raspi

I am trying to find a way to write to a usb device without specifying a local root directory. I found some information about using /dev/ttyUSB and /dev/pts/0, but when I attempt to implement that into my flow I am given either errors or a "permission denied" message. Is this even possible?

What do you mean by that? Do you mean you want to write to it without mounting it? I don't think that is possible.

Hi @hotdog.

This is on Raspberry Pi OS? Exactly which version?

Do you want to write a specific USB flash drive, or to any flash drive that is plugged in?

When a drive is plugged in:

  • What does the command lsusb show?
  • Does the command df -h show the drive?
  • Does the command sudo fdisk -l show it?

You’ll probably need to run Node-RED as root in order to access raw hardware like that. Generally a bad idea as it can wrong really easily :slight_smile:
Normally you would mount the drive outside of Node-RED and give access to it first. I thought for most drives that happened automatically on Pi and they appear somewhere like /media/drivelabel

I believe the desktop version of the OS automounts flash drives but strangely the command line only RPiOS Lite does not.

It's not too difficult for Node-red to detect via exec that a flash drive is present and attempt to mount it.

1 Like

[quote="jbudd, post:5, topic:85681"]
...
I believe the desktop version of the OS automounts flash drives but strangely the command line only RPiOS Lite does not.
...[/quote]

It's actually the file manager (PCmanFM IIRC) that handles the auto mount so it will not happen in Lite as this does not run.

If fstab cannot be used to mount then a UDEV rule could automatically mount the drive without impacting Node-RED. Note if you want to use fstab rather than create a UDEV rule then you could look at the x-system.automount or using mount -a from a CRON job to mount the drive if it's not present at boot.

Using the user options in the mount command the Node-RED user can have R/W access and I think the mount point could be under the application directory (/data in my Docker config) making access a doddle from the nodes.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.