systemctl – add nfs mountpoint

  • By :
  • Category : Linux
Linux

At home, you can’t make assumptions that your home server (whatever it is a simple laptop, from NFS point of view it is a server) will run all the time and you will just plug and unplug rest of your workstation.

The normal situation is that all your workstation is server/client at the same time.

Usually, I was used to using the autofs software to dynamically mount NFS and CIFS resources in my home. Autofs most time works as it should BUT now another big player came in to, systemd. As systemd do almost everything in Linux system nowadays than why do not use it to mount remote NFS/CIFS resources (well there is several reasons but it is subject for another discussion).

Anyway, configuring systemd to mount remote resources is quite simple.

    1. Update your fstab file with additional option: noauto and x-systemd.automount. My fstab line looks like this:
home1:/data/drawer  /mnt/nfs/home1_drawer  nfs noauto,x-systemd.automount,x-systemd.device-timeout=10,timeo=14,soft,intr,noatime,_netdev 0 0

home2:/data/media   /mnt/nfs/media nfs noauto,x-systemd.automount,x-systemd.device-timeout=10,user,timeo=14,soft,intr,noatime,_netdev,x-systemd.idle-timeout=1min 0 0

 

The importance of individual options:

        • noauto — do not mount share until it is accessed (auto to mount during start)
        • x-systemd.idle-timeout=1min  — unmount NFS share automatically if it is not used (good for laptop)
        • x-systemd.requires=network-online.target — if reboot, shutdown takes too much time; also enable NetworkManager-wait-online.service
        • noatime, nodiratime, noac, nocto — for speed
        • user — user can mount resource; this automatically adds another option, like noexecute
        • timeo — The time in deciseconds (tenths of a second) the NFS client waits for a response before it retries an NFS request (from fstab manual)
        • intr/nointr – ignore in kernel > 2.6.25; behaviour in case of signal to interrupt file operations on mount NFS filesystem
        • soft/hard — NFS behaviour in case the NFS request timeout; soft causing the NFS client to return an error to the application
        • x-systemd.device-timeout=10 — by default timeout for NFS is 90 second; so without this system would wait for resource for that time (especially with option nofail)..
    1. reload systemd daemon: sudo systemctl daemon-reload
    2. step above create new files in /run/systemd/generator directory; files are called like mount point directory with the dash instead of the slash in the middle and “automount” at the end.
    3. you can restart automount (sudo systemctl restart XXX-XXX.automount <- tab should help you in this case)

 

https://www.freedesktop.org/software/systemd/man/systemd.mount.html

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Linux
Nginx configuration for joplin note taking app

Introduction Joplin may not be the most perfect note-taking application, but it is open-source, well-known, has a long release history, works on multiple operating systems, and supports plugins. It’s not perfect, but it’s good enough and highly usable. In case of this type of application, it is important to have …

Linux
podcast

All podcast applications I have tested were quite OK(ish) – but I have always struggled with organizing podcasts, creating playlists, etc. It has always been challenging. Therefore, for me, it is more convenient to download podcasts as MP3s and manage them myself (in VLC, for example). There are many ways to do that, but my favorite …

Linux
jellyfin configuration in lxc container

Jellyfin is extremely useful software providing home streaming system. I am using it since a while for streaming my old ripped DVD, which I love to watch again and again. Jellyfin is opensource, cross platform as a server and as a client, including client for android and iOS. It is …