Josh Nock

Code Craftsman

BeagleBone Black NAS Server

So you got a beaglebone black laying around? “

beagle bone black rev c

 
Photo: adafruit.com

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 Adafruit.com 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

[public]
    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
or
\\(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.

How to Change the Bitnami ownCloud Default page

So in the previous post on ownCloud we launched the EC2 instance and made some DNS changes to build our own private dropbox at a fraction of the price….  but… it left us with this UGLY landing page.

image

And I’d prefer it to look like this when I go to the site.

image

 

So lets fix this…

First you need to download Putty, which is a very nice SSH client, or you can use the SSH client that amazon lets you run in the browser.

Grab the installer and just use the default settings.

image

Next make sure you download your key pair from Amazon.  After you have your key and putty installed follow amazons instructions for converting the key and using putty.

Once you have successfully logged into you EC2 instance, we’ll need to navigate to the apache directory and change the default configuration.


First change directories.

: cd /opt/bitnami/apache2/conf/

Next edit the httpd.conf file.

: pico httpd.conf file

It should look something like this (also you can use the command ‘ls’ to list the contents of the current directory)

image

Navigate down to the line that shows document root.

image

Here you can see I commented out the original line and added “org:” to the front of it.  (noob tip: The # symbol is what comments out the line, and tells apache to ignore)  Changing ‘DocumentRoot’ changes the default directory for apache.

 

There is also a second line to modify just a little bit further down (2 x PgDn)…

image

Now to save the file, it’s ctrl+O (“Write Out”), it will prompt you for the filename, in which it will already be shown.  Hit enter and the file will save.  Then it’s ctrl-X to exit the pico editor.

image

Now we need to restart apache for the change to take effect and there is a shell script that performs this for us.  To restart apache use the following command:

: sudo /opt/bitnami/ctlscript.sh restart apache

if there is anything wrong with the httpd.conf file then it most likely will stop the process and write out the error to the screen.

Otherwise you should see this.

image

 

Now when you go to the default landing page for your EC2 instance you should see your login screen.

image

 

Aaaahhhh so much more cleaner!

Technorati Tags: ,,,,,,,,,,,
WordPress Tags: How-To,DropBox,EC2,Amazon EC2,AWS,Amazon Web Services,Bitnami,Amazon,DocumentRoot,ownCloud,apache,pico