12

I'm trying to chown a specific USB drive folder that has been mounted on my RPI 400.

This is my lsblk -f result:

sda1 exfat  1.0   WD Media 0C23-43CD                               1.8T     0% /mnt/WD Media

And when I try to run as a root (at least according to whoami command) sudo chown -R 1000:1000 /mnt/WD\ Media/TV\ Shows/ I get the following error

chown: changing ownership of '/mnt/WD Media/TV Shows/': Operation not permitted

I think I need this because sonarr can't write there

Thanks!

Nico
  • 121
  • 1
  • 1
  • 3
  • 21
    In general, `operation not permitted` doesn't mean it's not allowed, it means it's not _possible_. The message for not being allowed something would be `permission denied`. – marcelm May 10 '22 at 09:14
  • 4
    @marcelm: Actually no. The string text for EPERM is "Operation not permitted" and it's what you get when you try to do things as a regular user that need root and can't be granted by file permissions. The fact that EPERM is returned for chown() and link() on FAT/EXFAT is an aberration. The only other case where EPERM is used to mean not possible is trying to create a hard link to a directory, and that because it once was permitted for root to do that, so the documentation says EPERM is the error code. – Joshua May 10 '22 at 18:25
  • @Joshua I stand corrected. Although I'd swear I encountered EPERM in more "impossible" situations, in particular drivers returning it in response to ioctl()s. But of course I can't find any concrete examples to back up my story :P – marcelm May 10 '22 at 20:05

1 Answers1

22

exfat doesn't support file ownership. There's no place to record it in the bits being stored on the USB drive, so Linux gives you an error when you attempt to change them.

Try mounting with uid=1000,gid=1000, which presents all the files and directories as owned by the user you're using. That should allow all programs run by that user to write to it.

Alternatively, you could use umask=0000, which presents all the files and directories as 777 (all users can read and write).

Brian Silverman
  • 354
  • 1
  • 7
  • 28
    Instead of umask=0000 try uid=1000 so the files appear as owned by you. – user253751 May 10 '22 at 10:34
  • 13
    -1 for suggesting that even completely untrusted system accounts like `nobody` should have write access to removable media. Setting the uid that media is mounted with is the Right Thing (or setting a gid and a umask that allows group read/write, if multiple users should be given access; the "other write" bit should _never_ be set without the +t bit also being active). – Charles Duffy May 10 '22 at 19:32
  • I guess that dodgy umask value _might_ be acceptable if the mountpoint is only accessible to the trusted users. But that's more brittle than a defence in depth. – Toby Speight May 11 '22 at 16:42