May
16

Howto: Mount your Android SD card under linux via wifi

This guide will get you from having an Android phone with a Samba sharing app installed (such as the one I currently use: https://market.android.com/details?id=com.funkyfresh.samba) and an Ubuntu (or any generic Linux) machine with Samba installed to being able to mount your SD card via WiFi. We will do this by: setting the computer to use netbios names for IP address resolution, testing the mount with mount.cifs, and then adding a permanent entry to /etc/fstab.

My setup: HTC Inspire 4g, rooted running Cyanomodgen 7; Samba Filesharing on Android app (from marketplace, free, version 110130-market); Ubuntu 11.04 (with samba package installed)

Prerequisites

First, you need a Samba server app for your phone (I’m using https://market.android.com/details?id=com.funkyfresh.samba, which seems to work well enough), then you need to go into your Samba app on the Android and set a netbios name for your phone (e.g. I’m using “bcoop-android”, so replace that with whatever name you set). For security reasons, you also want to set a user (e.g. “bcoop”) and a password required to access the share. If you have the option, you need to give the shared directory a name (on my app the name is fixed as “sdcard”).  You’ll also need to make sure that your computer has a samba client installed (this can be installed in Ubuntu by installing the smbclient package).

Using Netbios for IP address resolution

Secondly, we need to tell the computer to try to perform DNS lookups using netbios names if all else fails. You can tell if you need this step by running the command “ping bcoop-android” (making sure your phone is connected to the same network as the desktop via wireless and that the Samba app on the phone is running). If you receive a “unknown host” error, then the desktop is not able to look up names via netbios, which is a simple fix. Run the command

sudo gedit /etc/nsswitch.conf

and look for the line that starts with hosts:. At the end of this line, add wins. You should end up with the line looking something like:
hosts: files [...] wins

This will tell your machine to use Netbios name lookup if all else fails. You want to make sure to add wins at the end of the string of methods so that it does not check this before other methods. Save the file and close gedit.

Update: After an hour or so, my connection started timing out and I couldn’t remount the share.  I was confused about what was going on, but noticed that when I tried to ping the netbios name I suddenly got a response from a 209.XXX.XXX.XXX IP address, and not from my phone.  Long story short, it turns out that my lovely ISP (Comcast) has a policy of hijacking domain names that don’t exist so that they can redirect browsers to a search page with ads.  A side effect of this is that all DNS resolution requests are answered, regardless of whether they exist or not.  This causes the computer to assume that the request has been answered and not to look at the wins netbios name for a possible IP address.  The solution to this was to put wins just before the dns entry in the hosts line.

You should now be able to run the ping command and have the computer try to ping an IP address (it doesn’t matter if you receive a response or not, we’re just checking to see that the computer can translate the netbios name to the ip address of the phone).

Note: If you’re not able to get this to work, you can still move on, but just use the phone’s IP address instead of netbios name for the server.  It will be necessary to either continually change the IP address to the phone’s IP, tell your router to assign the phone the same IP address always, or to use some other method to ensure that the phone’s IP address remains correct.

Testing things out: Temporarily mounting the phone

To test things out, we need to create a directory to use as a mount point.  Run the command sudo mkdir /media/android to do this (using a different directory if you’d prefer). Now, we want to manually mount the phone in this directory. There are a couple different ways to do this, depending on how you want the file permissions to work.  I’ll list the different commands you can use, and you can see the below section for further discussion about which might be best.  You will need to modify this command with some specifics for your setup, see the section immediately afterwards.

To not allow any other users to access your files (the recommended method)

sudo mount -t cifs //bcoop-android/sdcard/ /media/android  -o user=bcoop,uid=bcoop,gid=bcoop,nounix,file_mode=0770,dir_mode=0770

To avoid using ‘nounix’, but allow others to read (but not write) your files

sudo mount -t cifs //bcoop-android/sdcard/ /media/android  -o user=bcoop,uid=nobody,gid=bcoop

To disable permission checking entirely (anyone can read/write your files)

sudo mount -t cifs //bcoop-android/sdcard/ /media/android  -o user=bcoop,noperm

For all methods

You’ll need to replace some parts of this command with your setup information:

  • //bcoop-android/sdcard should be your phone’s netbios name (or IP address) followed by the share name:  //NETBIOS_NAME/SHARE_NAME
  • /media/android should be your mount point directory
  • user=bcoop should be the user name that you set up on the phone for the Samba share:  user=PHONE_SAMBA_USER
  • uid=bcoop,gid=bcoop should be your computer user’s name and group (these are likely the same on a typical setup): uid=COMPUTER_USER,gid=COMPUTER_GROUP
  • uid=nobody should be the name of a fake user on your computer

After running the command, you’ll need to enter your sudo password, then your password for the phone’s samba share.  If all goes well, you should see no error messages then be able to run

ls /media/android

and see the contents of your phone. In that case, you’re ready to set the share up permanently. If you don’t mind running the mount command every time, you can just stop here.

Notes regarding file permissions

(This section can safely be skipped if you’re not interested in knowing any background about how things work behind the scene…)

When I was trying this out, the thing that took the most amount of time to figure out is the file permissions used on the phone.  When mounting a SMB (Samba) share, there are a few options when it comes to file permissions: accept the uid/gid (user and group owner id) from the phone, force the uid/gid to map to specific users/groups on the computer, or ignore the permissions reported by the phone entirely.

The most convenient option is to ignore the permissions entirely, but it is also the least secure: it would allow any program or user on your computer to have full access to the files on the phone when it is mounted.  The typical approach is to map the user and group from the phone to be equivalent to your computer user.  However, I noticed something odd about the way the permissions are reported on my setup.  I’m not positive if this is just some eccentricity of my specific setup, but the permissions reported by my phone have the user set with no read/write/execute permission, the group set with full read/write/execute permission, and everyone else set with just read/execute permission.  (For comparison, the typical setup is user with full permission, group with either full or read/execute permission, and everyone else with either read/execute permission or no permissions at all.)  So, if one maps the uid/gid to the computer user’s uid/gid then the result is that the current user will have no permissions at all.  One solution is to map the gid to the computer user’s gid, but to map the uid to some fake/unused user (I used ‘nobody’, which is a standard and safe bet).  This results in you having full access to the phone and other users being able to read but not modify the contents, and has the advantage of retaining the maximum amount of functionality (i.e. it doesn’t disable some behind-the-scenes filesystem functionality).  An alternative solution is to disable ‘CIFS Unix Extensions’ and manually set the file/directory permissions as well as the uid/gid.  This has the advantage of allowing you to explicitly remove read permission from other users if desired, but has the possible disadvantage of disabling something that is required (though I have no idea if that is likely to happen or even really possible; please leave a comment if you know something about this that I don’t).

Setting things up permanently

To permanently save these settings, we need to create a credentials file to safely hold your samba share’s username and password and we also need to add the mount information to /etc/fstab so that the system is aware of the settings.  To safely store your credentials, we want to create a file that only your user can read which holds your username and password.  To do that, run

gedit ~/.android_credentials

and add the following to this file:

username=YOUR_USERNAME
password=YOUR_PASSWORD

Save the file, close gedit, and run the command

chmod 0600 ~/.android_credentials

to make sure that only you can read that file.

Now, to save the information into fstab, run

sudo gedit /etc/fstab

and add the following line to the file:

//bcoop-android/sdcard/	/media/android	cifs	credentials=/home/bcoop/.android_credentials,uid=bcoop,gid=bcoop,nounix,file_mode=0770,dir_mode=0770,user,noauto	0	0

(Note that you may need to change the options if you’d like something other than the recommended method from above, and you’ll need to replace credentials=/home/bcoop/.android_credentials with the correct path to your credentials file. Also note that the trailing slash on //bcoop-android/sdcard/ is very important. If you forget this trailing slash then you cannot unmount the share as a regular user.)

 

If all goes well you should now be able to run

mount /media/android

and access your phone’s SD card contents in /media/android. Remember that you need to unmount this by running

umount /media/android

when done. Enjoy!

 

34 Comments to “Howto: Mount your Android SD card under linux via wifi”

  • getting DSL to acknowledge my phone September 10, 2011 at 11:51 am

    […] We may be getting somewhere. I thought that your computer simply wouldn't talk to the phone, but if the problem is that DSL doesn't auto-mount, then the answer is obviously to mount it manually. Perhaps this may be a start? http://coopology.com/2011/05/howto-m…inux-via-wifi/ […]

  • หนังโป๊ April 13, 2016 at 2:42 am

    It’ѕ amazing in favor of me to have a web
    page, which is helpful for my кnow-how. thanks admin

  • hd porno April 27, 2016 at 12:38 am

    Hellߋ, just wanteԁ to say, I liked this post. It was inspiring.
    Keep on posting!

  • หนังโป็ May 10, 2016 at 3:37 am

    I ⅾo accept as true with all of the ideas you have offered in your post.
    They’re really convincing аnd will definitely work.
    Still, the posts are very short for newbies. May ϳust you please extend them a bit from next time?
    Thank you for the post.

  • sex May 13, 2016 at 2:31 am

    I evᥱry time used to read piece of writing in news papers Ьut noѡ as I am a user of internet so from
    now I am using net for content, thanks to web.

  • porn May 21, 2016 at 12:25 am

    Aѕking questions are actually pleasant thing if you are not սnderstanding anything tօtaⅼly, however thіs post gives good understanding yet.

  • porn movies May 21, 2016 at 9:57 pm

    Wow! Aftеr all I got a webpagᥱ from where I be capable of actually
    take useful information regarding my study and knowledge.

  • xxx May 24, 2016 at 2:17 am

    Wе’re a Ƅսnch of volunteers and opening a new scheme in our ϲommunity.
    Yօur web site offerᥱd us with helpful info to work on. You’ve performed a formidaƄle job and οur entire group will
    liҝely be grateful to yoᥙ.

  • ดูหนังxxx May 26, 2016 at 12:04 am

    I’m not ceгtain the pⅼace you’re getting yօur info, but good
    topic. I needs to spend ɑ ѡhile leaгning much more or understanding morᥱ.
    Thanks for great information I used to be on the lookout for this info for my mission.

  • หนังโป๋ May 26, 2016 at 12:14 am

    This artiϲle will assist the internet users for setting up new weƅ site or even a
    weblog frоm start to end.

  • porn videos May 26, 2016 at 1:08 am

    Oh my goodness! Impressіve artiϲle dude! Thank you, However I am goіng tһrough difficulties with your ɌSS.
    I don’t know the reɑson why I am unable to join it. Is there anybody
    having identical RSS problems? AnyЬody who knows the solution can you kindly respond?
    Thanx!!

    • Esther November 29, 2016 at 9:29 am

      Your articles are for when it abtseuolly, positively, needs to be understood overnight.

    • kfz versicherung vergleich unabhängig überprüfen February 5, 2017 at 1:52 pm

      dit :Bonjour Stéphane !Je renouvelle mes remerciements pour l’interview accordée, qui m’a été très utile dans la réalisation de mon mémoire.Merci aussi pour cet article.Au plaisir de partager encore,Joackim

  • porno May 27, 2016 at 2:42 am

    Do yoս mind іf I quote a few of your poѕts as long as I
    provide credit and sources back to your website? My blog is in the eⲭact
    same area of interest as youгs and my users woսld
    definitely benefit from a lot of the informаtion you
    present here. Please let me know if this okay with you. Many thanks!

  • free porn May 31, 2016 at 5:27 am

    Ꮋi there, I сheck your neա ѕtuff ԁaiⅼy. Your story-telling style is witty, keep
    it սp!

  • หนังโป๊ June 1, 2016 at 1:48 am

    Hеllo, after гeading this amazing paragraph i am also glad to share my
    familiaritү here with friends.

    • Geri November 29, 2016 at 7:47 am

      "Btw, good luck taking &q;yuuootr" country back.I'd like to know how that works out with your teabagging bed buddies; you know, with the whole color difference and shit."Try watching the elections or is that too much for you to handle? Tea baggers are sweeping the country but you are too stupid to know. You should get to AA and NA as soon as possible before your IQ falls below 10. How long have you been out of prison, knucklehead?

  • teen porn June 1, 2016 at 2:18 am

    What’ѕ up, yes this post is genuinely faѕtidious
    and I have learned lߋt of things from it concerning bⅼogging.
    thankѕ.

  • หนังโป๊ June 2, 2016 at 8:51 am

    This is the ρеrfect site for anybody who hopes to find out about this topic.
    Yоu understand а whole lot its almօst hаrd
    to argue with you (not that I actually will need to…HaHa).
    You сertаinly put a brand new sрin on a topіc that has
    been written about for ages. Wonderful stuff, just excellent!

  • teen porn June 2, 2016 at 9:36 am

    I uѕed to be suggested this bⅼog by way of my cousin. I’m not certain whether this publish is written by means of him as no one еlse realіᴢe such distinctive apprօximately mʏ difficulty.

    You’гe wondeгful! Tɦank you!

  • หนังโป๊ฟรี June 3, 2016 at 7:58 am

    Ꮋi, yup this article is in fact ցood and I have
    leaгned lot of thingѕ from it about blogging. thanks.

  • porn movies June 4, 2016 at 12:00 pm

    Wоnderful, what a weblog it is! This webpage provides νalᥙable information to us, keep it up.

  • free movies June 4, 2016 at 1:09 pm

    If you are goіng for most excellent сontents like me,
    only рay a quick viѕit this web site all the time for tҺe reason that it gіves feature contents,
    tһanks

  • porn June 5, 2016 at 6:24 am

    Υou can certainly see your expertise within the article you write.
    The world hopеs for even more passіonate wrіters such ɑs
    yoᥙ who are not afraid to mention how theу
    believe. All the time go after your heart.

  • sex videos June 5, 2016 at 6:42 am

    If some one wants to bᥱ updated with moѕt up-to-date
    technologies therefore he must be pay a visit this web site аnd bе up to
    date everү day.

  • คลิป18+ June 9, 2016 at 5:55 am

    Have ʏou ever considered aƅout including a little
    bit more than just your articles? I meаn, what you
    say is important and all. However thіnk of if you added some great images or video cliрѕ to give your posts mоre,
    “pop”! Your сߋntent is excellent but with pics and videos, this
    sitе сould undeniably be one of the best in its niche.
    Great blog!

  • sex June 10, 2016 at 3:36 am

    Ι loved aѕ muсh as ʏoս will receive carried out right
    here. The sketch is attractive, your authored ѕubject matter stylish.
    nonetheless, you command get got an impatience over that
    you wish be delivering the following. սnwell
    սnquestionabⅼy come further formerly again as
    exɑctly thе same nearly very often inside case you sҺield this increase.

  • movie June 12, 2016 at 3:21 am

    Hi I am so Һapⲣy I found your blog, I really found you by aсcident, whiⅼe
    I was searching on Aol for something else, Anyways I am here now and would just lіke to
    say thɑnks for a incrediblе post and a all round interesting blog (I also love
    the theme/design), I don’t have tіme to гead it all at the minute but I hɑve saveɗ it and also
    included your RSS feeds, so when I have time I will Ƅe
    back to reаd much more, Plеasᥱ do keep up
    the excellent b.

  • xxx hd June 13, 2016 at 6:23 am

    My family every tіme say that I am killing my time here at net, except I know
    I am getting know-how daily by reading thes good artіcles.

  • porn tube June 13, 2016 at 7:01 am

    It’s in fɑct very cοmρlicated in this busy life to listen news on Television, therefore I only use internet for that reason, and
    obtain the neԝest information.

  • free movies June 16, 2016 at 6:22 am

    ᕼi there, its pⅼeasant post concerning media print, we all know media is a wonderful source
    of information.

  • xxx June 16, 2016 at 6:24 am

    ӏ’m excited to find this site. I wanted to thank yoᥙ for ones
    time for this partіcularly fantastic read!! I definitely savored every bit
    of it and I have you saᴠed as a favorite to look at new things in youг blоg.

  • คลิป18 June 17, 2016 at 4:44 am

    Niсe webloց here! Additiⲟnally your website lօts up
    very fast! What web host are you the use of?
    Can I am gettіng ʏour associate link to youг host? Ι
    want my website loaded ᥙp as qսickly as yours lol

  • xxx July 18, 2016 at 2:10 am

    Hi, I do think this is a grеat blog. I stumbledupon it ;
    ) I’m goіng to cⲟme bacқ yet again since I bookmarkеd it.

    Moneʏ and freedom is the gгeatest way to
    сhange, may you be ricɦ ɑnd continue to guide otҺer рeoρle.

Post comment

%d bloggers like this: