2

I have Ubuntu 16.04 LTS installed (with MATE DE if this matters).

After the insertion of USB-flash it is usually got auto-mounted to the /media/username/VOLUMEID and the mount shows the following information for it:

/dev/sdc1 on /media/username/VOLUMEID type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)

Note: this question is logical continuation of my other question.

How and where can I change the exact values of the default fmask and dmask mount options?

I can read man mount and use mount -o fmask=...,dmask=... but really I'm asking about configuration of the default values for them.

N0rbert
  • 99,918

2 Answers2

0

I have just solved the same problem on my Debian 10.5 with Mate DE (but I don't know if this is relevant).

While in /etc/fstab was listed the usb device without uid and gid option, udisks2 mount the usb key in /media/usb0 as root. User can read and umount disk but not write on it. This was my fstab:

/dev/sdb1       /media/usb0     auto    rw,user,noauto  0       0

Commenting out this row done the job.
Now my USB disk is mounted in /media/$USER/samething with the correct permissions.

I hope this help you and all the other posted similar questions (I found a lot of unresolved questions about this.

Antonio
  • 158
0

Had a similar question for Ubuntu 22.04.2 LTS and exfat flash drives, which also mounts with fmask=0022,dmask=0022 by default which results in all files being marked as executable by default.

Automounting of external flash drives are handled by UDisks daemon - this is noticeable by uhelper=udisks2 meta-option listed in mount output:

$ mount | grep /dev/sde1
/dev/sde1 on /media/user/Sandisk128 type exfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,iocharset=utf8,errors=remount-ro,uhelper=udisks2)

UDisks can be configured to pass specific mount options for different filesystem types/different devices. Configuration example can be found in /etc/udisks2/mount_options.conf.example, and based on it I created:

$ cat /etc/udisks2/mount_options.conf
[defaults]
exfat_defaults=uid=$UID,gid=$GID,iocharset=utf8,errors=remount-ro,fmask=0133,dmask=0022
exfat_allow=uid=$UID,gid=$GID,dmask,errors,fmask,iocharset,namecase,umask

Essentially adding fmask=0133,dmask=0022 to exfat_defaults (others *_defaults/*_allow should be used for other filesystem types, e.g. vfat_defaults/vfat_allow for vfat, see /etc/udisks2/mount_options.conf.example for examples).

Now restarting the UDisks with sudo systemctl restart udisks and re-pluggin the flash drive I see in logs:

Apr 13 11:26:55 host udisksd[9586]: Using overridden mount options: uid=$UID,gid=$GID,iocharset=utf8,errors=remount-ro,fmask=0133,dmask=0022

And applied settings in the mount output:

$ findmnt /media/user/Sandisk128
TARGET              SOURCE  FSTYPE OPTIONS
/media/user/Sandisk128 /dev/sde1 exfat  rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0133,dmask=0022,iocharset=utf8,errors=remount-ro

Answering the question where those defaults are coming from is a bit more interesting.

Mounting exfat disk without any options we can trace that no options are passed to the kernel:

# strace -e mount -f mount -t exfat /dev/sde1 /mnt/point/
mount("/dev/sde1", "/mnt/point", "exfat", 0, NULL) = 0
+++ exited with 0 +++

but fmask=0022,dmask=0022 are still present in the options list:

$ findmnt /mnt/point
TARGET  SOURCE  FSTYPE OPTIONS
/mnt/point /dev/sde1 exfat  rw,relatime,fmask=0022,dmask=0022,iocharset=utf8,errors=remount-ro

Looking through the kernel sources we can see that fmask=...,dmask=... are appended in exfat_show_options() based on opts->fs_fmask, opts->fs_dmask values:

static int exfat_show_options(struct seq_file *m, struct dentry *root)
{
    ...
    seq_printf(m, ",fmask=%04o,dmask=%04o", opts->fs_fmask, opts->fs_dmask);

fs_fmask, fs_dmask are set in exfat_parse_param() if the relevant mount option is provided (not our case), and otherwise initialized from the current task umask in exfat_init_fs_context():

static int exfat_init_fs_context(struct fs_context *fc)
{
    ...
    sbi->options.fs_fmask = current->fs->umask;
    sbi->options.fs_dmask = current->fs->umask;

We can confirm that Udisks is running with the umask of 0022:

$ grep '^Umask:' "/proc/$(pgrep udisksd)/status"
Umask:  0022

And manually confirm that changing umask of the process will change the used fmask/dmask, e.g. with umask 0133:

# umask 0133
# umask -S
u=rw,g=r,o=r
# strace -e mount -f mount -t exfat /dev/sde1 /mnt/point/
mount("/dev/sde1", "/mnt/point", "exfat", 0, NULL) = 0
+++ exited with 0 +++
# findmnt /mnt/point
TARGET  SOURCE  FSTYPE OPTIONS
/mnt/point /dev/sde1 exfat  rw,relatime,fmask=0133,dmask=0133,iocharset=utf8,errors=remount-ro
# ls -l /mnt/point/README.txt
-rw-r--r-- 1 root root 72 Apr 12 11:40 /mnt/point/README.txt
# mkdir /mnt/point/directory
# ls -ld /mnt/point/directory/
drw-r--r-- 2 root root 131072 Apr 13 11:19 /mnt/point/directory/
# umount /mnt/point

I.e. default fmask/dmask values for exfat filesystem are coming from the process umask (the same for vfat filesystems). Since typically we want to have different fmask/dmask (to make directories executable, and regular field non-executable), the preferred method to customize fmask/dmask is to explicitly add those options in the UDisks daemon configuration as suggested above.

rutsky
  • 428