Skip to content

Beginners Guide to Automounting File Systems With autofs and systemd

Updated 2 min read

Updated: 30 September 2026 · Applies to: autofs 5.1 and systemd automount on AlmaLinux and Rocky Linux 9 and 10, RHEL 9 and 10, Ubuntu 24.04 and 26.04, Debian 13

Automounting mounts a file system only when someone accesses its folder, and unmounts it again after a period of inactivity. This is useful for network shares (NFS, SMB) that are not always needed, or that may not be reachable at boot. There are two ways: the autofs service, which is flexible and supports many shares from one map, and systemd's automount option in /etc/fstab, which needs no extra software. We checked both on AlmaLinux 9 (autofs 5.1.7).

Option 1: autofs

  1. Install it (plus the NFS client tools for NFS shares):
    dnf install autofs nfs-utils          # AlmaLinux, Rocky Linux, RHEL
    apt install autofs nfs-common         # Ubuntu, Debian
  2. Create a master map entry in /etc/auto.master.d/nfs.autofs. It tells autofs to manage /mnt/nfs with the map /etc/auto.nfs and to unmount after 5 minutes without use:
    /mnt/nfs  /etc/auto.nfs  --timeout=300
  3. Create the map /etc/auto.nfs. Each line is a key (the folder name under /mnt/nfs), mount options and the location:
    data     -fstype=nfs4,rw   nfs.example.com:/export/data
    backups  -fstype=nfs4,ro   nfs.example.com:/export/backups
  4. Start autofs and test:
    systemctl enable --now autofs
    ls /mnt/nfs/data
    mount | grep /mnt/nfs
    The share is mounted the moment you access /mnt/nfs/data. Note that ls /mnt/nfs itself may look empty until a share is accessed.

automount -m prints all maps as autofs reads them, which helps to find mistakes. The line +dir:/etc/auto.master.d in /etc/auto.master is what loads your file; it is there by default.

Option 2: systemd automount in /etc/fstab

For one or two shares, add the automount options to a normal /etc/fstab line:

nfs.example.com:/export/data  /mnt/data  nfs4  rw,noauto,x-systemd.automount,x-systemd.idle-timeout=300,_netdev  0 0
systemctl daemon-reload
systemctl restart remote-fs.target
ls /mnt/data

x-systemd.automount creates an automount point, x-systemd.idle-timeout unmounts after 5 minutes without use, and noauto prevents mounting at boot. The boot no longer waits for the share.

Which one to use

  • Few, fixed shares: systemd automount, no extra service.
  • Many shares, home folders for many users, or maps shared through LDAP: autofs.

Official documentation: auto.master manual and systemd.automount manual.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket