Thursday, January 24, 2013

How to Auto-Mount an External (Networked) USB Flash Drive

Backing-up your user files onto a different storage device is very important.  Backing them up onto another location on your hard drive works, but if it fails you potentially lose your files.  For that reason it is better to back them up onto another hard drive, CD/DVD, or USB flash drive.

In my case, I elected to use my home router an Asus RT-56U which happens to have two USB ports. Why the home router? Simple - its on 24/7 - so it will always be on.  I installed a 64 GB USB flash drive in one of the USB slots.

Before going further, this advice pertains to Linux, specifically Ubuntu 12.XX.  The mounting of a storage device at boot time in Linux can be accomplished by editing the fstab (Wikipedia). Additional file format specifications here

My initial attempts to auto-mount the USB flash drive failed. In finding out why that failed I discovered that the file format that needed to be used in the fstab file is cifs. Unfortunately, cifs is only occasionally listed as being an available file format for fstab. After figuring that out, things still did not work as expected. After a bit more research it turned out that two Linux utility programs needed to be installed before fstab would accept the cifs file format option.

Please see this Ubuntu  topic: 12.10 cifs shares not mounting after modifying /etc/fstab

The first utility that needs to be installed: sudo apt-get install cifs-utils

The second utility that needs to be installed: sudo apt-get install smbnetfs

After installing these utilities, fstab still did not auto-mount the USB flash drive!! Unbelievable shock. More research once again. A couple of issues remained. One, through trial and error, that the permissible options that are allowed for fstab may not work when using the cifs file system option. For example the "sync" fstab option resulted in failure when the cifs file option was used. Second, realizing that Linux is case sensitive, I played around various capitalization schemes. Finally success, the name of the router needed to be in capital letters.

Working line of code for the fstab file: //RT-N56U/sda1 /media/usbdrive cifs guest,rw,nofail 0 0 

Update 4/25/2013: The upgrade to Ubuntu 13.04 resulted in the code above failing. Revised Code: //RT-N56U/sda1 /media/usbdrive cifs sec=ntlm,guest,rw,nofail 0 0

Thanks to Alan Brown: Xubuntu 13.04 - cifs-utils not working.

The code above is very basic, there may be additional options that could be added. If you know of any cifs compatible options that should be added, please leave a response.

I hope that his post proves useful for auto-mounting a USB flash drive to a networked device. But before following any of the advice above, I would encourage you to do additional research. Good luck.

Addendum (1/29/2013):  The story behind this post, is that I am using sbackup as the back-up program to save my files. sbackup proved to be finicky. It would back-up OK to devices already mounted, but it would periodically fail when backing-up to a device which the program had to mount.  This issue has apparently been resolved now by auto-mounting the USB flash drive at boot-up time.  After a week of back-up testing I have not received an error message.


Addendum (4/28/2014):  I ran across this article under the Ubuntu Community Support Wiki. MountWindowsSharesPermanently. At the time of this posting, the article contains a flag noting that the article requires updating. Nevertheless, it may be a useful resource.

If the post contains any errors or needs other improvements, please let me know.