Mounting Shared Folders to Play Media Files in Kubuntu

June 4, 2008 · Filed Under Linux · 2 Comments 

The world’s most complicated fix for the world’s simplest problem

As a warning, this article is not for people who are afraid to run some commands from a text-based terminal or edit some system files used by Linux. I’ve tried to make things as simple as possible, and you can use the GUI for most of these tasks, but some steps will require you to open a shell and type a few commands by hand. I don’t think there is much risk of hosing your system if you follow the steps carefully- it is more likely that the new changes just won’t work- but if you get too far off track or something goes poorly enough, I can’t be held responsible if it messes up your system. You have been warned.

Anyway, if the intro didn’t scare you off, you’re probably wondering “just how hard could it actually be to play .mp3 and .avi files over a network share?” Well, Kubuntu (or Dolphin to be specific) can open shared folders on PCs running Windows right out of the box, but it can’t seem to open media files without first copying them to the local hard drive. The reason is because shared folders on NTFS hard drives (the file system used for most Windows installations) are not “properly mounted”, which is a fancy way of saying that Linux doesn’t have enough control over them.

I almost uninstalled Linux when I first encountered this problem, because it is so ridiculously complex for such a simple request, but I’m glad I stuck with it because although Windows doesn’t have this particular problem, it has plenty of others. Now, let’s get started!

In case you were wondering, you can access shared folders by going to the System menu (next to the K menu) and selecting “Samba Shares”. Then you should be able to find the PC you are looking for. Although this is useful for some things, it is not useful for playing media, which tend to be large files.

The solution for this, as I mentioned before, is to properly mount your network drives. This involves a little bit of trudging through the command line, and there is probably a better way to solve this problem but after all the searching I did, this is the best I can come up with. There are basically 4 parts to this fix.

  1. Setup a local folder for mounting
  2. Create a credentials file under your root directory (optional, but recommended so your password is not revealed to other users on your PC)
  3. Edit your fstab file to mount the folders from step 1 upon booting into Linux
  4. A “fix for the fix”, because of a known bug when unmounting drives (during shutdown)

Setup a local folder for mounting

Go to the system menu and click any option to open Dolphin. Click on the root shortcut on the left, and then choose the option on the right hand column for “Open as root“. In here, right click and create a new folder named “net” without quotes. It doesn’t really matter what you call it here but you will use it later and it is case sensitive. In any case, open this new folder you just created and create another folder.

I named this new folder after the computer I was connecting to, then created another folder under that with the same name as the shared folder of the machine I’m connecting to. This is because I have a few computers on my network and I wanted it to be like a re-creation of my network tree, but you really just need one folder for each shared folder you want to connect to. For this demonstration, I will make a directory structure of /net/mkd/d, but again, you can call it whatever you want. mkd is the name of my computer, and d is the name of the shared folder on that PC (my D: drive in Windows).

Create a credentials file

To create the credentials file, go back to Dolphin and click on the root shortcut again (from the column on the left). You should still have root access unless you closed the window or opened the wrong Dolphin window, so go to /root in the folder list below. Right click here and create a new text file named “.smbcredentials“. The dot as the first character means it is a hidden file, so you will have to click Alt+. (alt and the period key at the same time) to see it in dolphin. Do this and then open the blank file you just created and add the following two lines:

username=[YOUR_USER_NAME]
password=[YOUR_PASSWORD]

Obviously, replace the parts that are in brackets with your actual username and password that you would use to connect to your network share. This would be your Windows password.

Edit your fstab file

Click on the root shortcut in dolphin again and open the folder named “etc“. In here, scroll down a ways and look for the file named “fstab“. Right click on it and choose Actions -> Edit as root. In this file, scroll down to the very bottom and add a couple of blank lines. Then add the following line:

//[IPADDRESS]/[SHAREDFOLDER]    [MOUNTEDFOLDER]    cifs    credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777    0    0

Again, replace the parts inside the brackets with real information. [IPADDRESS] is the IP address of the machine you are connecting to. You *can* use the computer name however for some reason this causes problems so I reccomend you find the IP address and use that. If you need to find out what the IP address is, go to your windows machine that you are trying to connect to and click on the start menu. Choose “run” and type “cmd” (without quotes) and press enter. When the window pops up type in “ipconfig” to see your ip address.

