LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   NVMe disk mounted by user but can't be accessed by user (https://www.linuxquestions.org/questions/linux-hardware-18/nvme-disk-mounted-by-user-but-cant-be-accessed-by-user-4175736376/)

minuzed 04-24-2024 06:37 AM

NVMe disk mounted by user but can't be accessed by user
 
I have an internal NVMe disk and when I mount it using a file manager it mounts to /media/<disk-id> which is fine. The problem is that after mounting the directory is owned by root:root and the permissions are 0700 which means that the user that just mounted the filesystem can't actually access it.

The system is a custom Yocto project using systemd so I suspect there is a udev rule somewhere that controls the mount options or falls back to some default values. The problem was evident after a semi-large update which might have updated systemd, polkit or any other software that is involved in managing the mounting of disks.

Is there a way to monitor what .rules-files are applied when I mount the filesystem? I seems to only affect the internal nvme-disk and not usb-sticks. USB-sticks are mounted (/media/<usb-device>) "correctly", owned by the user:usergroup with 0755 permissions.

EDIT:
After comparing with a different system that also contains an NVMe-disk it seems like it is also mounting it owned by root:root but with 0755 permissions, which at least lets the user read the filesystem. In my case I need the user to be able to test the disk so the user has to be able to write to the disk as well.

EDIT 2:
Manually setting the permissions with 'sudo chmod 666 /media/<disk-id>' works but I would prefer this to be done automatically during mounting. This also has to work on multiple systems with disks of different manufacturers and models, preferrably on all kind of disks no matter if it's a SATA, NVMe etc.

GlennsPref 04-24-2024 09:49 AM

Hi, I have had similar problems in the past and I found that I could add the drive to /etc/fstab and have the drives partition/s mounted automatically at boot using the uuid for the partition or the drive designation, like /dev/nvmexxxxx (/dev/nvme0n1p3 in my case, I'll use that discriptor in this example).

The information you'll need may be found using lsblk, blkid. you may need root access to get one of those to give you a read out.

lsblk
Code:

...
nvme0n1    259:0    0  1.8T  0 disk
├─nvme0n1p1 259:1    0    8M  0 part
├─nvme0n1p2 259:2    0  44.7G  0 part /
├─nvme0n1p3 259:3    0  23.9G  0 part /usr
├─nvme0n1p4 259:4    0  14.4G  0 part [SWAP]
├─nvme0n1p5 259:5    0  10.8G  0 part /tmp
...

blkid
Code:

...
/dev/nvme0n1p5: UUID="c3737cc7-39d2-4106-ada8-bec1b1854c67" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="snipped, not required for this demonstration"
/dev/nvme0n1p3: UUID="1c1068d5-59ae-4294-9e86-614b0db16e95" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="snipped"
/dev/nvme0n1p1: PARTUUID="9c56b000-efdb-4a61-b035-7ce9ba198261"
/dev/nvme0n1p4: UUID="0b2464d0-641c-46f7-a472-ffcee19dc462" TYPE="swap" PARTUUID="snipped"
/dev/nvme0n1p2: UUID="ce6a2394-4d9b-47f2-b000-68ad43fc2a4a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="snipped"
...

note, /dev/nvme0n1p1 is not mounted, but is a system boot partition.

Then you could add the info to fstab like so,
add the lines for the partition. The comment (#) is for your information and is not read by the system.
Code:

# /dev/nvme0n1p3:
UUID=1c1068d5-59ae-4294-9e86-614b0db16e95 /usr            ext4    defaults        0      2

The directory must exist, you could add it to the $USER home directory, not /usr... in this example.

If the directory is in /media/(some-name) you may have to set permissions for it after you mkdir /media/(some-name)
Code:

mkdir /media/(some-name)
chown -hR user:usergroup /media/(some-name)
chmod -R 755 /media/(some-name)

I hope this helps, regards Glenn

minuzed 04-25-2024 12:58 AM

That would be a solution if it wasn't for the fact that I need this to work on multiple different systems with different hardware so I'm not able to use the UUID.

I would prefer it to make the mountpoint (/media/<disk-id>) owned by root and belong to group disk with a mode of 0664. That way I can make the user a member of the disk group and it would have full read/write access.

GlennsPref 04-25-2024 03:57 AM

Sorry for the setting off in the wrong direction. It shows my limited experience.

I thought that the uuid was set when a partition was formatted because the uuid changes when formatted.

I don't have a solution.

I have seen an artical on ArchLinux site, but I haven't investigated it fully as I have only one system with multiple disks.

see this link for the artical...
https://wiki.archlinux.org/title/Per...orld_Wide_Name

I hope you find a solution asap. All the best.

minuzed 04-25-2024 04:21 AM

No worries, I appreciate all suggestions and ideas that might lead me in the direction towards a possible solution. :)

I will check the link and see if it gives me any new ideas. Cheers!

friendlysalmon8827 04-26-2024 09:56 PM

Could the OP please further explain why he/she needs the drive(storage asset) to be available for use on multiple machines/ If this is a hard and fast requirement than I would recommend that the OP highly consider investing in an external m2 sata drive encl user

There are several hardware manufacturers out there that have devices such as the one that I mention in the above shortened paragraph


All times are GMT -5. The time now is 02:09 PM.