1

I have samba installed on the Pi and mounted a usb drive, I can access it on windows but I cannot write to it, I suspect it’s because I need to chmod the drive, but FAT32 does not support permissions, so what are my options here?

pi@raspberrypi:~ $ cat /etc/fstab
proc            /proc           proc    defaults          0       0
PARTUUID=ed2ff758-01  /boot           vfat    defaults          0       2
PARTUUID=ed2ff758-02  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
/dev/sda1 /mnt/usb auto defaults,user 0 1
pi@raspberrypi:~ $

mounted:

pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        30G  2.0G   27G   8% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M  8.0K  464M   1% /dev/shm
tmpfs           464M   13M  452M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/mmcblk0p1   43M   23M   21M  52% /boot
/dev/sda1        30G   64K   30G   1% /mnt/usb
tmpfs            93M     0   93M   0% /run/user/999
tmpfs            93M     0   93M   0% /run/user/1000
pi@raspberrypi:~ $

Samba:

[share]
Comment = Shared Folder
Path = /mnt/usb
Browseable = yes
read only = no
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes

When I try to chmod:

pi@raspberrypi:~ $ sudo chmod 1777 /mnt/usb
chmod: changing permissions of '/mnt/usb': Operation not permitted
pi@raspberrypi:~ $

Successfully mapped on windows 10, but cannot create or delete files only read.

enter image description here

enter image description here

Additional information regarding the OS:

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~ $
  • TL;DR... You could try this approach ("recipe") on my github page. Change exFAT to FAT32 to suit your chosen file system. Let me know if you have questions. – Seamus Jan 29 at 12:57
  • I don't want to access the drive with a username and password. (From your comment you seem to imply this is a user issue/samba permissions issue and not a FAT32 chown related problem, IE in theory in my mind this would work if FAT32 supported permissions: sudo chmod 1777 /mnt/usb – Erik Thiart Jan 29 at 13:05
1

As you say you can't write to the device, I assume that reading works.

There are two approaches to fix this.

  1. Change the permissions when mounting the file system. As you can't chmod a FAT file system, this means that you have to put FAT specific mount options into /etc/fstab:

    umask=value
    Set the umask (the bitmask of the permissions that are not present). The default is the umask of the current process. The value is given in octal.

    dmask=value
    Set the umask applied to directories only. The default is the umask of the current process. The value is given in octal.

    fmask=value
    Set the umask applied to regular files only. The default is the umask of the current process. The value is given in octal.

    You can use this to give permissions to everybody, dmask=000 and fmask=111. Files don't need exec permission.

    Change your line in /etc/fstab to

    /dev/sda1 /mnt/usb vfat dmask=000,fmask=111,user 0 1
    
  2. Make sure Samba has the permissions to access the file system. In smb.conf, you can use the force user (and force group) option. By default the file system will be owned by root, so use with caution and only for the FAT file system.

    force user (S)

    This specifies a UNIX user name that will be assigned as the default user for all users connecting to this service. This is useful for sharing files. You should also use it carefully as using it incorrectly can cause security problems.

    This user name only gets used once a connection is established. Thus clients still need to connect as a valid user and supply a valid password. Once connected, all file operations will be performed as the "forced user", no matter what username the client connected as. This can be very useful.

    Change the definition of the share in smb.conf to

    [share]
    force user = root
    Comment = Shared Folder
    Path = /mnt/usb
    Browseable = yes
    read only = no
    Writeable = Yes
    only guest = no
    create mask = 0777
    directory mask = 0777
    Public = yes
    Guest ok = yes
    
  • Still lost as to how this will look with my config (I am a linux neophyte) – Erik Thiart Jan 29 at 6:40
  • I added the examples. – RalfFriedl Jan 29 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.