You are not logged in.

#1 2025-02-18 19:58:45

Kmartinez501
Member
Registered: 2025-02-18
Posts: 15

[SOLVED] Udev NVME mount rules

Hi,

I have the following system:

                    -`                    kmadmin@arch-rig 
                  .o+`                   ---------------- 
                 `ooo/                   OS: Arch Linux x86_64 
                `+oooo:                  Kernel: 6.13.2-arch1-1 
               `+oooooo:                 Uptime: 16 mins 
               -+oooooo+:                Packages: 868 (pacman) 
             `/:-:++oooo+:               Shell: bash 5.2.37 
            `/++++/+++++++:              Resolution: 3440x1440 
           `/++++++++++++++:             DE: Plasma 6.3.0 
          `/+++ooooooooooooo/`           WM: kwin 
         ./ooosssso++osssssso+`          Theme: Breeze-Dark [GTK2], Breeze [GTK3] 
        .oossssso-````/ossssss+`         Icons: breeze-dark [GTK2/3] 
       -osssssso.      :ssssssso.        Terminal: konsole 
      :osssssss/        osssso+++.       CPU: AMD Ryzen 7 5800X (16) @ 4.851GHz 
     /ossssssss/        +ssssooo/-       GPU: NVIDIA GeForce RTX 3090 
   `/ossssso+/:-        -:/+osssso+-     Memory: 4129MiB / 31996MiB " 

I am having issues assigning my kmadmin user and group to my nvme drives with the following udev rule. The issue is that once mounted under /mnt/ the drives get assigned the user root when that is not what I want.

I have the following Udev rule written out and stored within /etc/udev/rules.d/99-nvme-automount.rules:

ACTION=="add", SUBSYSTEM=="block", KERNEL=="nvme*", ENV{ID_FS_USAGE}=="filesystem", OWNER="kmadmin" , GROUP="kmadmin" , MODE="0660" , RUN{program}+="/usr/bin/systemd-mount --no-block --automount=yes --collect $devnode /mnt/%E{ID_FS_LABEL}"

When I add the rules I run udevadm test $(udevadm info --query=path --name=/dev/nvme1n1p1) 2>&1 and get the following output:

Properties:

DEVPATH=/devices/pci0000:00/0000:00:01.2/0000:02:00.0/0000:03:01.0/0000:04:00.0/nvme/nvme1/nvme1n1/nvme1n1p1
  DEVNAME=/dev/nvme1n1p1
  DEVTYPE=partition
  DISKSEQ=3
  PARTN=1
  PARTUUID=4268e16c-5772-564b-a768-4ce7c525c188
  MAJOR=259
  MINOR=1
  ACTION=add
  SUBSYSTEM=block
  TAGS=:systemd:
  ID_SERIAL_SHORT=S5H9NS1NA20100P
  ID_WWN=eui.0025385a01438adf
  ID_MODEL=Samsung SSD 970 EVO 1TB
  ID_REVISION=2B2QEXE7
  ID_NSID=1
  ID_SERIAL=Samsung_SSD_970_EVO_1TB_S5H9NS1NA20100P_1
  ID_PATH=pci-0000:04:00.0-nvme-1
  ID_PATH_TAG=pci-0000_04_00_0-nvme-1
  ID_PART_TABLE_UUID=28eec78d-56af-bd43-9dfe-199dcb9702dc
  ID_PART_TABLE_TYPE=gpt
  .PART_SUFFIX=-part1
  DEVLINKS=/dev/disk/by-path/pci-0000:04:00.0-nvme-1-part/by-partuuid/4268e16c-5772-564b-a768-4ce7c525c188 /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part/by-label/Games-2 /dev/disk/by-uuid/708a6a59-3895-4b77-98ee-a1e73b34ff2d /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part/by-uuid/708a6a59-3895-4b77-98ee-a1e73b34ff2d /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part/by-partnum/1 /dev/disk/by-id/nvme-Samsung_SSD_970_EVO_1TB_S5H9NS1NA20100P-part1 /dev/disk/by-partuuid/4268e16c-5772-564b-a768-4ce7c525c188 /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part1 /dev/disk/by-id/nvme-eui.0025385a01438adf-part1 /dev/disk/by-diskseq/3-part1 /dev/disk/by-id/nvme-Samsung_SSD_970_EVO_1TB_S5H9NS1NA20100P_1-part1 /dev/disk/by-label/Games-2
  ID_FS_LABEL=Games-2
  ID_FS_LABEL_ENC=Games-2
  ID_FS_UUID=708a6a59-3895-4b77-98ee-a1e73b34ff2d
  ID_FS_UUID_ENC=708a6a59-3895-4b77-98ee-a1e73b34ff2d
  ID_FS_VERSION=1.0
  ID_FS_BLOCKSIZE=4096
  ID_FS_LASTBLOCK=244189696
  ID_FS_SIZE=1000200994816
  ID_FS_TYPE=ext4
  ID_FS_USAGE=filesystem
  ID_PART_ENTRY_SCHEME=gpt
  ID_PART_ENTRY_UUID=4268e16c-5772-564b-a768-4ce7c525c188
  ID_PART_ENTRY_TYPE=0fc63daf-8483-4772-8e79-3d69d8477de4
  ID_PART_ENTRY_NUMBER=1
  ID_PART_ENTRY_OFFSET=2048
  ID_PART_ENTRY_SIZE=1953517568
  ID_PART_ENTRY_DISK=259:0
  UDISKS_AUTO=0
  CURRENT_TAGS=:systemd:
  USEC_INITIALIZED=5328562
  ID_PROCESSING=1
Tags:
  systemd
Device node symlinks: (priority=0)
  /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part/by-partuuid/4268e16c-5772-564b-a768-4ce7c525c188
  /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part/by-label/Games-2
  /dev/disk/by-uuid/708a6a59-3895-4b77-98ee-a1e73b34ff2d
  /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part/by-uuid/708a6a59-3895-4b77-98ee-a1e73b34ff2d
  /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part/by-partnum/1
  /dev/disk/by-id/nvme-Samsung_SSD_970_EVO_1TB_S5H9NS1NA20100P-part1
  /dev/disk/by-partuuid/4268e16c-5772-564b-a768-4ce7c525c188
  /dev/disk/by-path/pci-0000:04:00.0-nvme-1-part1
  /dev/disk/by-id/nvme-eui.0025385a01438adf-part1
  /dev/disk/by-diskseq/3-part1
  /dev/disk/by-id/nvme-Samsung_SSD_970_EVO_1TB_S5H9NS1NA20100P_1-part1
  /dev/disk/by-label/Games-2
Inotify watch:
  enabled
Device node owner:
  kmadmin (uid=1000)
Device node group:
  kmadmin (gid=1000)
Device node permission:
  0660
Queued commands:
  RUN{program} : /usr/bin/systemd-mount --no-block --automount=yes --collect /dev/nvme1n1p1 /mnt/Games-2
Unload kernel module index.
Unloaded link configuration context

Afterwards I run sudo udevadm control --reload-rules && sudo udevadm trigger and reboot my machine. The nvme drives are properly mounted but are not under kmadmin user as such:

ls /mnt/
total 4
drwxr-xr-x 2 root    root       0 Feb 18 14:41 Games
drwxr-xr-x 2 root    root       0 Feb 18 14:41 Games-2
drwxr-xr-x 2 root    root       0 Feb 18 14:41 Games-Windows
drwxr-xr-x 2 kmadmin kmadmin 4096 Feb 18 11:43 steam-nfs
ls /dev/nvme*
brw-rw---- 1 kmadmin kmadmin 259, 1 Feb 18 14:41 /dev/nvme1n1p1
brw-rw---- 1 kmadmin kmadmin 259, 3 Feb 18 14:41 /dev/nvme0n1p1
brw-rw---- 1 root    disk    259, 0 Feb 18 14:41 /dev/nvme1n1
brw-rw---- 1 root    disk    259, 2 Feb 18 14:41 /dev/nvme0n1
brw-rw---- 1 kmadmin kmadmin 259, 6 Feb 18 14:41 /dev/nvme2n1p2
brw-rw---- 1 root    disk    259, 5 Feb 18 14:41 /dev/nvme2n1p1
brw-rw---- 1 root    disk    259, 4 Feb 18 14:41 /dev/nvme2n1
crw------- 1 root    root    237, 2 Feb 18 14:41 /dev/nvme2
crw------- 1 root    root    237, 1 Feb 18 14:41 /dev/nvme1
crw------- 1 root    root    237, 0 Feb 18 14:41 /dev/nvme0

Last edited by Kmartinez501 (2025-02-19 21:28:58)

Offline

#2 2025-02-18 20:18:34

loqs
Member
Registered: 2014-03-06
Posts: 18,877

Re: [SOLVED] Udev NVME mount rules

If the file-system you want to mount is ext4 then the ownership of the block device and mount point will not determine the ownership of files and directories.  That would be determined by the files and directories own ownership attributes. Please use code tags for commands and their outputs.

Offline

#3 2025-02-18 21:04:35

Kmartinez501
Member
Registered: 2025-02-18
Posts: 15

Re: [SOLVED] Udev NVME mount rules

Thanks for the reply, I added code tags as suggested. Apologies as I am new here but will do so going forward.

Offline

#4 2025-02-18 21:12:25

frostschutz
Member
Registered: 2013-11-15
Posts: 1,645

Re: [SOLVED] Udev NVME mount rules

You don't want to set owner, group, mode in udev rule (for the block device). This effectively makes that user root (since they can write a filesystem with root suid binaries on it).

Set owner, group, mode within the filesystem using `chown`, `chmod`, ... Or create filesystems with that owner in the first place (mkfs sometimes has options for this, to not default to root:root owner).

For filesystems that do not follow the owner/group permission concept, you usually have to provide some mount options. systemd-mount tries to implement that with --owner=USER option, not sure which filesystems this works for.

Last edited by frostschutz (2025-02-18 21:35:37)

Offline

#5 2025-02-19 00:43:15

Kmartinez501
Member
Registered: 2025-02-18
Posts: 15

Re: [SOLVED] Udev NVME mount rules

For context my nvme drives were formatted and partitioned by user kmadmin (uid 1000) and all directories/sub-directories were created with that user on a previous linux distro (ubuntu). Since migrating to Arch and learning to use Udev I managed to set up the mounting but the owner and group always showed up as root. Now I can run sudo chown -R kmadmin:kmadmin /mnt/... and these changes take effect but when I reboot and run ls -la /mnt they switch back to root. Now I just noticed something very interesting. After rebooting and running the ls command again it does show as owner root and group root as such:

ls -la /mnt
total 17
drwxr-xr-x  2 root    root       0 Feb 18 19:25 Games-2
drwxr-xr-x  2 root    root       0 Feb 18 19:25 Games-Windows
drwxr-xr-x  2 root    root       0 Feb 18 19:25 Games
drwxrwxrwx  4 kmadmin    kmadmin    6 Feb 18 11:41 steam-nfs
drwxr-xr-x  6 kmadmin kmadmin 4096 Feb 18 01:38 .
drwxr-xr-x 17 root    root    4096 Feb 17 21:00 ..

But when I run for example touch /mnt/Games/test.txt I get the following after running ls -la /mnt

ls -la /mnt
total 21
drwxrwxrwx  6 kmadmin kmadmin 4096 Feb 18 19:33 Games
drwxr-xr-x  2 root    root       0 Feb 18 19:25 Games-2
drwxr-xr-x  2 root    root       0 Feb 18 19:25 Games-Windows
drwxrwxrwx  4 kmadmin    kmadmin    6 Feb 18 11:41 steam-nfs
drwxr-xr-x  6 kmadmin kmadmin 4096 Feb 18 01:38 .
drwxr-xr-x 17 root    root    4096 Feb 17 21:00 ..

Notice how /mnt/Games automatically switched from root to kmadmin being the owner and group. The same will happen if I create a file within Games-2 like so:

touch /mnt/Games-2/test.txt && ls -la /mnt yields:

total 25
drwxrwxrwx  4 kmadmin kmadmin 4096 Feb 18 19:40 Games-2
drwxrwxrwx  6 kmadmin kmadmin 4096 Feb 18 19:38 Games
drwxr-xr-x  2 root    root       0 Feb 18 19:25 Games-Windows
drwxrwxrwx  4 kmadmin    kmadmin    6 Feb 18 11:41 steam-nfs
drwxr-xr-x  6 kmadmin kmadmin 4096 Feb 18 01:38 .
drwxr-xr-x 17 root    root    4096 Feb 17 21:00 ..

It's almost as if ls is not displaying the correct user and group initially unless a command is ran or an operation is done on the mounted drives. Maybe there is something I am not understading as to this behaviour, anybody else experience something similar?

Offline

#6 2025-02-19 00:54:22

loqs
Member
Registered: 2014-03-06
Posts: 18,877

Re: [SOLVED] Udev NVME mount rules

Are all  'Games-2' 'Games' 'Games-Windows' 'steam-nfs' ext4 file-systems?

Offline

#7 2025-02-19 06:20:13

Kmartinez501
Member
Registered: 2025-02-18
Posts: 15

Re: [SOLVED] Udev NVME mount rules

Games & Games-2 are ext4. Games-Windows is NTFS and I don't plan to use this one on my rig, I dual boot with windows 11 on a separate disk. As for steam-nfs I am unsure. It's a network share I have setup with my truenas server and never had issues with it as uid and gid is always set to 1000.

Offline

#8 2025-02-19 08:58:13

frostschutz
Member
Registered: 2013-11-15
Posts: 1,645

Re: [SOLVED] Udev NVME mount rules

Was it mounted before? The mountpoint (when the filesystem is not mounted) would have root:root permission, which will then overridden by filesystem once it's actually mounted.

Normally that would not happen with ls / touch unless you have some automount magic going on which mounts things on demand in the background

(Edit: oh, you do use --automount in your options, so that will be it)

Last edited by frostschutz (2025-02-19 09:00:04)

Offline

#9 2025-02-19 21:25:17

Kmartinez501
Member
Registered: 2025-02-18
Posts: 15

Re: [SOLVED] Udev NVME mount rules

Thanks all for the explanations. I have opted to use fstab to manage internal disks such as my nvme ssd drives. I have opted to use the config below and works flawlessly upon boot and displays the correct owner and group off the get go. It seems udev was mounting when an operation was being performed, such as touch or ls -la.

fstab:

# Static information about the filesystems.
# See fstab(5) for details.

# <file system> <dir> <type> <options> <dump> <pass>
# /dev/sda3
UUID=a8448123-2409-407b-9239-5f153320a2f1       /               ext4            rw,relatime     0 1

# /dev/sda1
UUID=8C7A-A931          /boot           vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2

# /dev/sda2r
UUID=e9371d9e-af0d-45ba-bc4a-ef992dac1058       none            swap            defaults        0 0

# Steam Games NFS
192.168.70.148:/mnt/Steam/games   /mnt/steam-nfs   nfs  _netdev,noauto,x-systemd.automount,x-systemd.mount-timeout=10,timeo=14,x-systemd.idle-timeout=1min 0 0

# nvme0n1p1 Games

UUID=6043ed17-2681-463b-b8e4-6dcd0fab80ff /mnt/Games ext4 rw,noatime,discard,defaults 0 2

# nvme1n1p1 Games-2

UUID=708a6a59-3895-4b77-98ee-a1e73b34ff2d /mnt/Games-2 ext4 rw,noatime,discard,defaults 0 2

# nvme2n1p2 Games-Windows

UUID=58826FEC826FCCD6 /mnt/Games-Windows ntfs3 rw,noatime,defaults 0 2

To display UUID I used the following:

┌─[kmadmin@arch-rig]─(~)
└─[16:22]-(^_^)-[$] lsblk -o NAME,LABEL,UUID,MOUNTPOINT
NAME        LABEL         UUID                                 MOUNTPOINT
sda                                                            
├─sda1                    8C7A-A931                            /boot
├─sda2                    e9371d9e-af0d-45ba-bc4a-ef992dac1058 [SWAP]
└─sda3                    a8448123-2409-407b-9239-5f153320a2f1 /
sdb                                                            
└─sdb1      wd-external   efd4aca5-42db-44e8-b610-6c5b2dcdb537 /run/media/kmadmin/wd-external
nvme1n1                                                        
└─nvme1n1p1 Games-2       708a6a59-3895-4b77-98ee-a1e73b34ff2d /mnt/Games-2
nvme0n1                                                        
└─nvme0n1p1 Games         6043ed17-2681-463b-b8e4-6dcd0fab80ff /mnt/Games
nvme2n1                                                        
├─nvme2n1p1                                                    
└─nvme2n1p2 Games-Windows 58826FEC826FCCD6                     /mnt/Games-Windows

Ownership and permissions upon boot:

┌─[kmadmin@arch-rig]─(~)
└─[16:23]-(^_^)-[$] ls -la /mnt
total 29
drwxrwxrwx  4 kmadmin    kmadmin    6 Feb 19 16:13 steam-nfs
drwxrwxrwx  4 kmadmin kmadmin 4096 Feb 19 13:14 Games-2
drwxr-xr-x  6 kmadmin kmadmin 4096 Feb 19 00:16 .
drwxrwxrwx  6 kmadmin kmadmin 4096 Feb 18 19:38 Games
drwxr-xr-x 17 root    root    4096 Feb 17 21:00 ..
drwxrwxrwx  1 root    root    4096 Jan 28 20:06 Games-Windows

Offline

Board footer

Powered by FluxBB