Raspberry Pi上FAT32 USB记忆棒的默认文件权限 [英] Default file permissions for FAT32 USB stick on Raspberry Pi
问题描述
当我将已格式化为FAT32的USB闪存盘/缩略图驱动器插入Raspberry Pi(运行Raspbian)时,文件权限默认为644,我无法更改它们.
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.
我需要将存储棒保留为FAT32,以便可以将其用于Windows系统.
I need to leave the stick as FAT32 so it can be used back and forward to a Windows system.
我已经使用udev编写了一条规则,但是我无法使其正常工作.
I have written a rule using udev but I can't get it to work.
我的udev规则如下:
My udev rule looks like this:
# Set up any USB stick for full write access
KERNEL=="sd?1", MODE="0777"
# 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.
我最终要实现的目标是能够从PHP写入USB记忆棒.
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.
推荐答案
问题已解决-经过数小时并得到了我的Linux专家朋友Jox的大量建议.
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)Disable GUI,这又禁用了自动挂载. (Pi仍然无头运行).
1) Disble GUI which in turn disables Automount. (The Pi is running headless anyway).
2)如下创建udev规则(保存在/etc/udev/rules.d/81-usbmount.rule中):
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>
这会给USB驱动器一个统一的名称,并运行一个脚本来安装和卸载该驱动器.
This gives the USB drive a consistent name and runs a script to mount and unmount the drive.
3)向FSTAB添加一个条目(存储在/etc/fstab中):
3) Add an entry to FSTAB (stored in /etc/fstab):
/dev/stick1 /media/usbstick vfat uid=www-data 0 0
这会将默认用户ID设置为www-data,因为这是Apache/PHP运行的用户.
This sets the default user id to www-data because that is the user Apache/PHP runs as.
4)创建脚本以进行安装和卸载. (存储在/home/pi/mount_usb.sh中)
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>
回声仅用于调试目的.
[我也不认为我已经掌握了代码格式化的内容]
[I don't think I've mastered the code formatting thingy either]
这篇关于Raspberry Pi上FAT32 USB记忆棒的默认文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!