1

Really simple problem, I have run the following commands:

sudo mkdir /media/usb
sudo chown -R pi:pi /media/usb
show chmod -R 775 /media/usb

Checked everything and made sure that pi owned the directory, and then ran:

sudo mount /dev/sda1 /media/usb -o uid=pi,gid=pi

The drive is ext4 and if I sudo it works (I can write to it) but I cannot seem to get it to work so pi can write without, because when I run the above the command it will reset all permissions to root.

I also cannot seem to get it to auto mount as pi.

I have eve install ntfs-3g incase that made any effect, but every time only root can write.

Here is the output of mounting:

pi@raspberrypi:/media $ sudo umount usb
pi@raspberrypi:/media $ ls -la
total 16
drwxr-xr-x   4 root root 4096 Sep 21 13:12 .
drwxr-xr-x  22 root root 4096 Jun 27 02:22 ..
drwxr-x---+  4 root root 4096 Sep 21 14:24 pi
drwxrwxr-x   2 pi   pi   4096 Sep 21 13:12 usb
pi@raspberrypi:/media $ sudo mount /dev/sda1 /media/usb -o uid=1000,gid=1000
pi@raspberrypi:/media $ cd usb
pi@raspberrypi:/media/usb $ ls -la
total 36
drwxr-xr-x 6 root root  4096 Sep 21 14:24 .
drwxr-xr-x 4 root root  4096 Sep 21 13:12 ..
drwxr-xr-x 2 root root  4096 Sep 21 14:24 dfgfdh
drwxr-xr-x 4 root root  4096 Sep 21 14:18 f
drwx------ 2 root root 16384 Sep 21 11:45 lost+found
drwxr-xr-x 2 root root  4096 Sep 21 14:23 swedtfr
pi@raspberrypi:/media/usb $ 

With options switched:

pi@raspberrypi:/media $ sudo mount -o uid=1000,gid=1000 /dev/sda1 /media/usb
pi@raspberrypi:/media $ cd usb
pi@raspberrypi:/media/usb $ ls -la
total 36
drwxr-xr-x 6 root root  4096 Sep 21 14:24 .
drwxr-xr-x 4 root root  4096 Sep 21 13:12 ..
drwxr-xr-x 2 root root  4096 Sep 21 14:24 dfgfdh
drwxr-xr-x 4 root root  4096 Sep 21 14:18 f
drwx------ 2 root root 16384 Sep 21 11:45 lost+found
drwxr-xr-x 2 root root  4096 Sep 21 14:23 swedtfr
19
  • I don't think it's useful chown'ing and chmod'ing before the mount. Commented Sep 21, 2018 at 13:20
  • I have seen other guides do it. Since changing the auto mount point to pi user it now will mount as pi user to usb folder
    – Sammaye
    Commented Sep 21, 2018 at 13:29
  • I suspect the reason is that because it's an ext4 (linux) drive you are mounting that you can't just ignore the permissions on the folders and files on the USB drive. Executing chown and chmod on the mountpoint before you mount it won't make the file permission on the drive change when it mounts. You could maybe chown and chmod recursively on the drive after it has been mounted - this will reset the permission on the all files on the drive though - so if you are using it on multiple machines this won't be ideal.
    – Charemer
    Commented Sep 21, 2018 at 15:02
  • @Charemer even . comes under this problem, so it isn't a problem that recursive chown can solve
    – Sammaye
    Commented Sep 21, 2018 at 15:38
  • 1
    Why do you use /media and not /mnt?
    – Fabian
    Commented Sep 21, 2018 at 15:42

1 Answer 1

1

Supposing the uid of pi is 1001, and the gid of pi's group is 201, you'd use

sudo mount  -o uid=1001,gid=201 /dev/sda1 /media/usb

You need to pass the id's, not the names, and the options go before device and mount point.

Let me give you an example:

ghp-amdphIIX4B:/root
# id ghp
UID=1000(ghp) GID=1000(ghp)
ghp-amdphIIX4B:/root
# mount -o uid=1000,gid=1000 /dev/sdc1 /mnt/sdc1
ghp-amdphIIX4B:/root
# ls -al /mnt/sdc1
totaal 9087532
drwxr-xr-x  4 ghp  ghp        8192 jan  1  1970 .
drwxr-xr-x 13 root root       4096 aug 11 16:15 ..
-rwxr-xr-x  1 ghp  ghp          21 jan  1  1980 .cm0013
drwxr-xr-x  3 ghp  ghp        8192 aug 11 16:17 Jennifer
drwxr-xr-x  2 ghp  ghp        8192 jun 11  2017 System Volume Information

One difference, my usb stick contains a vfat.

19
  • I guess you could include your comment on the question in your answer as it seems to be related to the overall procedure.
    – Ghanima
    Commented Sep 21, 2018 at 13:23
  • I may be wrong, but I believe there's no need for the chmod and chown. Hope to hear from the OP. Commented Sep 21, 2018 at 13:26
  • Done that, same result
    – Sammaye
    Commented Sep 21, 2018 at 13:28
  • Can you add the output from "ls -al /media/usb" (after the mount) to your question? Commented Sep 21, 2018 at 13:29
  • 1
    device and dir are "unnamed", and the man page puts the options first. Commented Sep 21, 2018 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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