Nov
30
Sharing the Same Files Between Two PC’s
November 30, 2009 | By: UbuntuLinuxHelp | 1 Comment
Posted in How to...
Here's the scenario:
Box #1: Ubuntu Linux 8.04LTS
Box #2: Windows XP SP3
Box #3: Remote storage (NAS) DLink DNS-321
Linux and Windows both need read and write access to the remote files stored on the DNS-321 backup unit. This way there is only one set of files and directories to manage, that both computers will share. In other words the data stored on the backup unit (NAS) is common to both computers on the network.
Some time ago, I wrote a post on another blog, Saving Your Data When Disaster Strikes, that dealt with the issues of losing data because there were no backups. In that post I mentioned:
"...I also opted to install a proactive solution and purchased a D-Link DNS-321 network storage unit, to which I added two more hard drives again, and had one mirroring all it’s contents to the other. In the event when one of those drives fails - and eventually they will, the second drive in that unit will be a duplicate of the failed drive..."
At that time the solution was great! The only drawback (in the way I approached it) was having to synchronize files across all computers (over the network) and then backup a copy of those files to the remote storage. I played around with quite a few tools, but ended up just using plain old FTP, to send files back and forth. Needless to say, this resulted in unproductive use of my time.
I don't really know what took me so long, but it finally dawned on me (what was I thinking before!?) that a better use would be to have all common files on the remote server (that's the DNS-321 unit). It's a much more efficient to operate, (saves wasting time with synchronization) using it as a fileserver / backup unit. I should point out, that while my solution does revolve around that Dlink unit (because that's what I bought), this solution can use any type of network storage unit (NAS) or networked server. I should also mention, the NAS has two hard drives in it. I configured those drives to operate as RAID 1. This means that one hard drive will mirror the other one. If one hard drive fails, the data can be rebuilt by using the mirror image of the other one.
First, it's important to ensure the NAS is configured to your needs. This means enabling SMB. Why SMB (Samba) and not NSF? Remember, there's a Windows box on the network and it needs access too. If you intent to use the same NAS I have, log into it and go to the following screen:

Enable SMB and select the account you wish to allow access for. Remember to allow read and write access. In my case that's CHMOD 777
I'm assuming of course, that you've already set up user accounts on your NAS, and have enabled FTP. In the case of the NAS I used, there is no SSH server, as such I had to use FTP to create directories on it (so I could share them later). Via FTP, I created two directories. One called "stock" (to contain all the stock photos) and one called "sites" (to contain all client site files and data). I then shared the directories (via SMB) as "stock" and the other as "sites"; so they will be visible shares on the network.
Windows Access:
To access the shares on WinXP, double click the "My Computer" icon, then on the top navigation, select" Tools" and "Map Network Drive".

In the pop-up that appears, enter the following information (syntax is \\servername\sharename):

Remember to select "Reconnect at logon" then click "Finish". Your new networked drive will appear and you can copy data to it.
Linux Access:
To access the shares on Ubuntu and have them automatically mount at boot time, I did the following.
Installed smbfs:
sudo aptitude install smbfs or apt:smbfs
Still in terminal I created two mount points within the /media directory
sudo mkdir /media/stock && sudo mkdir /media/sites
Because the backup box requires login credentials, I added them as an external file (called .smbcredentials - the "dot" in front of the file name makes it a hidden file).
sudo gedit ~/.smbcredentials
is the command to create the file. (You can use nano or pretty much any plain text editor).
Inside that file I placed the username and password (that I originally created on the NAS). Place only that text in the file. It will look something like this:
username=roger
password =%^GkdA5m6_)c
What I'm posting online is not a real password (just an example), but it's important to note that the .smbcredentials file stores your password in plain text. Therefore, you may want to help prevent non-root users from seeing the password by using the command:
sudo chmod o= ~/.smbcredentials
The above command makes the file visible to root only. If you are not worried about security, then you don't have to take this step. I did use this because I didn't want the less experience Linux users on this network, to try using my password to fix issues and potentially cause even more problems.
Next, I edited the file system table (fstab), which tells Linux what disks are available and how to mount them. The command to edit that file is:
sudo gedit /etc/fstab
Your file will look something like this:
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# /dev/sda1
UUID=2e2d4d1d-c65f-4d84-bcdc-665b7033ba18 / ext3 relatime,errors=remount-ro 0 1
# /dev/sda5
UUID=6993ff17-6e9f-4d55-814a-04ad1dfd6d60 none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0
/dev/scd1 /media/cdrom1 udf,iso9660 user,noauto,exec,utf8 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
/dev/sdb1 /media/sdb-storage ext3 defaults 0 0
At the bottom we need to add the shares we created. Remember that we created the following:
On the NAS a share called "stock" and another called "sites".
On the Ubuntu box a mountpoint at /media/stock and another at /media/sites
I didn't want to add the hostname of the NAS box (nas001.localdomain) to the /etc/hosts file (so that Ubuntu can find the NAS via a hostname), so I mapped the shares directly to the IP address of the backup unit as 192.168.3.10
Finally the following two lines would be added as:
//192.168.3.10/sites /media/sites smbfs credentials=/home/roger/.smbcredentials,uid=roger,gid=users 0 0
//192.168.3.10/stock /media/stock smbfs credentials=/home/roger/.smbcredentials,uid=roger,gid=users 0 0
The first above line stipulates:
Connect to the SMB server at 192.168.3.10 and access the share named "sites". Mount that share in /media/sites and use the .smbcredentials file to provide access to the roger account. Set the owner of the data (uid) to "roger" and the group (gid) to "users".
Hopefully this post will help some of you out there - Let me know! Also, if you have a better way or some tips about this, I'd enjoy hearing from you!
Thanks!
UPDATE: I started getting CIFS VFS errors (during reboot, shut down, etc.) shortly after setting up the above "sharing" connections on a clean install of Ubuntu Jaunty, 9.04. After some research, I found a solution and posted the information at "CIFS VFS Shutdown Error When Using SMBFS".
Related posts:
- Quick Tip – When Linux Won’t Give Your CD Back
- Easily Manage Duplicate Files and Save Storage Space
- CIFS VFS Shutdown Error When Using SMBFS
- How to Install VMware in Linux via Source Files
- Automate Your Web Site Backup!

(1 votes, average: 4.00 out of 5)
[...] Ubuntu Jaunty (9.04) and set up access to (DNS-321) my network shares using smbfs; as in the post "Sharing the Same Files Between Two PC’s". Shortly afterwards, when rebooting, shutting down, etc. I received this error [...]