[SHAREDFOLDER] is just the name of the shared folder you are trying to access, and [MOUNTEDFOLDER] is the directories we created in the first part of this guide, for example, “/net/mkd/d“. Remember that uppercase and lowercase matters here. Also, note that between each field is a tab, though I think any whitespace (tabs or spaces) will do fine. In all, there should be 6 fields: ip address & shared folder name, mounted folder name, file system type (cifs), a long string of different options, 0, and another 0. I’m not sure what the last two are for but they are necessary.

Now when you restart you should have a network drive mounted for the shared directory sitting right on your desktop. Rename this to something meaningful like “d on mkd” and you’re almost done! You can add as many lines as you want to to fstab, and if it can’t find the network share it will simply ignore it. Just make sure to have a different folder in your net folder (or whatever name you gave it) for each network share you are trying to access. Going back to the example I used before, I might have folders for /net/mkd/d, /net/mkd/c, and /net/mediabox/d as different shared folders I’m connecting to.

A Fix for the Fix

Since that was not nearly complicated enough, we get to cover an additional fix for that fix. All of this just to be able to open a media file without copying it to your local hard drive! As you may notice when you restart, Kubuntu will take it’s jolly time to shutdown. It will also show the same cryptic error message for each of your mounted drives, which will usually add about an extra minute or two to the shutdown time for each shared folder you added. If you only mounted one shared folder then maybe this is acceptable, but if you mounted 6 like I did it is absolutely not acceptable.

First, we will need to use a script for unmounting all cifs drives before shutdown (all shared folders). Fortunately, two contributors to the Ubuntu forums came up with a solution for us: Max.durden modified a simpler version of jferrando’s script and posted it on the ubuntu forums here (http://ubuntuforums.org/showthread.php?t=293513). You may need to log in to be able to download the archive. Once you have downloaded it, right-click on it and choose Actions -> Extract to get the script file “mountcifs“.

Next, we have to install it. Open dolphin again if it isn’t already, and click on the root shortcut again. You may as well click on the option on the right for “open as root” now, since everything you do here will need to be done as root. Go into the folder /etc and look for the folder in here named “rc6.d“. Open this and copy and paste the script that you downloaded here.

Now, go to the K menu, choose “system“, and select “Konsole” to open a shell window. type the following commands one by one:

cd /etc/rc6.d
sudo chmod +x mountcifs
sudo ln -s /etc/init.d/mountcifs K02mountcifs

If all went well, you should be all set! Restart your machine and check to make sure that it doesn’t hang during shutdown anymore. If you still have problems with either mounting or unmounting your shared folders, I’m afraid you will have to consult the Ubuntu/Kubuntu forums or google. For me, the script worked fine and I believe this solution is complicated enough as it is.

I now have a shortcut on my desktop to all of the shared folders I regularly access on my Windows machines. Eventually, I will migrate them over to Linux, and hopefully this problem will go away altogether, but for now I can enjoy listening to music over the network on my Linux machine without any problems!

Pseudorant on Twitter’s Micro-Blogging Social Network

May 26, 2008 · Filed Under Blogs · 3 Comments 


Twitter - The Web 2.0 Micro-Blogging Website

Pseudorant is now part of Twitter. For those who are unfamiliar with Twitter, it is a micro-blogging social network website. Micro-Blogging is similar to blogging, but it is much more brief in what is posted. That means that users on Twitter are only able to post short updates of 140 characters or less.

These brief updates are known as “Tweets”, or posts that allow users in your social network to stay informed on what you are up to. The idea started as a way for friends and family to let each other know what was going on in everyone’s lives.

The micro-blogging phenomenon has become so popular on Twitter, that users have formed large networks of people they have never even met, and use the website in ways very similar to a chat room.

Users not only post updates, but shoot comments back and forth through their posts to respond to what other people are doing. (In addition to contacting users directly with PMs.) This way everyone can stay involved in what is going on.

Twitter is another great example of Web 2.0 in action. I was amazed to see the potential of the site. After signing up the other night my OCD got the best of me when setting up my following list. ^o^

So if anyone reading the blog is on Twitter feel free to put a follow on us. (paul@pseudorant.com) I am slowly exploring various social networks out there to understand how they work and to meet some new people.

As always thanks for checking out the site! We definitely appreciate all the support!

ss_blog_claim=555660c3e5f182ceb4fe4f9158f3d75e ss_blog_claim=555660c3e5f182ceb4fe4f9158f3d75e