Ubuntu - Setup CIFS Auto Mount at Startup


I use shared folders for a number of Docker containers. For example, the shared folder can be on a NAS or a file server. Below I describe how I added the shared folders to my Ubuntu VM. The shared folders are created automatically on every reboot.

Setup with fstab

  1. Install the CIFS Utils:
    sudo apt-get install cifs-utils
    
  2. Create the folder (for example the archive folder within the fileserver) to which you want to point the mount:
    cd /mnt
    sudo mkdir -p fileserver/archive
    
  3. I use the Nano text editor to get to the fstab:
    sudo nano /etc/fstab
    
  4. Add to fstab:
    //fileserver/archive /mnt/fileserver/archive/ cifs vers=3.0,credentials=/home/.smbcred,file_mode=0777,dir_mode=0777,iocharset=utf8,nofail 0 0
    

If necessary, adjust the following:

//fileserver/archive
This is the folder you want to create a mount for

/mnt/fileserver/archive/
This is the directory on the Ubuntu VM (in my case) you want to point the mount to

Exit Nano (CTRL-X) and save the changes.

  1. Put the credentials in a separate file. Do the following:
    cd /home
    sudo nano .smbcred
    
  2. Add to .smbcred:
    username=<user>
    password=<pass>
    

Adjust the following:

username and password
Enter the username and password of the shared folder (on the file server or NAS)

Exit Nano (CTRL-X) and save the changes.

  1. Test if it works with:
    sudo mount -a
    

If everything went well you should now see the shared folder in /mnt


Read other notes

Comments

    No comments found for this note.

    Join the discussion for this note on this ticket. Comments appear on this page instantly.

    Tags


    Notes mentioning this note


    Notes Graph