Sunday, September 03, 2006

Setting up External Hard Drive Samba Shares on OS X

I have a large USB 2.0 external hard drive (300GB) connected to my brand spanking new mac mini, loaded with files that I wanted to be able to access on my Ubuntu box, which is all the way on the other side of the room. Initially I was just unmounting the volume, unplugging it and carrying it all the way accross the room to my Ubuntu machine. Well after doing this once, my arms got tired, and I thought to myself there must be a better way.

My initial thought on this was to create an alias in my home directory, and then open it up for sharing. So to do this I created an alias of the drive in my home directory (right-click on the folder -> create alias of "FATMATT" -> drag the alias into my home directory) and then allow my home directory to be shared with samba (system preferences -> sharing -> windows sharing). This all seemed to work fine, except that linux (and windows for that matter) doesn't know what the alias is.

Well I have a solution for this I thought, I'll just soft link the directory into my home directory, certainly Ubuntu can understand that. So I opened up my trusty terminal window and went to work:

ln -s /Volumes/FATMATT /Users/matt

I go back to my Ubuntu box and it understands the soft link, and I can go into the folder and browse the contents. When I try to open anything in the samba share however, it won't do it. Well it turns out that since the actual files are ouside of the samba share, and also because OS X prevents sharing USB drives over samba shares, you're unable to open the files despite the fact that you can see what files are on the volume. Though I would recommend using soft links instead of aliases whenever possible, as through this process I discovered that a soft link is actually much faster in file browsing than an alias is (especially when using front row).

So I'm left with my final option, the one I didn't want to go with: configure an extra samba share for the USB drive. As OS X is nice enough to come with samba installed and configured for the home directories, I didn't have to install a samba server on the machine (a task that is quite daunting in Linux), all I had to do was reconfigure samba a bit.

In OS X samba's primary configuration is stored in the /etc folder as the file /etc/smb.conf, to add extra samba shares you need to configure this file by hand, so I went once again to my trusty terminal and opened the file with sudo and nano (that's right I use nano . . . just leave it), backing the file up first of course:

sudo cp /etc/smb.conf /etc/smb.conf.bak
sudo nano /etc/smb.conf

Samba's configuration is quite simple and easy to understand, it is comprised of sections denoted by starting tags of the form [start tag]. To define a share you just think of what you want the share to be called and then create a section with that name, for example my drive is called "FATTMATT" so I create the following section with the tag [FATMATT]:

comment = FATMATT
path = /Volumes/FATMATT/
browsable = yes
read only = yes

The configuration options in the section tell samba the following:

comment = FATMATT

This option gives samba the name of the share as it will be displayed to the samba client.

browsable = yes

This value allows the samba client to browse the contents of the folder.

read only = yes

This disallows the ability to write to the share from the client, to allow the share to be written to from a client merely exchange that line with the following line:

read only = no

Once you've added your section you need to make sure of a few things. Check the ownership and permissions of the USB drive to make sure that the user you will be accessing the share as has read permission to the drive (for read only) or read/write permission on the drive (for not read only)

ls -l /Volumes/

Then finally you'll have to reload samba with the new configuration file

sudo killall -HUP smbd



Keith Rodriguez said...

sorry to be dense, but can you describe how to create a "soft link" and how it differs from an "alias"?

Matthew Story said...

certainly, to create a soft link you have to use the command line, which in OS X requires you to open a terminal window: Applications -> Utilities -> Terminal. To create a soft link you use the link program: ln, with the soft option: -s like so:

shell ~$ ln -s <real file> <path to link>

A soft link just adds a link file at the specified location in the file system that points to the real file that you linked to. The reason we use a soft link, as opposed to a hard link (which is just ln without the -s option) is that with the soft link we can link folders and everytime the contents are updated the changes are replicated in the link, as when you navigate inside the soft link it just points you to the real file.

An alias file (OS X specific) is more like a shortcut in windows, and it isn't recognized in anything but OS X. Whereas a soft link is recognized by all *nix flavors, and also (as i found out) results in a slight performance boost.

Hope that answers your question.

MackH said...

Thats a great tutorial, worked like a charm, thx!

wow power leveling said...

You said you will love me the whole life, but you marry her. You said you will wow power leveling,come to marry me, but this will not be carried out forever.WoW Gold I am trying my best to forget you and do not love you anymore. wow leveling But I failed and I still love you. Maybe wow leveling she needs you more compared wow leveling with me. So I tell you that world of warcraft power leveling you should love world of warcraft power leveling her and take good world of warcraft leveling care of her. You said I was so of warcraft leveling Yes, because I love you,world of warcraft leveling I hope you will be happy forever.

nike said... : cheap polo shirts : polo shirt : lacoste polo shirts : ralph lauren polo shirts : wholesale polo shirts : Yellow Polo Shirt : Men's Polo Shirts : Wholesale Polo Shirts : polo shirts : Lacoste polo shirts : chaussure puma : chaussures puma : polo shirts

bing said... : chi hair straightener : chi flat iron : new polo shirts : cheap handbags : cheap bags : puma chaussures : chaussures puma : chaussure puma : Men's North Face : Women's North Face : hair straighteners : sexy lingerie store : cheap ugg boots : tattoo wholesale : men's clothing : women's clothing : cheap hair straighteners : cheap Lacoste polo shirts : cheap Lacoste polo shirts : 2009 nike shoes : new nike shoes : Women's max : Men's max 93 : nike shox : Nike air force : Nike air max 2003 : nike air max ltd : nike air max tn : Nike air rift : Nike air Yeezy : nike airmax : Nike air max 90 : Nike air max 97 : nike birds nest shoes : nike dunk : nike RT1 shoes : nike SB : nike shox shoes : Nike shox OZ shoes : Nike shox R2 shoes : Nike shox R3 shoes : Nike shox R4 shoes : Nike shox R5 shoes : Nike shox TL3 : nike trainers lovers : tennis rackets : Wilson tennis rackets : HEAD tennis rackets : Babolat tennis rackets