Mounting SMB to Ubuntu Server on Boot

Recently I’ve setup my custom built NAS server using an refurbished HP EliteDesk 800 Small Form Factor PC. The goal of this was to move my storage out of my primary home server that I had for my Immich instance.

I’ve booted the storage NAS using TrueNAS and created a SMB share to connect to my primary home server.

So for binding my NAS SMB Share to my Ubuntu Server on boot, I had to do following steps.

  1. Install cifs-utils

Run the following command to install cifs-utils in the primary home server.

Terminal
sudo apt-get update
sudo apt-get install cifs-utils
  1. Create a credentials file

In order to mount the SMB Share, we need to create a credentials file and add the username and password of the NAS server. Create the following file under /etc/samba/credentials.

Terminal
# It can be any path.
sudo nano /etc/samba/credentials

And add the following line to the file.

/etc/samba/credentials
username=<NAS_USERNAME>
password=<NAS_PASSWORD>
domain=<NAS_DOMAIN> # Usually it is WORKGROUP
  1. Create a mount point
Terminal
# It can be any path you want the storage media to be mounted to
sudo mkdir -p /mnt/nas
  1. Add the mount point to fstab
Terminal
sudo nano /etc/fstab

And add the following line to the file.

/etc/fstab
# ... previous lines
# Add the following line to the file
//<NAS_IP_ADDRESS>/<SMB_SHARE_NAME> /mnt/nas cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,x-systemd.automount 0 0

Replace <NAS_IP_ADDRESS>/<SMB_SHARE_NAME> with the IP address of your NAS server and the name of the SMB share you created in your NAS server. In my case it was //192.168.0.201/immich-data.

  1. Mount the SMB Share
Terminal
sudo mount -a
  1. Reboot the server

Once the server reboots, the SMB Share should be mounted to the mount point you specified in the fstab file.

Check the mount point by running the following command.

Terminal
df -h

screenshot of the mounted SMB Shares