In the spirit of a nice afternoon project, I'd encourage you to use what's laying around if it's close to the specs here. But if you're going to buy all these parts ahead of time like I do, hopefully it will help to use the product links below. While I love Amazon, please try and support great suppliers like Adafruit, who have a great forum community, customer service and tutorial section!
- Raspberry Pi Model B (Although a Model A might work, it wasn't used for this build.) Get it from Adafruit or Amazon.
- 5VDC USB Power Supply (For some reason, I had 2 of these in the bottom of a box, but this one would work great too.)
- 16GB SDHC Memory Card (I used this one, but feel free to use whatever you have laying around- this tutorial might not work with smaller density cards, so beware.)
- HDMI Monitor and HDMI Cable (I happen to have this one, but anyone should do.)
- 3TB External Hard Drive (I used this one.)
- A USB to SDHC Adapter (Like this one.)
- USB Keyboard
I'm guessing you already have a Windows PC nearby, you'll need that too. For software, you'll need:
From your Windows PC:
There are other ways to do this with Linux and OSX, but our tinker machines a PCs, so I thought it would be helpful to give everyone the rundown on a PC.
First, we need to setup the external drive. Since all my cool tunes from Archive.org are on another Windows PC, and most of the machines in my house are also Windows, it's important that I can plug the big storage drive into a Windows machine and copy stuff whenever I need to. Do the following:
- Assuming you're starting with a brand new drive, find it in My Computer and format it. To do this, right-click on the new hard drive and select 'Format'. Be very careful you've got the right drive, otherwise you're going to delete important stuff. If it's not a new drive, move everything off before formatting it. !!Formatting the drive will erase everything on the drive!!
- When you format it, select the filesystem type 'ExFAT'. Exfat is cool because it's supported a little better than NTFS on Linux, and it's fully supported on Windows 7&8 too- even for very large drives (unlike FAT or FAT32).
- Go ahead and check the box 'Quick Format' and click the 'Format' button.
- Once it's formatted with ExFAT, go ahead and copy stuff onto it- in my case it's my Music from Archive.org.
- Assuming you've got quite a bit of stuff to copy, go ahead and step away while the copy job is running. If you don't have anything to copy, unplug the drive and set it aside- we'll come back to it later.
Next up is setting up the SDHC card to image Occidentalis onto it. Go ahead and plug the SDHC card into the USB adapter, then plug that into the PC. Note what drive comes up, because we're going to format it too.
- Again, I'm assuming you've got a brand new memory card to play with- if you still have stuff on it, move it off now- we're going to format this card too, and that erases everything on the memory card.
- Right-click on the new hard drive and select 'Format'. Be very careful you've got the right drive!
- If the memory card is under 20GB, select FAT32. Others might work, but I have done this with FAT32. That's ok, because it's going to get overwritten. We need the SDHC card to be blank though- don't skip this step.
- Go ahead and check the box 'Quick Format' and click the 'Format' button.
Now that we have a blank SDHC card, we can write the Occidentalis v0.2 image onto it!
Download a copy of the Occidentalis v0.2 image from Adafruit here. This may take a little bit since it's over 800 megabytes, so we'll come back to this step in a bit. When it's done downloading, it's a zip file that must be extracted to get the file named "Occidentalis_v02.img".
Download the Win32DiskImager application here and extract the zip file to a folder. Inside the folder of files you just extracted, you will find Win32DiskImager.exe, go ahead and run it. If you're on Windows 7 or 8 and have User Account Control (UAC) turned on, it may prompt you for administrator access- this is ok since the application needs access to your disk devices to write the image. Now that we have it running, it looks something like the window below:
Click the blue file icon and navigate to your Occidentalis file, and it should be named "Occidentalis_v02.img". If you try to do it with the original zip file you downloaded without extracting it, this process won't work. Under 'Device' you'll see that the application has selected a removable disk letter for you automatically. Make sure this is the right drive letter for your SDHC memory card! Again, if you select the wrong drive letter you can erase a drive on your PC. Once you're sure, click the "Write" button.
When it's done you'll get a dialog box that tells you it's been successful. This means you have successfully written the Occidentalis image to the SDHC card. Go ahead and unplug the SDHC USB adapter from your computer and insert it into the Raspberry Pi. Note the angled end of the memory card and how it lines up with the Raspberry Pi when you slide it in.
Raspberry Pi Memory Card photo
Go ahead and hook up all the connections to the Raspberry Pi. This includes:
- Plug in the SDHC card, in case you haven't done so already.
- Plug in the HDMI cable to your monitor and the other end to your Raspberry Pi.
- Plug in the network cable to the Raspberry Pi.
- Plug in the USB keyboard
- Last, plug in the power.
It will take a minute to boot up, but you'll find out that this $40 computer runs pretty fast!
When the Pi boots up for the first time, you'll be greeted by the Raspi-config menu. We'll do a couple things here that will help with the operation of the Pi.
- First, use the arrow keys to select 'expand_rootfs' and hit Enter. It will only take a second and give you a message something like, "Root partition has been resized. The filesystem will be enlarged upon the next reboot."
- Hit Enter again.
- It will take a second or two to load, but it will load up a list of locales. Scroll down and find "en_GB.UTF-8 UTF-8" and hit the spacebar to clear the * next to it. I'm not in England and don't have one of their keyboards, so I don't want this locale. Scroll down and find, "en_US.UTF-8 UTF-8" and hit the spacebar to select it. You should see a * next to it. Use the Tab button to get to the 'Ok' button and close this menu.
- When prompted, select 'en_US.UTF-8' for the default system locale and hit Enter. It will take 20-30 seconds to update the system.
- Arrow down to 'ssh' and hit enter. When prompted, select 'Enable' and hit Enter. Hit Enter again after it tells you it's been enabled.
- Arrow down to 'change_pass' and hit Enter. Enter your new password, then again to confirm. Your username is pi.
- Arrow down to 'Finish' and hit Enter. When prompted for the reboot, select 'Yes'.
- When it reboots it will resize the partitions to use the whole SDHC card. This only takes about 1 minute.
- Login with your new password. Remember, your username is 'pi' and the password is whatever you set it before rebooting.
We're going to be using 'nano' to edit our files. Old-schoolers may prefer emacs or vi, but for the casual user nano is the way to go. You'll see 'sudo' at the beginning of each command, which is required since each of these files can only be opened by a root account. Sudo will run whatever you type in after it as root. Commands in nano are easy- they are at the bottom of the screen, but the easy ones are Ctrl-O to save the file, Ctrl-X to exit.
This step is optional, but if you are going to use the Pi as a file server then you want a static IP for a number of reasons. We're going to change from a dynamic IP that uses 'DHCP' (Dynamic Host Configuration Protocol) to a static one. DHCP addresses are usually handed out by your router- we're going to assign one that never changes. We're going to use 192.168.26.6. First, let's fire up nano again, this time to edit the /etc/network/interfaces file. Go ahead and run the command:
sudo nano /etc/network/interfaces
See the line that says:
iface eth0 inet dhcp
We're going to put a '#' in front of it so that Linux will skip it. Edit it so it looks like this:
#iface eth0 inet dhcp
Now below it, add these lines:
iface eth0 inet static
You can leave all the other lines alone.
Hit Ctrl-O to save it, then Ctrl-X to quit.
We now need to reboot to make the changes take effect. At the console type:
After it's done rebooting, go ahead and log in again. From here on out you can use Putty as an SSH client to connect to your Pi from a windows machine. The commands will be the same, but to use Putty simply run it, type in the IP address of your Pi, then click 'Connect'. The first time you connect it will ask you to confirm the RSA thumbprint- it's ok just to click yes.
Next up, let's make sure all of our packages are up to date. We'll be using the system many Linux systems enjoy called 'apt-get'. This is a system for downloading and installing packages. Since many add-on applications for Linux require other applications, apt-get does a great job of automatically getting these dependencies for you.
This command will update the package list that apt-get has.
sudo apt-get update
Now that we've updated apt-get, let's go ahead and upgrade all of our packages.
Press 'y' when prompted.
sudo apt-get upgrade
This will take a while- go grab a cup of coffee while you wait, this could take at least an hour.
Now let's install the packages we need:
First we'll add support for the ExFAT filesystem. This is easy, thanks to our friend apt-get:
sudo apt-get install exfat-fuse
Pretty easy! Now let's plug in your external drive to the Raspberry Pi. You can run the command 'dmesg' and it will spit out a bunch of stuff- but if you look, you can see the last 20 or so lines it can see your hard drive you just plugged in. Look at the screenshot below, and you can see if found my 'U3 Cruzer Micro' and you can see it's been identified as disk [sda1]. Now we're ready to mount it, but before we do we need to make a folder for it to mount to. Let's call it 'flash4gb' and let's put it under the /media folder. To do that, run this command:
sudo mkdir /media/flash4gb
Now let's mount the drive:
sudo mount /dev/sda1 /media/flash4gb -t exfat
Let's check and make sure it's there:
Ok, if we look at the screen above we can see it's mounted and it sees all 3.8GB of the USB drive. Remember, this process is the same for the 3TB drive in the example- my 3TB is still copying files over so it will be a little while. We'll keep going with the flash drive.
If we left it as it is now, the drive will be uncleanly dismounted (forced) when the Raspberry Pi shuts down, and it won't be mounted automatically either. Let's modify the fstab file that keeps track of what gets mounted on boot. If you're going to remove the drive all the time, you don't want it in fstab- but we will want it in there. Run the command:
sudo nano /etc/fstab
Add a new line at the bottom that reads (each set of text is separated by a tab):
/dev/sda1 /media/flash4gb exfat defaults0 1
Again, Ctrl-O to save, Ctrl-X to exit.
Let's install Samba, the network suite that lets our Raspberry Pi look like a Windows file server. Run the
apt-get command as shown:
sudo apt-get install samba
When prompted, hit Enter to approve the packages and let apt-get do all the work. Now it's time for some very, very basic Samba configuration. Samba is a beast, and can take lots of effort to get it just right. For this tutorial, we're only going to setup basic sharing so we can see our media files. To do that, we need to edit the Samba configuration file:
sudo nano /etc/samba/smb.conf
Scroll down about 300 lines, and you'll see a section called [printers]. We're not going to add any printers, but you can look at that section and how it's laid out. We're going to add a new section below it, but leave the printers stuff there. Add the following lines:
[Archive.org-Music] comment = Archive.org Music Share path = /media/flash4gb/music guest ok = yes browseable = yes create mask = 0600 directory mask = 0700
Again, press Ctrl-O to save, Ctrl-X to exit.
Now let's restart Samba to read our new configuration.
sudo service samba restart
Now if we navigate to the Raspberry Pi from the network, we can see the files are there from the flash drive and happy.
Now we're ready for minidlna, a lightweight and simple DLNA server that will stream to network devices, specifically my TV. First, let's install minidlna with apt-get, confirm when it asks with a press of the Enter key.
sudo apt-get install minidlna
Now that it's installed, we need to setup the folder in minidlna.conf
sudo nano /etc/minidlna.conf
We're going to add a line that looks like this:
We will also comment out the line that looks like this:
Now it should look like this:
We're telling minidlna which folders have media to stream, and the A stands for audio. If you had one with video, we'd change it to a V. Hit Ctrl-O to save, Ctrl-X to exit.
Now we need to launch minidlna the first time with a -R to get it to build the library. Run this command:
sudo minidlna -R
Depending on the size of your library, this could take several minutes. For me, I only have a few albums here, so it indexed right away. Finally, let's restart minidlna one more time:
sudo service minidlna restart
Go check your local DLNA client. For me, it's the TV.
Now that we have it running, it's time to tinker with it! As you can probably tell from the first photo, the cables weigh more than the Raspberry Pi itself. I needed something to anchor it to, and I figured that new 3TB hard drive would do the trick. So I carefully drilled a few holes...
Then I mounted a couple generic standoff screws to it. I carefully screwed on the standoffs- the plastic is very soft and I did not want to strip the threads. Then I mounted the Raspberry Pi using a couple small PC screws.
After that, I wired it all back up.
And that's it! Please remember to check the parts list for links to pick up the parts, and a big shout-out to Adafruit!
Follow up: I shared this project on Adafruit's Show and Tell this last weekend. You can see it on YouTube here: