[root tip] [How To] Use systemd to mount ANY device

Difficulty: ★☆☆☆☆

Disk device recognition

Manjaro uses udev (see Arch Wiki) to load devices at boot time. The loading of devices is arbitrary and therefore you cannot predict which device will be available at a given path.

But static device names do exist and you can assign specific locations to your device and thus ensure e.g. scripts will work as expected.

What to learn

  1. Overview of system mount units
  2. Structure and Content of a mount unit
  3. Mount at boot (immediate mount)
  4. Mount on demand (mount on first access)
  5. Permissions
  6. Conclusion

1. What is systemd mount units

The systemd manual has the following somewhat contradicting statement

Mount units may either be configured via unit files, or via /etc/fstab (see fstab(5) for details). Mounts listed in /etc/fstab will be converted into native units dynamically at boot and when the configuration of the system manager is reloaded. In general, configuring mount points through /etc/fstab is the preferred approach. See systemd-fstab-generator(8) for details about the conversion.- system.d.mount.5.html#FSTAB (Emphasized by me)


As mounts listed in fstab will be converted into native units dynamically at boot - logically we create the units ahead so the system don’t have to bother with converting fstab - the contradiction in above statement is fstab is the preferred approach.

What? Why would it be preferable to use a configuration which must be parsed and converted when you can create native units?

I recommend mount units because

  • They are easy to create
  • They provide clear logic of
    • What
    • Where
    • When
    • Why
    • How
  • Simple auto mount defines

Auto mounting a device using systemd is a simple secure approach. For one - you don’t have to edit your fstab - the slightest error in fstab can render your system unbootable.

This article will use an USB device which may or may not be available at boot time and when you plug it you want it to be mounted on a special path - it could be dedicated backup disk.

The basics of this guide can also be used to mount any extra devices available in your system, or remote shares e.g. WEBDAV, SMB, FTP and NFS. You can find link to a topic containing sample mount units at the end of this article.

2. Structure and Content of a mount unit

There is no rules as to where you can mount the device. Just remember a few things

  • Structure
  • Recognizable
  • Dont’t use /home your mount may not mount at all
  • Don’t use /run is a volatile structure recreated at boot
  • Don’t use /mnt it’s primary use is temporary mount

By structure I mean organizing a directory tree - I usually recommend create a data folder on root and populate the tree with your devices and locations like below.

By recognizable I mean naming your mount point with a logical description of the content - but don’t use dashes anywhere in the mount point - see explanation below. If you really need a double word in your data tree - use a low dash ( _ ). You should also avoid local accented characters (e.g. danish æ ø å Æ Ø Å)

Immediate branches are your devices - and network share mounts in a branch named for the type of fileservice e.g. NFS and SMB.

Sample tree
➜  ~ tree /data -L 2
├── backup
├── build
├── nfs
│   ├── data
│   ├── music
│   ├── photo
│   ├── video
│   └── web
├── private
├── projects
├── smb
│   └── web
└── virtualbox

Naming the mount units uses a mandatory convention.

Lets say you have a disk for backup and the disk mounts to /data/backup then the filename becomes.

  • data-backup.mount

Note: Make sure the filename corresponds to the mountpoint you want to use. E.g. the unit name data-backup.mount can only be used if are going to mount the share under /data/backup. Otherwise the following error might occur: systemd[1]: data-backup.mount: Where= setting does not match unit name. Refusing..

:exclamation: Dashes in the file name represents the directory separator - so don’t use dashes anywhere in the mount point.

Create a file as root

$ sudo touch /etc/systemd/system/data-backup.mount

Open the file with your favorite CLI editor or a gvfs compliant editor (xed or gedit)

$ xed admin:/etc/systemd/system/data-backup.mount


Insert the following template into the file - and modify the description - continuing our backup disk example

Description=Mount Backup disk (/data/backup)




The section [Mount] is the same data as you see in your fstab - except the What which must the full path to the device. The nature of systemd makes it impossible to rely on the traditional path /dev/sda1 - luckily there is other options

  • /dev/disk/by-uuid/
  • /dev/disk/by-label/


