Skip to main content

Mount an SMB share.

You nee the helper program installed for either the nfs or cifs file system. For nfs based file system, following utility is required

sudo apt-get install nfs-common

To mount a Cifs file system, install the following utility

sudo apt install cifs-utils

Then mkdir /mnt/folder and :

sudo mount -t cifs //machineNameOrIPadress/folder /mnt/folder -o username=myusername,password=mypassword

You might want to add puid:pgid to make it writable, eg: 998:100

sudo mount -t cifs //machineNameOrIPadress/folder /mnt/folder -o username=myusername,password=mypassword,uid=998,gid=100

Example, where Video is the SMB share physically located at /srv/devdiskbyuuid.../Video

sudo mount -t cifs //orbiter/Video/ /mnt/OrbiterVideo -o username=root,password=omgstrongpassword,uid=998,gid=100

Edit fstab to automounnt after a reboot.

nano /etc/fstab

Add this to fstab - hardcoded credentials option.

//[IPADDRESS]/[SHARENAME] /mnt/[SHARENAME]/ cifs username=[SMBUSER],password=[SMB PASSWORD],iocharset=utf8,noperm,uid=1000,gid=1000 0 0

i.e:

//orbiter/Video /mnt/OrbiterVideo/ cifs username=root,password=password,iocharset=utf8,noperm,uid=998,gid=100 0 0

Here's a breakdown of the options you have specified in the fstab entry:

  • //orbiter/Video: This is the network location of the CIFS share you want to mount.
  • /mnt/OrbiterVideo/: This is the mount point where you want to access the CIFS share.
  • cifs: This is the filesystem type you want to mount. In this case, it is a CIFS share.
  • username=root,password=password: This specifies the username and password you want to use to access the CIFS share. Replace "root" and "password" with your actual username and password.
  • iocharset=utf8: This specifies the character set to use for filename encoding.
  • noperm: This option prevents permission checks on the CIFS share, allowing any user to access it.
  • uid=998,gid=100: This sets the user ID and group ID for the mount point. Replace "998" and "100" with the actual user and group IDs you want to use.
  • 0 0: These are the mount options. The first "0" indicates that the file system should not be backed up by the dump utility. The second "0" indicates that the file system should not be checked by the fsck utility at boot time.

To unmount an SMB share, you can use the umount command followed by the mount point directory. Here's an example:

sudo umount /mnt/folder

To force:

sudo umount -a -t cifs -l

 

I have not done it yet, so I cannot give you a walkthrough, but you should visit the *arr wiki and Ibracorp's site/yt content for ideas and instructions. If you are not using any Windows machines you will probably be better served with NFS protocol for shares, but if you intend to share the folders with Windows machines too, then CIFS/Samba might be a better solution.

You should read about hard links, but you should also read why some suggest avoiding the use of hard links and make your own decision if you wish to do it. Basically, a hard link makes a pointer to a file on the level of a file system. You can have multiple pointers to the same file from various folders without having spent any additional space. It is as if the file was mounted in different folders. The alternative to a hard link is a soft link that functions more like a shortcut, so if you change the location of the file or its name it will get defunct.

To permanently add bind mounts there is an option to add them to fstab list. Because mounts added to the system get unmounted on system reset, so to have them automount you have to add them to the list. The other thing, there is an option for mount to add a credentials file for mounts and to reference the file in the mount command instead of having to write the credentials manually every time you mount some folder.


Make sure to create a directory for the mountpoint on the target server.
mkdir /mnt/[SHARENAME]

Add this to fstab - hardcoded credentials option.

//[IPADDRESS]/[SHARENAME] /mnt/[SHARENAME]/ cifs username=[SMBUSER],password=[SMB PASSWORD],iocharset=utf8,noperm,uid=1000,gid=1000 0 0

OR

//[IPADDRESS]/[SHARENAME] /mnt/[SHARENAME] cifs credentials=/home/[YOURUSER]/.smbcredentials,iocharset=utf8,noperm,uid=1000,gid=1000 0 0

Then store your credentials in home/[YOURUSER]/.smbcredentials like this:

user=[SMBUSER]

password=[SMBPASS]

Secure your credentials using
chmod 0600 ~/.smbcredentials