Mounting external EXT4 with 'user' option

Hi,
I have successfully configured an external EXT4 drive to be used as general network share for my family. My use case is that any family member can use transmission to download then uses ftp or smb to retrieve files from ext hdd. But I run into a problem when configuring transmission.
Transmission web daemon offers no directory write control, download directory can be anything.
Screenshot_20210114_101147
I had hoped this would be no problem if I set 'run as user' in transmission config, but it turns out that only root can write to my external drive and mount does not have the 'user' option, I also tested with 'user' and mount failed.

/dev/sda1 on /mnt/sda1 type ext4 (rw,noexec,noatime,nodiratime,data=ordered)
root@OpenWrt:~# mount --help
BusyBox v1.30.1 () multi-call binary.

Usage: mount [OPTIONS] [-o OPT] DEVICE NODE

Mount a filesystem. Filesystem autodetection requires /proc.

        -a              Mount all filesystems in fstab
        -i              Don't run mount helper
        -r              Read-only mount
        -t FSTYPE[,...] Filesystem type(s)
        -O OPT          Mount only filesystems with option OPT (-a only)
-o OPT:
        loop            Ignored (loop devices are autodetected)
        [a]sync         Writes are [a]synchronous
        [no]atime       Disable/enable updates to inode access times
        [no]diratime    Disable/enable atime updates to directories
        [no]relatime    Disable/enable atime updates relative to modification time
        [no]dev         (Dis)allow use of special device files
        [no]exec        (Dis)allow use of executable files
        [no]suid        (Dis)allow set-user-id-root programs
        [r]shared       Convert [recursively] to a shared subtree
        [r]slave        Convert [recursively] to a slave subtree
        [r]private      Convert [recursively] to a private subtree
        [un]bindable    Make mount point [un]able to be bind mounted
        [r]bind         Bind a file or directory [recursively] to another location
        move            Relocate an existing mount point
        remount         Remount a mounted filesystem, changing flags
        ro              Same as -r

There are filesystem-specific -o flags.

So I have to set transmission user to root, but then it can write anywhere. How can I solve this?

As you've found, mount doesn't work that way. Permission to mount a filesystem is different than permission to access the files contained there. Generally only root can mount a filesystem since the /dev/sdxy psuedofile is owned by root. To control who can access the files, set ownership and/or permission on the mount point (which is an empty directory before the drive mounts). Or one of its subdirectories, this would be saved on the drive itself. Linux uses numbers instead of names to identify users so that is not real portable to another system.

I'd recommend mounting under /tmp instead of /mnt, because then if something goes wrong with the mount and you write files to the mount point, it only clobbers the RAM disk, which is a lot easier to recover from than filling up the internal flash. /mnt is generally used temporarily to mount a drive and copy to or from it.

I think that the UCI based block package can handle this, rather than running mount directly.

I forgot to mention that I've tried to set owner & permission to mounted directory (transmission:transmission, 755, 777...etc.. ), it did not work. Or do I have to set permission to that directory before mounting

The directory containing the files, if it already exists, must have permission for that user. Permission for the mount point conveys to the top of the tree allowing the non-privileged user to write to the root of the filesystem including creating directories there-- neither of which you likely want.

The mount point does require read permission for all users, so that they can navigate through the directories.

1 Like