Write file node issue with usb on rpi

I am trying to save some objects to a file on an USB-stick in my raspberry pi.

This USB-stick I am already using for daily backup of influx database with an exec node, that runs simple without any issues.

Now I am trying to save some objects to file by means of the write file node. When I activate the node I get "permission denied"-error.

afbeelding

I guess this has something to do with access rights ????
How can I solve this problem??

How did you install node red and how do you run it?
Stop node red and start it again in a command window and copy/paste the full output here please.

@Colin

node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.0.41:1880
On Pi Node-RED works better with the Firefox or Chrome browser

Use node-red-stop to stop Node-RED
Use node-red-start to start Node-RED again
Use node-red-log to view the recent log output
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot
Use sudo systemctl disable nodered.service to disable autostart on boot

To find more nodes and example flows - go to http://flows.nodered.org

Starting as a systemd service.
6 Mar 14:39:32 - [info]
Welcome to Node-RED

6 Mar 14:39:32 - [info] Node-RED version: v3.0.2
6 Mar 14:39:32 - [info] Node.js version: v16.19.0
6 Mar 14:39:32 - [info] Linux 5.15.84-v7+ arm LE
6 Mar 14:39:34 - [info] Loading palette nodes
6 Mar 14:39:44 - [info] Dashboard version 3.3.1 started at /ui
6 Mar 14:39:45 - [info] Settings file : /home/pi/.node-red/settings.js
6 Mar 14:39:45 - [info] Context store : 'default' [module=localfilesystem]
6 Mar 14:39:45 - [info] User directory : /home/pi/.node-red
6 Mar 14:39:45 - [warn] Projects disabled : editorTheme.projects.enabled=false
6 Mar 14:39:45 - [info] Flows file : /home/pi/.node-red/flows.json
6 Mar 14:39:45 - [info] Server now running at http://127.0.0.1:xxxx/
6 Mar 14:39:45 - [warn] Using unencrypted credentials
6 Mar 14:39:46 - [info] Starting flows
6 Mar 14:39:46 - [info] ttsultimate-config 595102db6902593e: Autodiscover current IP 192.168.0.41
6 Mar 14:39:46 - [info] ttsultimate-config 595102db6902593e: TTS cache set to /home/pi/.node-red/sonospollyttsstorage/ttsfiles
6 Mar 14:39:46 - [info] ttsultimate-config 595102db6902593e: google credentials path set to /home/pi/.node-red/sonospollyttsstorage/ttsultimategooglecredentials
6 Mar 14:39:46 - [info] ttsultimate-config 595102db6902593e: hailing path set to /home/pi/.node-red/sonospollyttsstorage/hailingpermanentfiles
6 Mar 14:39:46 - [info] ttsultimate-config 595102db6902593e: permanent files path set to /home/pi/.node-red/sonospollyttsstorage/ttspermanentfiles
6 Mar 14:39:46 - [info] ttsultimate-config 595102db6902593e: Node-Red node.js Endpoint will be created here: http://192.168.0.41:xxxx/tts

As you can see, I installed it as user PI.

That looks ok.

Does that folder exist? The file node expects the folder to exist.

Are you relying on the OS auto mount feature to mount the stick or have you put the mount details in /etc/fstab? Automount only happens if you are logged in to the pi, so if you are not currently logged in then it will not be mounted.

I think it will make the dir if not exist,

I don't no about auto mount or /etc/fstab.

It is probably the automount issue then.

@Colin

In Linux, I can make folder there as user pi, with sudo mkdir <foldername>.

But even then write file node is permission denied to write the file.
I think I cannot use write file node here, because doesn't work with sudo internally or something?

I guess have to use exec node to get the job done....:frowning:

You need to give pi permission to write to the stick. Remove the settings folder then run
sudo chown pi:pi /media/pi/BU
Remove the settings folder and try to create it again, now you should be able to create it without sudo and node-red should be able to write to it.

1 Like

@Colin

I think Linux doesn't like that,

afbeelding

Please copy/paste output rather than screenshot, if possible. Use the </> button at the top of the forum entry window when pasting it so that the forum does not mess with the format.

No you are right, you can't change the ownership of the device mount point. You will have to create a folder on the stick and then use that. So make a folder backups, or whatever on the stick and chown it to pi as shown. Then you should be able to write to that without sudo and it should work from node-red.

@Colin

Ok, I made the folder settings with sudo mkdir settings in BU folder.

Then I tried to take ownership, but failed again,

pi@EBStest:/media/pi/BU $ sudo chown pi:pi /media/pi/BU/settings
chown: changing ownership of '/media/pi/BU/settings': Operation not permitted
pi@EBStest:/media/pi/BU $ 

OR

i@EBStest:/media/pi/BU $ sudo chown pi:pi settings
chown: changing ownership of 'settings': Operation not permitted


What do
ls -al /media/pi/BU
and
ls -al /media/pi/BU/settings
give?

Also
blkid

I presume the stick is not write protected.

@colin

