Quick thoughts on IT, fun projects, and the singularities I come across.
  • Electronics Projects

    Electronics Projects

  • Coding Projects

    Coding Projects

Raspberry Pi Project 1: NAS and XBMC

The Raspberry Pi makes a great HTPC or media PC, whatever you want to call it, because of its low cost, low power consumption, quiet, and small form factor. As I was getting ready to start my Raspberry Pi build, I realized that the Pi could take over a few other functions that my desktop does, including NAS, at a fraction of the cost (see my previous post about Powering a Pi and related utility savings). But could I modify a RaspXBMC build to also run Samba or some other network file sharing? Could XBMC be installed on Raspbian with less than a thousand calls to aptitude? Could XBMC and Samba run simultaneously on a Pi without making video playback unwatchable? That’s what I hoped to find out.

For context, I started with a Raspberry Pi starter kit from Amazon. For storage, I am using a Fantom 2TB external hard drive. After some preliminary research, I decided to start with Raspbian and try to install XBMC on top. For this walk-through, I’ll assume you’ve got your Raspberry Pi powered, connected to your router, and that you have gotten Raspbian installed. If you need help getting started, check out the Raspberry Pi Quick Start Guide.

Part 1 – NAS

Part 1.1 – NTFS-3G

If you don’t plan to use NTFS as your filesystem for your Pi storage, you can skip this step!

If you do want to use NTFS, and you want to be able to read AND write to the drive, you need to install NTFS support:

If you’re starting with a brand new external hard drive, you’ll need to create the partition and filesystem.

Part 1.2 – Automounting with fstab

In Raspbian (and every flavor of Linux I’ve worked with so far), all filesystems that should be mounted at boot are identified in the fstab file (/etc/fstab). The fstab file can be configured a million ways, so I’ll just share my configuration and explain.

The first four lines were created automatically by the Raspbian install, we’ll leave those alone. We’re only interested in the last line that starts with /dev/sda1, that’s the line I’ve manually added to the configuration.

BUT WHAT DOES IT ALL MEAN???  The columns of the fstab file (courtesy of the ArchLinux wiki) are

<file system> - the partition or storage device to be mounted. In my case, “/dev/sda1″
<dir> - the mountpoint where <file system> is mounted to. In my case, “/media/1TB”
<type> - the file system type of the partition or storage device to be mounted. In my case, it is “ntfs-3g”
<options> – mount options for the filesystem. In my case, I chose “defaults” which includes mounting the filesystem as read-write with no umasks for permissions/access
<dump> – not needed in our case, just use 0 (zero)
<pass> -
used by fsck to decide which order filesystems are to be checked. You can set this to 0 (zero)

So my configuration file says to mount /dev/sda1 on /media/1TB as an NTFS filesystem, using default mount options, and never run fsck on this drive.

Now that you have an example, implementing is pretty easy.

  1. Make a backup of your fstab file
    sudo cp /etc/fstab /var/fstab
  2. Open fstab in your favorite text editor
    sudo vim /etc/fstab
  3. Add the lines to the configuration (see example above) to automount your drives
  4. Save and close the fstab file
  5. Test your configuration by executing a mount all command
    mount -a

If your drive correctly mounted to the mount point you specified (/media/1TB) and it is mounted as read-write, you’re golden.

If you are using multiple drives, then simply add additional lines to the fstab to cover all of the drives you want to automount. Now our storage will automatically mount read-write at startup.

Part 1.3 – Samba

In my build, I wanted to share out any drives mounted in /media/ in case I added drives in the future. Additionally, accessibility rather than security was the priority for me. Because of that I set up Samba to allow anonymous access to any device on my LAN. If you’re cool with that approach, follow along. If not, you may have to do some research on how to set up Samba to your liking.

  1. Install samba
    sudo apt-get install samba
  2. Open the samba config file in your favorite text editor
    sudo vim /etc/samba/smb.conf
  3. Find the line that says “security = user” and update the file with the following lines
  4. Scroll to the bottom of the Samba configuration file and add a new section for your new share. See my configuration for example
  5. Test your configuration by executing ‘testparm’ and examining the output
  6. Assuming your test went well, reload samba
  7. On another device, try to mount the share. On Windows, you can just open the start menu and type “\\yourservername” or “\\your.server.IP.address” On a Mac, open Finder, go to the “Go” dropdown menu at the top, and choose connect to server

    Courtesy of Mobilefish.com

    and enter “smb://yourservername” or “smb://your.server.IP.address” If prompted for a user account, choose Guest.

OK, this is already over 1000 words long so let’s take a breather and continue with XBMC in Part 2.

Part 2 – XBMC

Part 2.1 – Installing XBMC

Installing XBMC is usually pretty easy, but since we’re using Raspbian we can’t use the normal packages. Fortunately for me and anyone who is trying to accomplish this, Michael Gorven has already figured this out for us and even hosts the packages we need. Go ahead and open a new window or tab and browse to http://michael.gorven.za.net/raspberrypi/xbmc . The author has already done a great job of documenting this process so I won’t duplicate it here. Once your installation is finished, test that you can start XBMC by executing ‘sudo xbmc-standalone’ and seeing if XBMC appears on your display.

This is perfect, except that XBMC is now tied to our session. Now if you’re directly connected to the Pi with a keyboard, this is irrelevant. If, like me, you’re doing all of your Pi work via SSH, XBMC will die once you terminate your SSH session. Let’s set up XBMC as a service so we can start/stop it gracefully and allow it to run after our SSH session ends. Additionally, if you’re having issues with XBMC not starting at boot, setting up a service can ensure that XBMC is started for the right run levels.

