Default file permissions for FAT32 USB stick on Raspberry Pi

余生长醉 提交于 2019-12-11 19:32:44

问题


When I plug a USB stick/thumbdrive that has been formatted as FAT32 into a Raspberry Pi (running Raspbian) the file permissions default to 644 and I cannot change them.

I need to leave the stick as FAT32 so it can be used back and forward to a Windows system.

I have written a rule using udev but I can't get it to work.

My udev rule looks like this:

# Set up any USB stick for full write access KERNEL=="sd?1", MODE="0777"

I determined that the rule is getting triggered because I had it renaming the device. It is setting the permissions of the device itself, but not the individual files on the device.

What I am ultimately trying to achieve is the ability to write to the USB stick from PHP.

I feel I am very close to the answer but can't see what I am missing.


回答1:


Problem resolved - after several hours and much advice from my Linux guru friend Jox.

It is somewhat involved and there may be an easier way - happy to hear about it if there is.

1) Disble GUI which in turn disables Automount. (The Pi is running headless anyway).

2) Create a udev rule as follows (saved in /etc/udev/rules.d/81-usbmount.rule ):

<code>
# Set up any USB stick for full write access

KERNEL=="sd?1", ACTION=="remove", RUN+="/home/pi/mount_usb.sh"
KERNEL=="sd?1", SYMLINK="stick1"
KERNEL=="sd?1", ACTION=="add", RUN+="/home/pi/mount_usb.sh"
</code>

This gives the USB drive a consistent name and runs a script to mount and unmount the drive.

3) Add an entry to FSTAB (stored in /etc/fstab):

 /dev/stick1     /media/usbstick  vfat    uid=www-data        0 0 

This sets the default user id to www-data because that is the user Apache/PHP runs as.

4) Create script to do the mount and unmount. (Stored in /home/pi/mount_usb.sh)

<code>
 #! /bin/bash
 # script to mount and unmount USB stick
 echo "Starting $ACTION" > /home/pi/mylog.txt
 case $ACTION in
   add)
      echo "Mounting" >> /home/pi/mylog.txt
      umount /dev/david  2>> /home/pi/mylog.txt
      mount -a  2>> /home/pi/mylog.txt ;;
   remove) 
      echo "Unmounting" >> /home/pi/mylog.txt
      umount /dev/sda1  2>> /home/pi/mylog.txt ;;
   *)  
      echo "NOTHING x$ACTIONx" >> /home/pi/mylog.txt ;;
 esac 
</code>

The echoes are just for debug purposes.

[I don't think I've mastered the code formatting thingy either]



来源:https://stackoverflow.com/questions/23097285/default-file-permissions-for-fat32-usb-stick-on-raspberry-pi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!