ContextStorage: saving to USB SSD

Running Node Red on a Raspberry Pi 4 with a USB SDD for file storage.

I'm trying to set up ContextStorage to save variable to a USB SDD to avoid frequent writing to the SD card. I've got it to work, variable are saved to the USB SSD but Node Red no longer start on Reboot and I get a warning when starting it from a Command window so I guess something is wrong.

settings.js
contextStorage: {
default: "memoryOnly",
memoryOnly: { module: "memory" },
file: { module: "localfilesystem",
config: {
dir: "/media/pi/usb1/",
base: "context" }
},
},

Start log
22 Nov 21:52:11 - [info] Node-RED version: v3.0.2
22 Nov 21:52:11 - [info] Node.js version: v16.18.0
22 Nov 21:52:11 - [info] Linux 5.15.76-v7l+ arm LE
22 Nov 21:52:13 - [info] Loading palette nodes
22 Nov 21:52:15 - [info] Dashboard version 3.2.0 started at /ui
22 Nov 21:52:16 - [info] Settings file : /home/pi/.node-red/settings.js
22 Nov 21:52:16 - [info] Context store : 'memoryOnly' [module=memory]
22 Nov 21:52:16 - [info] Context store : 'file' [module=localfilesystem]
22 Nov 21:52:16 - [info] User directory : /home/pi/.node-red
22 Nov 21:52:16 - [warn] Projects disabled : editorTheme.projects.enabled=false
22 Nov 21:52:16 - [info] Flows file : /home/pi/.node-red/flows.json
22 Nov 21:52:16 - [info] Server now running at http://127.0.0.1:1880/

22 Nov 21:52:16 - [info] Starting flows
22 Nov 21:52:16 - [warn] Unknown context store 'memory' specified. Using default store.
22 Nov 21:52:17 - [info] Started flows
22 Nov 21:52:17 - [info] [mqtt-broker:Local server] Connected to broker: mqtt://192.168.1.20:1883

Are my setting.js entries correct?

Read this page of the documentation and then look at your settings:
https://nodered.org/docs/user-guide/context

If you reboot then immediately run node-red-log what do you see?

I think your entry in settings.js should look like this"

contextStorage: {
	default: { 
		module: "memory" },
		file: { module: "localfilesystem",
				config: {
					dir: "/media/pi/usb1/",
					base: "context" 
				}
		}
	}
},

@Switchblade2 sort out settings.js as @zenofmud suggests, then if it still doesn't run on boot, post the log as I suggested.

Thanks for your help on this.

I've made the settings.js changes as suggested (removing one } to make it work).

node-red-log after reboot gives

Started Node-RED graphical event wiring tool.
23 Nov 10:41:58 - [info]
Welcome to Node-RED
===================
23 Nov 10:41:58 - [info] Node-RED version: v3.0.2
23 Nov 10:41:58 - [info] Node.js  version: v16.18.0
23 Nov 10:41:58 - [info] Linux 5.15.76-v7l+ arm LE
23 Nov 10:42:00 - [info] Loading palette nodes
23 Nov 10:42:05 - [info] Dashboard version 3.2.0 started at /ui
23 Nov 10:42:06 - [info] Settings file  : /home/pi/.node-red/settings.js
23 Nov 10:42:06 - [info] Context store  : 'memoryOnly' [module=memory]
23 Nov 10:42:06 - [info] Context store  : 'file' [module=localfilesystem]
23 Nov 10:42:06 - [error] Failed to start server:
23 Nov 10:42:06 - [error] Error: Error loading context store: Error: EACCES: permission denied, scandir '/media/pi/usb1/context'
    at /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/context/index.js:180:15
nodered.service: Succeeded.
nodered.service: Consumed 8.138s CPU time.

and then node-red-start gives

Started Node-RED graphical event wiring tool.
23 Nov 10:56:30 - [info]
Welcome to Node-RED
===================
23 Nov 10:56:30 - [info] Node-RED version: v3.0.2
23 Nov 10:56:30 - [info] Node.js  version: v16.18.0
23 Nov 10:56:30 - [info] Linux 5.15.76-v7l+ arm LE
23 Nov 10:56:31 - [info] Loading palette nodes
23 Nov 10:56:33 - [info] Dashboard version 3.2.0 started at /ui
23 Nov 10:56:34 - [info] Settings file  : /home/pi/.node-red/settings.js
23 Nov 10:56:34 - [info] Context store  : 'default' [module=memory]
23 Nov 10:56:34 - [info] Context store  : 'file' [module=localfilesystem]
23 Nov 10:56:34 - [info] User directory : /home/pi/.node-red
23 Nov 10:56:34 - [warn] Projects disabled : editorTheme.projects.enabled=false
23 Nov 10:56:34 - [info] Flows file     : /home/pi/.node-red/flows.json
23 Nov 10:56:34 - [info] Server now running at http://127.0.0.1:1880/

23 Nov 10:56:34 - [info] Starting flows
23 Nov 10:56:34 - [warn] Unknown context store 'memoryOnly' specified. Using default store.
23 Nov 10:56:34 - [warn] Unknown context store 'memory' specified. Using default store.
23 Nov 10:56:35 - [info] Started flows
23 Nov 10:56:35 - [info] [mqtt-broker:Local server] Connected to broker: mqtt://192.168.1.20:1883             

It looks like a permission issue but on the same time once node red is started manually I can read and write to the usb disk.

I'm normally running the Raspberry without GUI and I see now that Node Red will not start in the Terminal after Reboot.
But if I start the GUI (startx) and then launch a Terminal window I can start Node Red.
If I close the GUI and return to Terminal then Node Red keeps working without any issue.

I think you are mounting the file when you login to the gui. You should be doing it in /etc/fstab so that is available at all times. On my phone, but I think that is the right file.

Ok, I suspected this and tried to change fstab but could not get it right, I'll read up and make a new try.

This is what I have in /etc/fstab for a usb disc on one of my Pis
UUID=499d9cb2-ecd9-4f64-8fa4-00df680ed271 /media/usbhdd ext4 defaults,nofail 0 0
That is formatted as ext4 of course. I do that with all mine. You can get the UUID of the partition by running
sudo blkid
You have to have a matching partition (/media/usbhdd in my case) already present on your root drive for fstab to mount it at.

All is working now.
@Colin & @zenofmud, many thanks for helping me out.

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