Solved Mounting ext4 USB drive to /mnt. How to fix the dermission denied error?

Hello,
This is the ext4 drive:
Code:
Geom name: da0
Providers:
1. Name: da0
   Mediasize: 4037017600 (3.8G)
   Sectorsize: 512
   Mode: r1w0e0
   descr: Generic Flash Disk
   lunname: ALCOR   ALCOR
   lunid: 200049454505080f
   ident: A74100B4
   rotationrate: unknown
   fwsectors: 63
   fwheads: 255

And this command should mount the device read-only:

Code:
$ mount -r -t ext2fs /dev/da0p1 /mnt

However, when I access the /mnt folder with a regular user, I get this error:

Code:
$ cd /mnt
cd: /mnt: Permission denied

I can list the contents of the folder with root permissions, though:

Code:
doas ls -l  /mnt
total 76
drwx------  5 1000 1000   4096 Jan 18  2024 file1
-rw-r--r--  1 1000 1000    368 Jan 18  2024 file2
-rw-r--r--  1 1000 1000   8260 Aug 21  2023 file3

Here are my configurations:

/etc/sysctl.conf:

Code:
# Allow regular users to mount
vfs.usermount=1

/etc/devfs.conf

Code:
own da0 root:operator
perm da0 0660

/etc/devfs.rules

Code:
[system=10]
add path 'usb/*' mode 0660 group operator
add path 'da*' mode 0660 group operator

/etc/rc.conf:
Code:
devfs_system_ruleset="system"

Any idea what could be preventing the regular user from accessing the /mnt folder after mounting?
 
Only the user with numerical id 1000 can access the root directory on that disk.

You need to either:
- chown -R the whole disk
- or create a user with id 1000
 
Oh, uhm… devfs.conf(5) states:​
[…] The devfs.conf file provides an easy way to set ownership and permissions […] for devices available at boot.

It does not work for devices plugged in and out after the system is up and running, e. g. USB devices. […]​
So: “Have you tried turning it off and on again?” ?​
 
Only the user with numerical id 1000 can access the root directory on that disk.

You need to either:
- chown -R the whole disk
- or create a user with id 1000
Thanks. I learned something new, and you're right, looking at the output of "ls -ld /mnt". Unfortunately, I don't think I can use the chown command because the disk is ext4 and mounted as read-only. Maybe I can chown the drive "chown -R myuser:myuser" on a Linux machine?
 
And this command should mount the device read-only:

Rich (BB code):
$ mount -r -t ext2fs /dev/da0p1 /mnt
I assume the mount command is executed as user, considered the configurations made to grant users permission to mount media devices.

How did you mange to mount as user on /mnt? Normally a user can not mount on a mount point not owned by the user.
Code:
 % ls -ld /mnt
drwxr-xr-x  2 root wheel 2 Jul 16 14:05 /mnt

Have you tried to mount as user on a mount point owned by the the user mounting?
 
Oh, uhm… devfs.conf(5) states:

So: “Have you tried turning it off and on again?” ?​
A devfs.conf is not needed here anyway.

The devices default to file group "operator", the permissions are set by devfs.rules.

Without devfs.rules
Code:
 % ls -l /dev/da*
crw-r-----  1 root operator 0x69 Jul 29 07:27 /dev/da0
crw-r-----  1 root operator 0x6a Jul 29 07:27 /dev/da0p1
 
Code:
$ ls -ld /mnt
drwx------  4 1000 1000 4096 Jan 18  2024 /mnt
A user with uid and gid both 1000 is the default used by debian linux distributions and their derivatives, when you create the first user during installation. Can you put the stick into a linux machine, mount it and then chmod 777 the directory to change the permissions? Then unmount and take it back to your freebsd machine and mount it again. The ls -ld /mnt output should then show "drwxrwxrwx".

Either that or you have to create a user with user id 1000 on freebsd to have permission to read it, using the commands described in this section of the handbook https://www.freebsd.org/doc/handbook/users-synopsis.html. So try this:-

$ adduser -u 1000
and follow the prompts.

Once you have a user with uid of 1000 you should have access to the drive if you log in as that user.
 
A user with uid and gid both 1000 is the default used by debian linux distributions and their derivatives, when you create the first user during installation. Can you put the stick into a linux machine, mount it and then chmod 777 the directory to change the permissions? Then unmount and take it back to your freebsd machine and mount it again. The ls -ld /mnt output should then show "drwxrwxrwx".

Either that or you have to create a user with user id 1000 on freebsd to have permission to read it, using the commands described in this section of the handbook https://www.freebsd.org/doc/handbook/users-synopsis.html. So try this:-

$ adduser -u 1000
and follow the prompts.

Once you have a user with uid of 1000 you should have access to the drive if you log in as that user.
Thank you. What you described is indeed the problem in my case. The USB drive was created on Debian. I'll try to switch to a Linux machine and fix it. I marked this thread solved for now.
 
It is useful to add your user on FreeBSD to a group that has the same numerical id as any groups on foreign file systems that you use.
Then it is simple to change group permission on any mounted (foreign) filesystems so that you can read (and write if needed) there. Just use sudo / doas.
 
Back
Top