Mounting Network shares with fstab

Auto Mounting a Network SMB or CIFS Drive

As always, backup your working fstab first:
sudo cp /etc/fstab /etc/fstab.bak

The following is a way to automatically mount a network share without the risk of it blocking you computer from booting. This is useful for non-critical drives such as media or backups. Review the params before saving your fstab file, you may need to adjust some!

In this example we will mount the SMB share photos to the local directory /mnt/photos. Replace with your shared drive and preferred local folder.

  1. Create the directory your drive will mount to. This can be owned by any user: EG. root
    1. sudo mkdir /mnt/photos
  2. Add the mount as a new line to /etc/fstab
    1. //IP_ADDRESS/photos /mnt/photos cifs vers=3.0,nofail,noauto,x-systemd.automount,username=USERNAME,password=PASSWORD,uid=1000,gid=1000,dir_mode=0777,file_mode=0666 0 0
    2. Read the explanation below before continuing to save!
  3. Make sure you didn't make a mistake. Validate your fstab file changes with:
    1. sudo findmnt --verify --verbose
  4. Tell the system to re-load the fstab changes with:
    1. systemctl daemon-reload
    2. Because the example here sets noauto, you cannot mount them with the "mount -a" command
  5. Usually the network shares will mount automatically once you try and access the local directories. Sometimes this takes a few minutes the first time. You can speed this up with the following command:
    1. sudo systemctl restart local-fs.target

Explanation of line #2:

Notes:

You may have a different preference about the noauto param preventing mounting a boot time. If you absolutely need your drive to mount first thing and it should hold up booting until it has mounted, you can remove that option. If you want booting to fail entirely if the drive is not available, you can also remove the nofail param.


Revision #3
Created 10 March 2025 16:59:31 by William
Updated 10 March 2025 17:43:55 by William