To get the device uuid you can use lsblk command and the -no UUID or -no LABEL to retrieve the identification you need for the mount. (substitute sdy1 with your actual device and partition). If you choose to use LABEL you must ensure you have different labels for all filesystems.

$ lsblk -no UUID /dev/sdy1

Then insert the UUID into the file



Next type in the path where you want the device mounted. If the path do not exist it will be created.

:information_source: default permissions is 755 owned by root

If your actual device is an existing device and the owner:group UID:GID do not match your device will be mounted read-only.


Caveat using dashes in a folder-name

:exclamation: Comment by @FadeMind
Don’t use a dash - in your path because a dash refer to a new branch on the folder tree and this will break the naming of the mount/automount file

  • Invalid /data/home-backup
  • Valid /data/home_backup
  • Valid /data/home\x2dbackup

To get the correct name for your mount/automount filename when you use dashes in your folder-naming

$ systemd-escape -p --suffix=mount "/data/home-backup"


The Type is optional for disk devices - but from the viewpoint - the more information we provide - less work for the system.

You can retrieve the file system the same way as the UUID.

$ lsblk -no FSTYPE /dev/sdy1

Other types like NFS, SMB and FTP requires Type to be set.


The Options is optional for disk devices.

As with fstab it takes a comma separated list of options for the filesystem mounted.

Other types like NFS, SMB and FTP requires Options to be set.


Save the file

3. Mount on boot

This works just like your fstab - if the device is not available - the system will use the default 90 seconds for the device to be available. The behavior can be changed by setting TimeoutSec= to a value matching the device actual mount time or use an additional automount unit.

First reload the systemd daemon

$ sudo systemctl daemon-reload

Note the state of the mount

$ systemctl show -p ActiveState -p SubState --value data-backup.mount

Mount the device

$ sudo systemctl start data-backup.mount

Now you can verify the service

$ systemctl show -p ActiveState -p SubState --value data-backup.mount

Note that the folder was created by systemd - list the content of the mount
:information_source: note permissions changed to partition content

$ ls -la /data/backup

If the device is an internal device always available you can enable the mount and your device will be mounted during boot.

sudo systemctl enable data-backup.mount

If - on the other hand - this is an USB device - which is not available at boot time - do not enable the the mount unit but proceed to create an .automount unit for your USB device.

The same rule applies to any remote file system such as SMB, NFS, FTP, WEBDAV, SSH and some which has not yet been invented.

4. Mount on demand

An automount unit is a special unit which takes care of activating the corresponding mount unit when the mount path is accessed. The difference for mount and automount is when it is mounted.

To demonstrate the automount - first unmount the data-mount

$ sudo systemctl stop data-backup.mount

Verify the content of the mount point - it should now be empty.

$ ls -la /data/backup

Now we proceed to create an automount for the mount. Create a file - it must be named using the same rule as the mount but with the extension of .automount

$ sudo touch /etc/systemd/system/data-backup.automount

The automount service will fail if the device path is mounted - only ever enable one - either .mount or .automount.

Automount define

Edit the file and insert the following content - expanding our backup disk example - and save it.

Description=Automount backup partition



Test automount

Now enable and start the automount for data-backup

$ sudo systemctl enable --now data-backup.automount

You know you unmounted the device - don’t mount it - just access the /data/backup folder from terminal or a file manager - you will find systemd mounts it behind the scenes.

5. Check permissions

If this is a newly formatted device or a reused device - it is wise to check the permissions. If you get issues with the device being mounted read-only - depending on filesystem - it may be due to the permissions stored on the device.

If the device is using a Linux file system you can change permissions when it is mounted. To change the permissions on your games partition mounted at /data/games

sudo chmod ugo+rw /data/games -R

If your device is a shared device dual booting Windows and Linux and formatted using NTFS and it mounts read-only - reboot your system into Windows and disable features like Fastboot, hibernation, sleep and hybrid sleep as these will taint the filesystem and cause Linux to mount it read-only.

6. Conclusion

This approach is a safer way than editing your fstab. Worst case the device is not mounted - if you make a mistake in fstab - the system breaks.

You can mount all kind of devices - NFS, SMB, FTP, WEBDAV, SFTP, SSH - using this recipe. Sample files for different kind of mounts can be found in this topic.

Crosspost nix.dk

How can I change automount pont /run/media/user to /mnt?
What am I doing wrong when I set up SMB or FTP automount for /etc/fstab?
Where and how can I mount HDD?
Help to setup 2nd HDD as Storage
Mount point Too many levels of symbolic links
Mount new partition for media files
I want to Remove Windows 10 without re-installing Manjaro
How to rename the external HDD from its UUID to an intelligible name?
Shortcut error Manjaro xfce on laptop
How do I get rid of Read Only on all my partitions (even on newly formatted seperate hard drive)
I don't see an option to mount 2 of my hard drives
Odd Issue With Samba Cifs Auto-Mount
Festplatte Schreibschutz entfernen
2nd HDD Not Mounting on Startup
Why is second hd auto mounting and by what mechanism
Partition that I use for data won't automatically mount after reboot
Cannot delete or modify any files in my other partitions
After creating a link to a folder, folders' content is empty
Binding a drive that is mounted to /run on boot
Gnome - Unable to mount my NAS shares
Since Nibia Update - Unable to put hard drives in the correct order
Shares not mounting through fstab after update 01-01-2021
Sshfs share sometimes not mounted
Path to NAS / network shared folders from /
Adding more than 1 drive in smb share
How to make permanent links and shortcuts to Windows partition
Stop Job Is Running for Plex Media Server
Multiple folder on run media user
Thunar hanging - Synology NAS
Drive showing only lost+found directory
Very new to Manjaro. Need help with text and HDD issues
NFS4: Couldn't follow remote path
Unable to locate Local disk D drive
Directory structure question
When I open a folder using vscode in KDE, I cannot find the remote location
Zyxel nsa320s access
Easiest way to swap homedrive?
Probleme mit Nautilus und Netzwerkerkennung ( WSD)
How to run Windows partitions automatically when booting my computer
Dolphin cannot write to second internal drive
Help! research problems, How to overwrite old with a fresh install + HDD is not under /etc/fstab
Manjaro refuses to boot unless a specific drive is removed from fstab
Auto Mount NTFS partition
Automouting nfs using systemd - dolphin is erratic
External optical disk drive (CD/DVD) not showing in Dolphin file manager (doesn't work with different USB ports)
Manjaro not committing file system changes until the (external) drive has been ejected
How do I give read/write/execute permission to myself for newly partitioned SSD and Harddrives?
How do I give read/write/execute permission to myself for newly partitioned SSD and Harddrives?
Mounting drives and ownership
Troubleshooting mount unit naming
SSD and HDD mount after manjaro install
Unable to boot because of fstab
Fix filesystem on unformatted drive /dev/sg2
Making a seccondary ssd usable
Auto mount Windows partition on startup
Can't log in into KDE after logging out. (I cannot log in twice)
Copy to smb share slow
How do you get to a libreoffice file in chroot/LiveISO?
I am dual booting windows and linux and all my windows ntfs partitions are read only
Can I mount a device accessible for all users?
Can systemd mount a share for a specific user and show it in the filemanager?
Ntfs-3g don't mount external USB3.0 disk with ntfs partitions
Help me put to use my 1TB SSD
Mount WD MyCloud volume in Dolphin
Mounting Network Shares
How to run a script on system startup
Open file from another partition in qpdfview
Problem mounting network drive
Deja Dup unmounting backup drive
Mounting CIFS/SMB share with fstab? Pi fails to mount share and crashes into emergency mode at boot
Password required to use partition
Where is the automount option for hard drives on gnome
Auto mount usb key encrypted
Cifs - mount error(13): Permission denied
QEMU/KVM + Windows - Making USB redirect persistent (permanent)
Udev, cannot create name for USB drive
Automount HD at startup
Automount Partitions
Setting up a SD card as /home(?)
Post-cloning advise required... I think the boot is pointing to the original disk
Cannot paste files from USB to mounted drive
Browse local network issues
Shared SSD partition between Windows 10 and Manjaro is set to Read-Only
Mounting samba shares on boot fails half the time
Family shared desktop: how to properly create a family group and auto mount partition for every family member?
User groups not lining up
Chown user:group directory not changing user or group (automonted partition)
Udev, cannot create name for USB drive
Welcome and introduce yourself - 2022
Troubleshooting mount unit naming
Troubleshooting mount unit naming
NTFS-3G mount / unexplained change
How do i change name of my hard drive and give access to all users?
Mounting my enterprise dropbox that has spaces in the dir name as ~/Dropbox in fstab works, but then it uses double the diskspace! Can you avoid this?
How to automatically mount network shares?
Getting permissions right with systemd mount unit
Unable to mount freshly encrypted usb stick partition
Where do I start - it all seems difficult to learn
Auto-mount drives at boot
Dolphin filemanager hangs out
Why can't I automount NFS directory using systemd units?
Mount partition using systemd
Steam game doesn't work
How to change /home partition after installation?
Auto-mount drives at boot
How to process files from a different computer?
Most Apps I Open Do Not Display All Drives On My PC
[HowTo] Use multiple partitions / drives in your Manjaro installation
Mount options for external SSD used for backups (BackinTime and general data storage)
How to automount at boot
Every Time I Boot Into Manjaro A Popup Is Shown To Enter Password For Encrypted Internal 4TB HDD?
Mount only if source is available
Dolphin cannot save to Samba drive
Need help automounting NAS storage?
System read-only
Choice home at boot
I'm pretty dumb so I came here to get help modify /etc/fstab so that my 2nd hard drive works
Jellyfin can't detect external drives and files in home directory
[root tip] [How To] Mount partition using fstab
Issues with SystemD Automount for NFS Shares
[root tip] [How To] systemd mount unit samples
Issues with SystemD Automount for NFS Shares
[root tip] [How To] Basic Samba Setup and Troubleshooting
Instructions to permanently mount network drive
Messed up new Manjaro xfce installation
Dolphin SFTP issues on a certain server
Trying to modify /etc/fstab getting save error
Cant share a folder
Fstab custom drive throws me into emergency mode!
How can I switch /home partition?
Mount.nfs: remote share not in 'host:dir' format - how to resolve?
My drive won't show up
Long pause when doing a reboot
Scribus Open file dialogue doesn't show network / online account drives
/etc/fstab is empty and ERROR: device ´UUID=<longnumber>´ not found
Apple timecapsule 2T - manjaro
Fstab cannot mount ntfs drives
Automount systemd unit needs a restart to work on every boot
Want to move Steamlibrary from HDD to my SSD
Unable to write to non-system drives
Multiple Issues when installing manjaro with KDE Plasma as Dual Boot
After installation I can only see one partition and its a read only
How to open and write Libreoffice Writer files to a NAS using Samba
Permission issues mounting SMB share
Checking fstab settings AND Automount options?
System will not mount NAS at boot, although the mount does work fine after its finished booting
Programmers Partitioning Scheme
Need Help With Two Issues On Boot Of Manjaro KDE
Timeout when sshfs mount not reached
[root tip] [How To] Basic Samba Setup and Troubleshooting
Dolphin - Problems with mounting netwrork shares and reseting it's credentials
Automount second internal hdd
Can't connect to samba after update; Service is running (2022-08-13++)
Bizarre umount issue
Install manjaro plasma and use other hard disk to files
I can not access my second drive (HDD)
"Folder empty" on Samba-accessed NAS after a file operation
Differences in permanently(FSTAB) auto mounting NFS share (client) Gnome vs. XFCE
Hard disk is not mounted proberly after booting
External drives/partitions won't stay mounted
System not mounting network drive on boot
Slow boot time/restart
Autofs won't work on new install
Selecting a mounted NAS on Dolphin causing high network activity
Autofs won't work on new install
Cifs: "mount error(20): Not a directory" while mounting
Best way for live mapping a NAS shared folder
Externes USB Laufwerk mounten als wäre es eine interne HDD
Wallpaper turning black
How can I add an additional partition to Manjaro?
How to add additional drives as pernament storage? Manjaro GNOME (SSDs)
Manjaro in VirtualBox- how to mount the shared folder with host without using root
Easiest way to swap homedrive?
Cifs requires sudo mount -a after restart
Steam removes my standard downloads folder on restart
How to add additional drives as pernament storage? Manjaro GNOME (SSDs)
Can't write on harddrive
VLC / SMB - Watching videos via network-computer
Making a drive writable
Multiple fstab files in /etc/fstab.d
Having difficulty mounting an SMB share correctly
SMB Mounts Fail
Broke my system with fstab

A post was merged into an existing topic: How do I mount a share with a space in the name

Is it also able to mount smb Shares of a Synology NAS?

Systemd mounts anything - provided the right information and options.

I have several shares on Synology NAS - using mount and automount. Entering the mount point either by cli or gui mounts within seconds.

1 Like

getting this.:

● nas-home.mount - NAS SMB home share
     Loaded: bad-setting (Reason: Unit nas-home.mount has a bad unit file setting.)
     Active: inactive (dead)
      Where: /data/smb/home
       What: //<IP>/home/

Okt 13 19:52:00 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:53:42 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:53:45 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:54:34 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:54:36 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:54:38 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:55:06 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:55:09 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:55:11 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.
Okt 13 19:56:16 Workstation systemd[1]: nas-home.mount: Where= setting doesn't match unit name. Refusing.

Read the message - then read the rules on unit naming - also see the sample units

Even sshfs ? I am really looking forward to test this.

yup - also sshfs


wow this is great. :slightly_smiling_face:

Any idea if automount works under “–user” as well? Or it’s strictly privilege thing.

I’ve read something on fedora wiki that it might be set up under root which is sad as I can use Fuse to mount things without needing to modify the system.

I remember trying - but could not get it to work - probably my own fault - but not investigated further as my use is satisfied by the system mount.

You might add that you can generate the correct unit name using systemd-escape(1):

To generate the mount unit for a path:

$ systemd-escape -p --suffix=mount “/tmp/waldi/foobar/”

Already mentioned

Ahh i didn’t notice, because it was hidden by this:

Maybe put the mentioning of it under the portion i quoted :arrow_heading_up: in the open :wink:

How about, once a device is set up (using gnome-disks or fstab) we simply

  1. copy the file from /run/systemd/generator to /etc/systemd/system/
  2. Hash # it from fstab, save/exit fstab
  3. systemd to enable?

I like easy shortcuts. Obviously the automatically generated file isn’t quite up to scratch… tidying up and editing now.

Initially, systemd didn’t like my file and politely declined. However, after a tidy up it seems to be fine - after a reboot, then deleting the hashed lines from fstab it’s automagic.

Thanks for the guide.

However, I did keep the /mnt/T3 and /mnt/T4 paths (as there’d be a few issues raised by changing the path) and I’m curious if there’s really any reason or benefit to create a new folder (/sata for example) to mount my whirly disks?

Well - it is not a problem - as long as you know what you are doing - and you appear to do so.

My recommendation on folder structure is what it is - a recommendation from a long time sysadmin - with autistic treats :slight_smile:.

You know the saying - only a genius can make reason out of chaos - just look at my desk - what a mess.

1 Like

Lolz but it’s a nice guide - no problems after setting up my systemd mounts, thanks for that :wink:

1 Like

2 posts were split to a new topic: Systemd mount unit error

6 posts were split to a new topic: Troubleshooting mount unit naming

A post was split to a new topic: Where do I start - it all seems difficult to learn