RE: Use systemd to mount ANY device

For people (dual-booting with Windows) struggling with file permissions after following this guide, try setting the Options field to include your uid and gid. An example .mount file with this would look like:

[Unit]
Description=Mount MEDIA disk (/data/MEDIA)

[Mount]
What=/dev/disk/by-label/MEDIA
Where=/data/MEDIA
Type=exfat
Options=uid=1000,gid=1001
#TimeoutSec=seconds

[Install]
WantedBy=multi-user.target

Find your uid and gid by running

$ id

Moderator edit: Linked to referenced tutorial

I have several systemd mount units and I do not have it set:

$ systemctl cat mnt-4tb_backup.mount
# /etc/systemd/system/mnt-4tb_backup.mount
[Unit]
Description=Mount Backup disk (/mnt/4tb_backup)

[Mount]
What=/dev/disk/by-uuid/c47c5a52-db30-4aef-bcbc-af35b7b021fd
Where=/mnt/4tb_backup
Type=ext4
Options=defaults,rw
$ systemctl cat mnt-5TB.mount
# /etc/systemd/system/mnt-5TB.mount
[Unit]
Description=Mount 5TB data disk (/mnt/5TB)
Before=graphical.target

[Mount]
What=/dev/disk/by-uuid/953836d8-e355-4c6d-ac1a-0914b8414f50
Where=/mnt/5TB
Type=ext4
Options=defaults,rw
TimeoutSec=3600

[Install]
WantedBy=multi-user.target
# /etc/systemd/system/mnt-5TB.mount
[Unit]
Description=Mount 5TB data disk (/mnt/5TB)
Before=graphical.target

[Mount]
What=/dev/disk/by-uuid/953836d8-e355-4c6d-ac1a-0914b8414f50
Where=/mnt/5TB
Type=ext4
Options=defaults,rw
TimeoutSec=3600

[Install]
WantedBy=multi-user.target

I suspect a permission error is the cause of your problems.

But I start mine at boot, as root, so that might also be a contributing factor.

1 Like

That’s only needed on windows filesystems such as ntfs, exfat, etc. You seem to be using exfat.

If it’s a linux filesystem then you’d change owner or permissions on the mountpoint.

2 Likes

And it’s not strictly necessary, even then, unless maybe defaulting to the ntfs3 kernel module. The former fuse-based ntfs-3g drivers tended to be overly forgiving from too many perspectives.

Your suggestion is a classic xy problem because you have not set the correct permissions for the mount point - so you try with uid and gid - then you think that is a solution which it is not.

Adding uid and gid to options in the tutorial is confusing - what about the - potential - other users on the system?

exFAT is born permissionless, and in the world of Linux NTFS is a permissionless filesystem.

However the mount point e.g. /data/media, is not permissionless as those are located in the Linux file system.

This means - that you need to allow rw access for the mount point and you need to do it before mounting.

Using your example

sudo chmod o+w /data/MEDIA

Then start the unit

2 Likes
sudo chmod o+w /data/MEDIA

Does this need to be run once before starting the mount unit or should it run every time before the unit runs at boot? I would rephrase this as, does the Linux mount point persist with its permissions on reboot?

Regarding the confusion with including uid and gid in the tutorial, would this command be a better option, and would every user need to run this command before mounting? If so, would this command fit in the guide better than my uninformed “solution”? And if so, I request you to add just a tiny blurb about permissions issues to your article.

In my opinion a guide is supposed to be comprehensive, and the nature of computing knowledge is such that a guide can never be complete. I hope I am not stepping on anyone’s toes by sharing what worked for me, even though it might not have been the “right” thing to do.

yes - it does - once set - it retains it’s value in the file system.

It has been there all the time

This implies verifying if the permissions are correct for the usecase.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.