Josh Nock

Code Craftsman

BeagleBone Black NAS Server

So you got a beaglebone black laying around? “

beagle bone black rev c


It was fun, but now you’ve run out of ideas.  Well if you’ve been thinking of getting an external storage device for backups and don’t want something you need to turn on or off every time you need to backup a file or download something to your laptop.  Or lets say you’ve got a hard drive laying around with a bunch of movies and photos you backed up.  Well lets set up your low power BeagleBone Black as a NAS server.

First if you don’t have a revision C beaglebone, you’ll want to swap out the default Angstrom operating system for a more common *nix OS.  There’s a great tutorial on to guide you through installing a new operating system. 

I choose ubuntu so all my instructions here will be based on those commands for that brew of linux.
Start by updating your os

> sudo apt-get update 

Next we’ll want to install samba which will let us create a network share

> sudo apt-get install samba samba-common-bin 

Now we’ll want to create a directory that we will map our external hard drive to, this directory will be become a “virtual” directory once the OS maps to the hard drive.

> cd ~/     
> mkdir mnt
> mkdir mnt/usbdrive

Ok, so with Samba, you can actually create password protected folders for individual users, and the configuration for samba you can specify where this directory is, but we are going to take advantage of the public share features (no authentication necessary) of samba, and share the entire hard drive.  Please note I’m assuming you’ll keep this behind a router with a fully enabled firewall, less you really love giving the NSA minimal resistance to snooping.

What we want to do next depends on whether you have a brand new hard drive or an existing one.  If you have a new hard drive, follow these instructions for formatting your hard in ubuntu but stop before last section on mounting and come back here.

Chances are if it’s an external hard drive you used with your windows PC, then it is formatted with NTFS.  If you have a brand new drive than it is recommended to use ext4 for most *nix operating systems.  You’ll want to google how to format a new drive for ext4, as I have not gone through that yet.  If you’re like me and stuck with an NTFS drive with a bunch of crap on it already, then you’ll want to install some ntfs driver goodies.

> sudo apt-get install ntfs-3g

So lets plug in the hard drive to the Beagle and see what we get.  We need to find out what drive the OS sees, normally it is something like “/dev/sdaX” where x is an assigned number.  Seeing as my beagle bone has no other drives attached it shows up as /dev/sda1 but for you to be sure you can just type this

> ls /dev/sd*

 this should list the directories/partitions for the connected drives, you can also use the following command to see which drives your system can see and which partition is which based on size.

> sudo fdisk -l

the parameter after fdisk is "L" as in list the drives.  ok. so now that we're sure which drive is our external hard drive, lets mount it to our "/mnt/usbdrive" directory we created earlier.  we can do this manually with the following.

> sudo mount /dev/sda1 /mnt/usbdrive

now make sure you use the correct /dev/sda* <- drive directory for the mount command.  to check if this works, you should be able to browse the contents of the directory.

> ls /mnt/usbdrive

Now we need to configure the samba server, but first a caveat, you can use samba to create user specific directories that are password protected.  I was not interested in using these features and just wanted a public folder that anyone inside my network can access.  

First lets make a backup copy of the default samba configuration

> sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old

Next, lets edit the configuration for the public folders

> sudo nano /etc/samba/smb.conf

Find the section public folders section and we'll want to change it to following

    comment = Public Files
    path = /mnt/usbdrive
    browseable = yes
    writeable = yes
    guest ok = yes
    read only = no

Now if you're using nano editor, to save and exit, first hit ctrl+X then type Y for yes to save the changes and next hit enter to save it with the original file name (ergo, overwriting the existing file).

Next we need to restart the samba service

> sudo service samba restart

Now you should be able to navigate windows explorer to the shared drive, but you'll need to know the name of your beagle bone, (the name you told ubuntu to name the computer when installing), or you'll need to know the IP address.

In windows explorer you'll want to enter the following

\\(name or ip)\Public
\\(name or ip)\

If you're not able to access the drive or you can't create a folder or copy a file to it.  It may be that the drive doesn't have the correct permissions set.  The following will allow that

chmod -R 777 /mnt/usbdrive

Now the very last thing to know is that if your Beagle Bone resets or reboots the external will no longer be mounted.  And you'll need to login and remount it, unless you instruct the OS to re-mount on startup.  I'll go into detail with that in the next post.  but for now you'll just have to quickly SSH into your beagle bone and run the mount command.  it'll keep your linux skills un-dull.

blog comments powered by Disqus