pi@EBStest:~ $ ls -al /media/pi/BU
total 996
drwxr-xr-x  32 root root 32768 Jan  1  1970 .
drwxr-x---+  3 root root  4096 Feb 15 07:34 ..
drwxr-xr-x   2 root root 32768 Feb  9 15:52 2023_02_09T15_52_07
drwxr-xr-x   2 root root 32768 Feb  9 16:41 2023_02_09T16_41_32
drwxr-xr-x   2 root root 32768 Feb 10 02:00 2023_02_10T02_00_00
drwxr-xr-x   2 root root 32768 Feb 11 02:00 2023_02_11T02_00_00
drwxr-xr-x   2 root root 32768 Feb 11 10:38 2023_02_11T10_38_24
drwxr-xr-x   2 root root 32768 Feb 12 02:00 2023_02_12T02_00_00
drwxr-xr-x   2 root root 32768 Feb 13 02:00 2023_02_13T02_00_00
drwxr-xr-x   2 root root 32768 Feb 14 02:00 2023_02_14T02_00_00
drwxr-xr-x   2 root root 32768 Feb 15 02:00 2023_02_15T02_00_00
drwxr-xr-x   2 root root 32768 Feb 16 02:00 2023_02_16T02_00_00
drwxr-xr-x   2 root root 32768 Feb 17 02:00 2023_02_17T02_00_00
drwxr-xr-x   2 root root 32768 Feb 18 02:00 2023_02_18T02_00_00
drwxr-xr-x   2 root root 32768 Feb 19 02:00 2023_02_19T02_00_00
drwxr-xr-x   2 root root 32768 Feb 20 02:00 2023_02_20T02_00_00
drwxr-xr-x   2 root root 32768 Feb 21 02:00 2023_02_21T02_00_00
drwxr-xr-x   2 root root 32768 Feb 22 02:00 2023_02_22T02_00_00
drwxr-xr-x   2 root root 32768 Feb 23 02:00 2023_02_23T02_00_00
drwxr-xr-x   2 root root 32768 Feb 24 02:00 2023_02_24T02_00_00
drwxr-xr-x   2 root root 32768 Feb 25 02:00 2023_02_25T02_00_00
drwxr-xr-x   2 root root 32768 Feb 26 02:00 2023_02_26T02_00_00
drwxr-xr-x   2 root root 32768 Feb 27 02:00 2023_02_27T02_00_00
drwxr-xr-x   2 root root 32768 Feb 28 02:00 2023_02_28T02_00_00
drwxr-xr-x   2 root root 32768 Feb 28 08:01 2023_02_28T08_01_20
drwxr-xr-x   2 root root 32768 Mar  1 02:00 2023_03_01T02_00_00
drwxr-xr-x   2 root root 32768 Mar  2 02:00 2023_03_02T02_00_00
drwxr-xr-x   2 root root 32768 Mar  3 02:00 2023_03_03T02_00_00
drwxr-xr-x   2 root root 32768 Mar  4 02:00 2023_03_04T02_00_00
drwxr-xr-x   2 root root 32768 Mar  4 10:17 2023_03_04T10_17_16
drwxr-xr-x   2 root root 32768 Mar  5 02:00 2023_03_05T02_00_00
drwxr-xr-x   2 root root 32768 Mar  6 02:00 2023_03_06T02_00_00
pi@EBStest:~ $ ls -al /media/pi/BU/settings
ls: cannot access '/media/pi/BU/settings': No such file or directory
pi@EBStest:~ $ ls -al /media/pi/BU/settings
total 64
drwxr-xr-x  2 root root 32768 Mar  6 19:50 .
drwxr-xr-x 33 root root 32768 Jan  1  1970 ..
pi@EBStest:~ $ blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="D386-9DE9" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="667563a5-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="996c1b5f-170b-4f38-a5e0-85eef5acf12c" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="667563a5-02"
/dev/sda1: LABEL="BU" UUID="C3F7-8710" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="766457fc-01"
pi@EBStest:~ $

second time with

ls -al /media/pi/BU/settings

The folder settings has been made

I don't think this is ever going to work! I read a lot of stuff about this subject, most are endless dicussion with no solution.

I make backup's of my influx database with command:

sudo influxd backup -portable /media/pi/BU/2023_03_06T20_35_29

That works perfect, on any usb-stick.

So I think I will use the same procedure for this as well.
Only problem is how to get object to a file.

Are you running RPiOS? Desktop or lite?

With no USB drive inserted, what does ls -al /media/pi show?

I wonder if it is because the stick is formatted as vfat that you can't change the permisssions. I format mine as ext4 so as to be fully compatible with linux.

I run mine as ntfs, you do have to have ntfs-3g installed though.

Try sudo chown -R pi:pi /media/pi (assuming that the mount point is /media/pi) because you should not have to use sudo to copy files to the stick

@Colin @jbudd @Buckskin

I have chosen for a pragmatic solution. My motto is always:

If it doesn't want it the way it should, then it should be the way it wants.

So I use the node-red folder as temporary storage to write the file to with file write node .
Then with exec node move file with sudo mv <source> <destination> to final usb-destination.

This works great for me!!

Thanks for all your help, guys. Keep up the good work.

1 Like

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