# Writing to a Flash Drive located on a Raspi

**URL:** <https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681>\
**Category:** Hardware\
**Tags:** raspberry-pi\
**Created:** [19 February 2024 21:19 UTC](https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681 "2024-02-19T21:19:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotdog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotdog/32/88448_2.png) [@hotdog](https://discourse.nodered.org/u/hotdog)\
**Post date:** [19 February 2024 21:19 UTC](https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681/1 "2024-02-19T21:19:04Z")

</div>

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?

---

<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:** [19 February 2024 21:36 UTC](https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681/2 "2024-02-19T21:36:48Z")

</div>

> [@hotdog](#):
>
> without specifying a local root directory

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.

---

<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:** [19 February 2024 21:46 UTC](https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681/3 "2024-02-19T21:46:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 February 2024 23:17 UTC](https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681/4 "2024-02-19T23:17:18Z")

</div>

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 🙂  
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

---

<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:** [20 February 2024 00:08 UTC](https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681/5 "2024-02-20T00:08:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AndrewBeasley](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@AndrewBeasley](https://discourse.nodered.org/u/AndrewBeasley)\
**Post date:** [21 February 2024 01:20 UTC](https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681/6 "2024-02-21T01:20:02Z")

</div>

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

---

<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 April 2024 01:20 UTC](https://discourse.nodered.org/t/writing-to-a-flash-drive-located-on-a-raspi/85681/7 "2024-04-21T01:20:38Z")

</div>

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