Permanently mounting remote Windows network drives on Linux isn't as easy as it first appears...or is it?


Recently we were challenged to provide the link (pun intended) for a backup project that involved an older (circa 2003) Windows Server implementation (CIFS/SMB/SMB2 network). The plan was to provide containerized, on-demand data retrieval in an existing VM platform. Nightly individual backups were created. After a specified amount of time legacy data was put onto tape and moved offsite. The network already utilized a specific backup software tool that: 1) scans each individual network drive, 2) creates a backup for each and 3) moves backups to individual Ubuntu (desktop) virtual machines. The first two actions already existed. The third did not not.

So off we went to documentation-land. Mount the network locations, pass the credentials, all good. Reboot. Nothing. Manually mount the shares, good. Reboot. Nothing. The Ubuntu wiki was so clear, grrr!

After reviewing various guides (AskUbuntu, ServerFault, etc) we came to the conclusion that a) this specific Windows network wasn't compatible with Linux or b) the documentation was wrong.

Fortunately after some testing in both 32bit and 64bit Ubuntu, we realized the documentation was correct; it was us. We missed the section about /etc/fstab under guest locations! Back to the official Ubuntu wiki: https://wiki.ubuntu.com/MountWindowsSharesPermanently

Man pages per Ubuntu will state persistently mounted network locations required editing of the fstab file by invoking:

sudo nano /etc/fstab

In our haste we ran, "sudo fstab" which created a local file in our own user's home directory, not the global (and existing root location) /etc/fstab file. One can edit this local user fstab file to match the remote locations and manually perform a "sudo mount -a" command to check if the mount works. It will (duh) but root doesn't care and nothing happens when the machine is rebooted.

In our tunnel vision we tried several startup command variations and bash script files with dirty sudo workarounds. Nothing would persist beyond a reboot or cold boot. Crontab-ing the hell out of it wasn't something we wanted either...

A day later and without tunnel vision, we tried again, running the network mount in /etc/fstab. One restart later it persisted and still does, permanently to this day. The project works flawlessly.

So you want your own setup? Lets break it down...

Some pre-reqs:

sudo apt-get install cifs-utils

Step 1: Determine location, which we will call "RootLocation/SomeNetworkFolder" which is the "other drive" on the network.

Step 2:

sudo mkdir /RootLocation/SomeNetworkFolder

Step 3:

sudo nano /etc/fstab

Step 4: the fstab location information (with local domain authentication credentials). The man pages warn against this for security reason but consider if someone has access to your fstab file you already lost the war!

//YourIP/SomeNetworkFolder /RootLocation/someplace cifs username=YourNetworkUsername,password=NetworkPassword,iocharset=utf8,sec=ntlm 0 0


Step 5: manually mount the remote

sudo mount -a

Step 6: reboot machine

Step 7: browse to /RootLocation/SomeNetworkFolder using the root account and your file manager (sudo nautilius, gksu caja, etc).

 

About the Writer
Chris Lessley
Author: Chris Lessley
A server admin, dev ops warrior and website designer since 2002, Chris is a lover of all things Linux and open-source! Each blog topic has been tested by fire in the real world and shared with the hope to help others. Need more help? Hire me! Chris' other interests include fine art and the humanities in the classical tradition and can be found writing for our friends over at gripfastart.works. If you like this content, kindly consider donating to keep this website free to all, without ads.

Comments powered by CComment

Member of The Internet Defense LeagueOpen Source Initiative