File Lister node not returning filename unless Pi is logged in

I've read so many different posts about how to auto-mount USB's and all seem to suggest different methods. I tried to find it on the Raspberry Pi documentation but I couldn't see it.

The method I used above seems to have mounted the USB, the file-lister node can now see the file and use this to send the path - but I can no longer write to it with Node-Red (file node) or edit it through the Desktop.

If someone would be able to point me in the right direction to fix these permissions that would be great.

Thanks

If you list the processes running on your pi who owns the us disk glue process?
My guess is that you are running udisks-glue as root.

I'd suggest you investigate how to use udisks-glue as the user pi

Hi, Thanks for the reply. I've listed the processes and you are correct - the udisks is running as root. I'll try and find a tutorial on how to run udisks as user pi.

I don't think it is a matter of running udev as use pi, but of telling it what permissions to give the mounted drive. However there may be an easier way. If you create a folder on the drive and make it owned by user pi, then it should not matter who the drive itself is owned by, you should still be able to write to the folder. Perhaps that will be good enough for you.

Maybe too late to the party, but here is what I use to mount usb to pi -

Mount USB drive (automount):

  • determine UUID of drive by using "sudo blkid"

  • create directory for mount point "sudo mkdir /mnt/usb1"

  • open "fstab" using sudo "nano /etc/fstab"

  • edit "fstab" and add "UUID=whatever-it-is /mnt/usb1 ntfs nofail,noatime,auto,users,rw,uid=1000,gid=100,umask=0002 0 0"

  • change permissions on /mnt/usb1 directories "sudo chown pi:pi -R /mnt/usb1"

@Bobo does that work if the drive is inserted after boot?

Hi Bobo,
Thanks for getting in touch.

I'm looking to mount all drives automatically so that we can collect and swap the drives from site without having to set up the mount each time.

I believe that your method only works for a single usb drive, is this correct?

Honest answer is I'm not sure as it stays permanently plugged in.

The same procedure should work for any number of drives.

Another aspect I haven't seen mentioned yet in this topic, but have you thought of a way so far to prevent that when the USB drives are pulled out, it is being unmounted first and isn't being written to at the moment, to prevent data corruption or even damaging the station/partition. A forced reboot can already cause that, let alone if the pi is writing information to it while the drive is being swapped. I was usually very careful already with unmounting/waiting for it to be done before removing, but when Windows 7 once decided to force a reboot while updating (I was too late cancelling it manually as I was writing 1 tb of GIS data to that drive, and wasn't watching the system itself at the time). The drive got corrupted, and most of the written data was lost.

Make sure that when the USB drive is removed from the pi, the station get unmounted first, then removed, and carefully mounted (or automatically mounted) again when the new drive is inserted. Thinking in Node-RED terms, a potential setup could be through using exec nodes, though I have no clue if umount can be called nowadays when not on an elevated prompt. I used the hardcoded /etc/fstab aproach, and the drives were never removed. Either way, set up a flow where when it's not being written and a request was arrived (I'm just brainstorming here, a GPIO connected button perhaps?) for removal it stops writing, unmounts the drive, signals it's ready and the drive can be replaced, then when the new one gets detected it mounts it again.

Especially when dealing with manual removal and "once in a while", corrupted drives and data loss are not what you want. :slight_smile:

Hi AFelix,

Thanks for the detailed response. Currently I have a button set up with a GPIO (pin 5) that sends a shutdown command to the pi. Then when I have swapped the drives I can press the button again, grounding pin 5 and restarting the pi.

Is this a valid way to do this or am I likely to corrupt my drive?

As long as you're using a clean shutdown you should be fine :stuck_out_tongue: Sounds like you won't have to worry about that :slight_smile:

I don't think you mentioned you were restarting the pi rather than hot plugging. In that case you can certainly use fstab to tell the system where to mount each drive.

Hi Colin,

How would I got about using the fstab to mount multiple drives automatically? The drives will all have different UUIDs and I can't sign in each time to run the mounting process manually.

The way described by @Bobo. Make a folder for each one to mount into then add a line to fstab for each drive, identified by the UUIDs. Then on reboot any drives present should be mounted to the appropriate directory. Keep a copy of fstab before you start in case you mess up and can't remember what was there originally.

Hi Colin, sorry I don't think I worded that very well. I cannot run the fstab command for each USB change as the devices will be on site. I'm looking to find a way to automatically mount any drive on boot - I potentially have large amounts of these devices so it has to be automatic and can't rely on any manual processing after initial set up.

There isn't any manual process after initial setup. /etc/fstab is not a command, it is a file. All you need to do is to put a line in there for each of the devices.

Just realised you want to mount any usb device to one mount point on boot. If that is so then the original method you tried, using udisks, is the correct way.

For your user permissions problem try adding uid=1000,gid=1000 to the udisks automount_options. I have not used udisks but googling suggests that may be the way to do it. This assumes that user pi is the default user (id 1000). You can check that using the command
id -u pi

Hi All,

I think I've got it working.

My process was:

sudo apt-get update
sudo apt-get install udisks-glue
sudo nano /etc/rc.local

And then add the following two lines between the description and "exit 0"

sudo udisks --unmount /dev/sda1
sudo udisks --mount /dev/sda1 --mount-options umask=0000

This worked to mount the drive, all I needed to do after this was change the directory that the Node-Red was looking to as it was set to look in /media/pi/ and the drive was mounted in /media/.

Thank you to everyone for their help over the last few days - wouldn't have had a clue how to do this without your help.

2 Likes