Linux.com

Home News Hardware Servers Plugging Away: DIY File Server Using Samba

Plugging Away: DIY File Server Using Samba

"That sounds like something I could have used in my office," Dad exclaimed.

I had just described mating a Plug Computer with a 500 GB Western Digital USB external disk and putting in on my LAN. Servers and support were difficult, back in the days when Dad had his small business. We've certainly come a long way.

The Plug Computer is one of the latest products in the newly emerging micro-server market. It doesn't have a video card, keyboard, mouse, fan, or hard disk. It does have Gigabit Ethernet, a USB port, an SD card slot, a 1.2 GHz processor, 512 MB of RAM, and a matching 512 MB of solid state storage. The thing is accessed over the LAN using SSH. Oh, yes... it's about a quarter of the size of a brick and costs US$99 (development system version). Add an external disk and Samba for a simple, low-cost networked drive with a lot of potential.

You can build your own, which is the subject of this article. Or, you buy one already set up to accept your external disk drive. Here are a couple of examples, before we launch down the DIY path.

  • Cloud Engines PogoPlug: Just connect the Pogoplug to your home network and attach an external drive or memory stick. Then, go to the Pogoplug site and register your machine. A little setup program will run, you'll answer a few questions, and then the new drive will be available on your LAN or over the Internet.
  • CTERA Cloud Plug: CTERA has a similar product that also features automated backups to their cloud.

Let's see how you put your own system together.

Add Samba To The Plug Computer

The first thing to do to get your Plug Computer file server going is to log into the machine as root via the command line and a regular terminal. Naturally, you'll need to know the Plug Computer's IP address.

rreilly-laptop$ ssh -l root 192.168.1.30

Once you're logged in, you can use apt-get to install Samba.

plugcomputer# apt-get install samba

You'll then need to put together a basic /etc/samba/smb.conf file. Here's what I used. I found it easy just to save the original factory smb.conf file to another name and create a new one with VI or Nano.

[global]
workgroup=ROBNET
netbios name=SAMBA
server string = Sambaserver %v
map to guest = Bad User
log file = /var/log/samba/log.%m
max log size = 50
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
preferred master = no
local master = no
dns proxy = no
security = User

[bigdisk]
browseable=yes
path = /bigdisk
valid users = rreilly
read only=no
create mask = 0777
directory mask = 0777

[sdcard]
browseable=yes
path = /sdcard
valid users = rreilly
read only=no
create mask = 0777
directory mask = 0777

You'll also need to create suitable directories such as /bigdisk and /sdcard, to allow mounting of the drives (or SD card) to the file structure.

There are several ways to find out the mount point for your big external hard disk.

plugcomputer# fdisk -l

This will show physical devices that are attached to the Plug Computer. You could also plug your disk into the USB connector and then check the /var/log/messages.

To attach the drive or card use the mount command, again as root. In my case the Western Digital drive showed up as /dev/sda1 and the SD card was /dev/mmcblk0p1. Since the devices I used were formatted in VFAT, they will mount as read only, at this point. More on this situation in a minute.

plugcomputer# mount /dev/sda1 /bigdisk
plugcomputer# mount /dev/mmcblk0p1 /sdcard
You'll also have to set up some users. On my machine the user (myself) is rreilly.
plugcomputer# smbpasswd -a rreilly

New SMB password: ######
Retype new SMB password: ######

The last thing to do is to start the Samba server. Don't forget that each time you edit the /etc/samba/smb.conf file, you should restart the server.

plugcomputer# /etc/init.d/samba start

Storage Options

You should be aware that there are a couple of quirks, if you are building your own micro-server, that point out fundamental philosophical differences between the Windows and Linux world.

If you plug in a standard Western Digital 500 GB external USB drive, you'll have to treat it as a public disk. Since the disk is formatted with the VFAT file system (Windows), by default, it will look like one big disk and will not have any segregation, according to user. In other words, everyone that accesses the disk will have read/write to all the files. There is a catch though. Since root needs to mount the file, root will be the only one that can write to it because of the permissions. The easy way around this problem and how you can ensure the drive will be properly mounted after a reboot is to edit the /etc/fstab file. Add a line at the bottom of the file like.

/dev/sda1 /bigdisk vfat umask=000 0 0

This will allow regular users to read and write files to the drive.

On the other hand, if you use a generic external USB drive enclosure, with your own choice of harddisk, you can install a standard Linux format, like ext2, with all the permissions you want. You'll be able to apply standard user and group permissions, as well. A generic disk enclosure could also be useful if you need to recover data from a dead laptop. Stick your old laptop drive in the enclosure, mount it as usual and retrieve your data.

SD cards can generally be treated as VFAT media. A great tutorial on setting up Samba permissions and shares can be found on the Swerdna.net site.

Access Over The LAN

Reading and writing to the network drive from a Linux machine is pretty easy. Fire up Dolphin and click on the network tab. Then click on the "add a network folder" menu item and choose to connect a Microsoft Windows Network Drive. Click next. In the name text box, give your disk a name, like bigdisk. Put the IP address of the Plug Computer in the server box. Finally, put the directory name in the folder box. My directory was also bigdisk. Click save and connect. You should immediately see a popup box asking for your Samba username and password. Put those in and you should see your drive. You did restart the Samba server after editing the smb.conf file, didn't you?

You'll need to do a little more work to connect to the drive from a Windows Vista machine.

Click on Start and then select the Control Panel. Select the System icon and when that page appears click on the Change Settings button under the Computer Name, Domain, and Workgroup heading. Click the Change button on the Computer Name tab. You can then fill in the workgroup that you used in the smb.conf file. Of course, I used ROBNET. Hit OK. Now if you click the Network menu item on the Start menu, you should see the SAMBA server name appear as one of the shared drives. Double click the SAMBA share. You should again get the popup screen asking for your Samba user name and password. Enter those and then you can select the bigdisk directory. Once you click on that icon, you'll be able to travel down to any of the files or subdirectories.

You can also start up the Windows File Explorer and click the drive mapping tool. Here you can set up a link (like a G: drive) to the drive that will be persistent after a reboot.

Where Do We Go From Here?

Lots of possibilities exist to expand on our basic file server theme. Maybe you'd want to try your hand at installing FTP.

Another option might be to use a USB hub to attach additional storage devices. Why not plug in three 1 TB drives and have a little disk farm?

Rob Reilly is a consultant and freelance technology writer. His interests include Linux, anything high-tech, speaking, and working with conferences. You can visit his web page at http://home.earthlink.net/~robreilly.

 

Comments

Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFD331 Developing Linux Device Drivers
    13 Oct » 17 Oct - Virtual
    Details
  2. LFS425 Linux Performance Tuning Crash Course
    16 Oct » 16 Oct - Düsseldorf, Germany
    Details
  3. LFS220 Linux System Administration
    20 Oct » 23 Oct - Virtual
    Details

View All Upcoming Courses

Become an Individual Member
Check out the Friday Funnies

Sign Up For the Linux.com Newsletter


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board