Part 2.2 – Setting up XBMC as a Service

The XBMC Wiki has a good article for how to set up XBMC as a service, but I want to expand on it a little bit.

  1. Create the init script file
  2. Paste the following code into your vim session:

    Save and quit out of vim. There are a few differences between my init script and the one provided on the XBMC wiki. For one, my “runas” user is set to “pi” – you’ll want to set this to whatever user you installed XBMC with to avoid permissions issues. Additionally, my init script will take “status” as an argument to the init script and will return information about whether or not XBMC is running.
  3. Change the script’s permissions to make it executable
  4. Test that the init script is working:
  5. If you want XBMC to start when the OS boots, update the rc.d scripts. Unless you have a specific use case, using the “defaults” argument will work for you.
  6. If you want to be thorough, restart your Raspberry Pi and verify that your disk has been mounted (via fstab from Part 1) and that XBMC has started.
  7. You’re done. Time to enjoy.

abed_cool_cool_cool

Part 2.3 – XBMC Remote

If you’re going to manage your XBMC/NAS/Pi remotely, I would also suggest downloading the XBMC Remote App for your Adroid or iPhone. To enable remote control on XBMC, go to System -> Settings -> Services -> Remote Control and enable both “Allow programs on this system to control XBMC” and “Allow programs on other systems to control XBMC.”

XBMC Settings->Services Screen

Courtesy of xbmc.org

Assuming you’re on the same wireless network, you should be able to connect to the XBMC with your remote app using your Pi’s IP address and the default username and password of ‘xbmc.’

Well at nearly 2000 words, this has been a whopper of a post. Hopefully this write up has helped you one way or another, and let me know if you have any questions. Enjoy your new combination NAS and HTPC.

Powering a Raspberry Pi

I recently started building out a combination NAS and HTPC on a Raspberry Pi and came across some interesting information about powering Raspberry Pi’s. While this isn’t a project post per se, I thought it was interesting enough to share and wanted to send this out as sort of a PSA for the users out there who don’t know the potential danger of “backpowering” a Raspberry Pi.

For those who don’t already have one, here are a few suggestions for where to get a Raspberry Pi.

Where to get a Raspberry Pi

If you have some of the peripherals (SD card, HDMI cable, micro USB power supply), you can get started with a standalone Model B Raspberry Pi for as low as $35.

If you would rather get a starter kit, the prices are pretty reasonable and usually includes an SD card pre-loaded with the Raspberry Pi New Out Of Box Software (NOOBS). Here are two good starter kits.

Power Consumption

As an Arduino die hard, I didn’t think I really needed a Raspberry Pi for anything. I was sold once I realized I could run all of my home web server functions on the 3.5 watt ARM processor instead of 85 watt Intel chip in my desktop. The Raspberry Pi will actually pay for itself in about 4 months.

Utility cost of running home server on full x86 desktop (Intel dual core, ATI Radeon HD GPU, 3 HDDs) [high estimate]

(Power draw x hours per week x weeks per year x cost per kilowatt hour) / (1000 watts per kW x 0.85 efficiency x 12 months a year) = estimated cost per month

(150 watts x 168 hours x 52 weeks x $0.10 per kW hour) / 1000 watts per kW x 0.85 efficiency x 12 months a year) = $12.85 per month

Utility cost of running home server on Raspberry Pi and one external hard drive (5 watts for Raspberry Pi, 15 watts for HDD under load) [high estimate]

(20 watts x 168 hours x 52 weeks x $0.10 per kW hour) / 1000 watts per kW x 0.85 efficiency x 12 months a year) = $1.71 per month

Approximate cost savings: $11.14 per month

Powering the Pi and the Dangers of “Backpowering”

The Pi only has two USB ports, so obviously many folks incorporate a powered USB hub to expand its capabilities. At some point, someone discovered that the powered hubs were actually supplying power to the Pi via the uplink between the hub and the Pi. Now you can power your peripherals and the Pi from one outlet. Cool right?

no

Read More

Download All Files From A Site With wget

I recently got a membership to a site hosting a boatload of private label rights (PLR) material (IDPLR.com). 99% of PLR items are scams, garbage, or are outdated, but if you have the time or tools to dig through it you can find some gems. (Just so we’re clear, I’m not running any scams, I was just looking for some content for another project). Anyway, I got access to the site that had thousands of zip files but obviously didn’t want to download them one by one. Administrator wouldn’t give me any way to download the files in bulk either, so I was left with no choice but to automate…

This is one of those projects that can be done a dozen different ways. There’s probably a real slick way to do this with one line of code, but this method worked for me.

Read More

Thematic Password Generator

I’ve been wanting to build a thematic password generator for some time. Basically, choose some sort of “theme” and a few password strength parameters, and it will generate random passwords for you. Will come back to update this post and expand on themes shortly.

Read More

Stabilized Gimbal

Arduino-uno-perspective-whitw

This post is part of a new series strictly dedicated to project ideas. Unlike my usual posts, these are projects I haven’t had the time to implement, but that I would like to record both for myself and for other makers who may need ideas for projects. See the Project Ideas page for more.

This is a really fun project idea, and has a dozen use cases. Basically, a gimbal is a device that keeps an object oriented in one way regardless of how the supporting structure moves. This definition is sort of hard to picture or imagine, so let’s talk about a few use cases first.

One of the most common and practical applications is photography. If you’re running around or bouncing around in a boat or something, a gimbal can be used to stabilize the camera. Some gimbals use no electronics whatsoever and rely on a counterweight. Other gimbals are super-expensive pieces of engineering madness. Here’s an awesome example of the latter:

Read More