# Write file node issue with usb on rpi

**URL:** <https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174>\
**Category:** General\
**Created:** [6 March 2023 12:00 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174 "2023-03-06T12:00:59Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [6 March 2023 12:00 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/1 "2023-03-06T12:00:59Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9ff682bfb4835789d87a3e712ce438435878aed4.png)

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 12:14 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/2 "2023-03-06T12:14:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [6 March 2023 13:41 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/3 "2023-03-06T13:41:38Z")

</div>

@Colin

node-red-start

Start Node-RED

Once Node-RED has started, point a browser at [http://192.168.0.41:1880](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](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](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](http://192.168.0.41):xxxx/tts

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 14:09 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/4 "2023-03-06T14:09:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [6 March 2023 14:55 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/5 "2023-03-06T14:55:46Z")

</div>

> [@Colin](#):
>
> Does that folder exist? The file node expects the folder to exist.

I think it will make the dir if not exist,

 ![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/c/1cbfc437fb546e030e4082b021dcb6d6b846a3ab.png)

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

 ![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c9f4c6efa1907ff2c5866651876b2a5005b6e92.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 15:17 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/6 "2023-03-06T15:17:45Z")

</div>

It is probably the automount issue then.

---

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [6 March 2023 15:25 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/7 "2023-03-06T15:25:41Z")

</div>

@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....☹

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 15:30 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/8 "2023-03-06T15:30:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [6 March 2023 15:40 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/9 "2023-03-06T15:40:09Z")

</div>

@Colin

I think Linux doesn't like that,

![afbeelding](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d561ba09995a5a4149c2bbc50beb16906fd9dcc4.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 15:44 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/10 "2023-03-06T15:44:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [6 March 2023 15:54 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/11 "2023-03-06T15:54:40Z")

</div>

@Colin

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

Then I tried to take ownership, but failed again,

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 16:37 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/12 "2023-03-06T16:37:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [6 March 2023 18:52 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/13 "2023-03-06T18:52:04Z")

</div>

@colin

```auto
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

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [6 March 2023 19:39 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/14 "2023-03-06T19:39:44Z")

</div>

Are you running RPiOS? Desktop or lite?

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 21:30 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/15 "2023-03-06T21:30:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [6 March 2023 22:40 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/16 "2023-03-06T22:40:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![henkkas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henkkas/32/39844_2.png) [@henkkas](https://discourse.nodered.org/u/henkkas)\
**Post date:** [7 March 2023 09:09 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/17 "2023-03-07T09:09:42Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 March 2023 09:09 UTC](https://discourse.nodered.org/t/write-file-node-issue-with-usb-on-rpi/76174/18 "2023-03-21T09:09:55Z")

</div>

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