Setting Up A SheevaPlug Media Server

Over the next few days I will be posting a series of tutorials on setting up a kick ass media server that is cheap, powerful, tiny and dead silent. For about $100 USD and an external hard drive you can set up a media server that streams to all the computers and gaming consoles in your house providing you with media wherever you are.

I have found that Marvell's SheevaPlug is the perfect candidate for a home media server. It can be purchased online from Global Scale Technologies. This $100 USD Plug Computer may seem intimidating to some at first due to its lack of a visual interface, but fear not, this series of tutorials should help familiarize anybody with the command line. I will walk you through the major steps and point out the errors I made along the way so you can avoid them.

The majority of the work I completed on this server took about a week total but the majority of that time was making mistakes and starting over. You should be able to get the full server up and running in a day or two following these tutorials....if not....I really didn't do a very good job. Feel free to leave comments along the way for each section. I'm more than happy to help out if you run into any troubles!

A great resource for information and how-to's is Plugcomputer.org's wiki. I will be referring to a few how-to's from there throughout the series.

This first section of the series is the longest and most complex by far though once you're done, you will have a fully functioning Unbuntu server to play with. In the next posts I will go over setting up each component of the media server.

Knowledge Requirements

  • How to move and interact with a computer through the command line
    • I will go step by step as much as possible but a little familiarity is always good to have
    • Having a CLI knowledgeable friend also helps for your first go, whether as a person to call or to have with you during the setup of the server.
  • Knowledge of a command line based text editor
    • I will be using Vim. Every computer comes with a copy of vimtutor, a text file that will teach you how to use the basic functions in Vim. I highly suggest you take 30 minutes to go through the file. Just type "vimtutor", without the quotes, in any command line environment. The file will take you through the rest.

The Hardware

Basic SheevaPlug Specifications

  • 1.2 GHz Core
  • 512MB Storage
  • 512MB DDR2 RAM
  • USB 2.0 Port
  • Gigabit Ethernet
  • SDHC Port
  • Physical Dimension
    • 110mm (L) x 69.5mm (W) x 48.5 mm (H) (Tiny!!)
  • Head to Global Scale Technologies to see a full list of specifications, photos and pricing.

External Storage

  • USB 2.0 Hard Drive
    • Recommended that it be at least 250 GB in size
    • You can currently pick up a 500 GB hard drive from Best Buy for under $100

Now this computer is no gaming rig, but as a media server, it will do quite well. You don't need a lot of resources to stream video and other content to a few devices at once. The whole computer is about the size of a medium brick of cheese. You can see in the photo that it is quite small compared to a Mac Pro. I currently have it just set up here for testing. It is also wall mountable it at the wall socket level.

Configuration Possibilities

The USB 2.0 port on this computer can be used for absolutely anything that has a USB interface such as a printer or hard drive. You don't even have to compromise with one or the other as you can use a USB hub to connect as many devices as you please.

I currently have a 250 GB hard drive that wasn't being used. For this project you will need external storage and, since you will be streaming media, you will need a lot of it.

The Software

The media server we are building here will use a version of Ubuntu Server. The SheevaPlug comes pre-installed with a version of the Ubuntu Server Operating system. The benefit of this is that you do not have to worry about installing and configuring the initial server. Necessities like SSH are already installed for you so that you can connect easily. On a traditional setup, you would have a monitor attached to the server for the initial install and configuration. At that point you would set the static IP and install tools like SSH. Since we can't hook up a monitor to the SheevaPlug, the pre-installed Ubuntu is needed with SSH installed.

SheevaPlug Setup

1. Finding your SheevaPlug on the network

My first hurdle was right out of the box as there is no way of attaching an external monitor to the plug computer. In previous setups, I always set up the static IP and SSH with a monitor first. The SheevaPlug comes pre-installed with a version of Ubuntu Linux and has SSH set up. The default setup for Ubuntu is to have a dynamic IP address given to it by your router. This is an issue if you want to SSH from another computer as you need to know it's IP. That's why we'll be setting it to static later.

In order to find the computer's current assigned IP, you need to go into your router setup. For my Linksys this meant going to 192.168.1.1 in my web browser. Depending on your router, this IP may differ. If you google for your router, you will probably find information for it within the first few search results. Once you have access to the settings in your router, you want to find the DHCP Client Table. I found mine under Status > Local Network > DHCP Client Table. This location will vary depending on your router and its firmware. Once you find it, you will see an entry for the SheevaPlug. It may not be named anything coherent but by a process of elimination you should be able to determine which IP is the SheevaPlug. Write down this IP as you will need it in the next step.

2. Connecting to the SheevaPlug

Once you have the SheevaPlug's current IP address, you can can SSH into the device by typing in command line "ssh root@IP" where IP is the address your device is currently assigned to. The default password for the SheevaPlug is "nosoup4u", without quotes. Once you have access you should see the view below:

   Linux plugserver 2.6.22.18 #1 Thu Mar 19 14:46:22 IST 2009 armv5tejl
    The programs included with the Ubuntu system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.
    Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
    applicable law.
    To access official Ubuntu documentation, please visit:
    http://help.ubuntu.com/
    Last login: Sun Feb 15 16:17:54 2009 from 192.168.1.110
    root@plugserver:~#

3. Initial Software Configuration

Out of the box, the SheevaPlug needs a few tweaks so that it can run smoothly. I followed the getting started how-to from PlugComputer.org found here. The main section to pay attention to is the "Fixing the existing Ubuntu install" section which can be seen below.

  • The DHCP client is configured to ignore any DNS servers returned by the DHCP server and use 127.0.0.1 instead, while there is no local DNS server. Consequently, you won't be able to connect to any hosts by name until you fix this. In order to fix it:
    • Edit /etc/dhcp3/dhclient.conf and comment out or delete the line "supersede domain-name-servers 127.0.0.1;".
    • Run "dhclient eth0".
    • Try "ping kernel.org" - it should work.
  • The directory /var/cache/apt/archives/partial which the APT package management system uses lives on a RAM disk, so it gets wiped on every boot. Marvell helpfully included a boot script to recreate the directory, but they not so helpfully failed to make the boot script actually work. Additionally, /tmp and /var/tmp have invalid permissions. To fix these problems:
    • Edit /etc/rc.local. The two insmod commands fail, and because the shell is invoked with the -e flag (see first line of the file), a failing command causes the whole script to exit. Delete or comment out all lines except "mkdir -p /var/cache/apt/archives/partial" and add "chmod 1777 /tmp /var/tmp" before the mkdir. You might also want to add, after the mkdir, a line "/usr/sbin/ntpdate-debian" to automatically sync your clock over the network.
    • Alternatively, replace /etc/rc.local with the following text:
   #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
              chmod 1777 /tmp /var/tmp
              mkdir -p /var/cache/apt/archives/partial
    # optionally uncomment the follwoing line to enable clock sync on reboot
    #ntpdate-debian
  • After editing, run "/etc/rc.local" from the command line.
  • The TimeZone is not set. To fix it, just execute the following command as root and select the appropriate timezone for you: "dpkg-reconfigure tzdata"

4. Setting a Static IP

By setting a static IP, you will be able to easily SSH into the SheevaPlug from now on. You will not have to consult your DHCP tables in order to find the assigned IP address of the server like you previously had to do. First you need to open the network interfaces file with the following command

   vi /etc/network/interfaces

For the primary interface, which will be eth0, you will see the following lines

   auto eth0
    iface eth0 inet dhcp

Currently the server is using DHCP which means it's local IP is assigned to it by the router. This is not good as it could change. You will want to make this file appear as I have it below. Note that your base network may be different. It's normally 192.168.1.0 or 192.168.0.0. This is the same IP that you used earlier to log into your router.

   auto lo
    iface lo inet loopback
    address 127.0.0.1
    netmask 255.0.0.0
    auto eth0
    iface eth0 inet static
            address 192.168.1.200
            netmask 255.255.255.0
            network 192.168.1.0
            broadcast 192.168.1.255
            gateway 192.168.1.1

After this, restart the networking components with the command:

   /etc/init.d/networking restart

Ping a website you know will work to make sure that you still have a connection. You local IP address of the server is now whatever you set in the networking file. Mine is 192.168.1.200. That last 3 digit number can be what you want, I recommend 200 as your router will most likely not try to assign this to any other computers on the network.....unless you have over 200 computers on the network. Just pick a number that you know will not be taken should the server be turned off or restarted.

Now the basics of your server are all set up. I recommend exiting from the shell with "exit" and SSH back in with the new static IP to make sure it worked. If not, find the dynamic IP like we did in step 1.

5. Adding Users

You now need some users, other than root, to work with. You can add as many as you'd like. The easiest way to add a user is with the command

   adduser username

Where username is the name of the user you'd like to add. It will then walk you through the next steps which include setting a password and full name. If there is information you do not wish to enter, other than password, just press enter on each blank line. It will confirm with you at the end that all the above information is correct.

If you log in as a user other than root, you will need to preface editing commands like "vi" with "sudo", or you can switch to the root user by typing "su" and entering the root password.

6. Setting up the Hard Drive

Since the SheevaPlug has very little internal memory, you will need to set up an external hard drive. This step was the most troublesome for me as sometimes the hard drive would not appear where it was supposed to be. After some fiddling, and many tries, I got it to work like expected. The hard drive I started with was formatted as Mac OSX Extended Journaled and was empty. You need to make sure you have all the data you want off the hard drive as the next few steps will completely erase it.

In a perfect world you will be able to type

   fdisk -l

and you will see the unmounted hard drive like so.

   Disk /dev/sda: 300.0 GB, 300090728448 bytes
    255 heads, 63 sectors/track, 36483 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x00000000
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1       36483   293049666   83  Linux

If this works like expected for you, you can skip to mounting the hard drive. If your hard drive did not show up, there are a few ways you can investigate what's going on.

The first place to start is to unplug the hard drive and type "dmesg" into the command line. This lists all the latest activity on the server. Don't clear this data just yet. Plug in the hard drive and run "fdisk -l" just to make sure it's still not showing up. If that's the case, run "dmesg" again and compare the two logs. You should see that a drive was mounted at the bottom. This will tell you that it is mounted but not necessarily what the drive directory is.

You will now have to do another comparison, but this time of a folder. Unplug the drive again and run the commands:

 cd /dev

then

 ls

This will show you the contents of the dev folder. This is were hard drives are initially stored before mounted. Plug in the hard drive and type "ls" again for this folder. Compare the two results and hopefully you should see a difference. For myself, I saw that there was another folder named "sda". That name is what you need to remember for the next few steps.

Next we're going to format the hard drive. Once again. make sure you have all information you want off of the hard drive. The following commands will assume your hard drive's "name" is "sda". Replace "sda" with your hard drives assigned name in the following commands. Run

   fdisk /dev/sda

This will start up fdisk which is used to format and partition hard drives. First we need to remove any existing partitions that are on the drive. Press "d" for delete and press enter.

Next we're going to make a new partition. Press "n" for new and press enter, then press "p" for primary and then 1. Then simply press enter for the next two questions as the defaults are fine. This will make 1 partition that takes the entire disk.

Lastly, press "w" for write and then enter. This will write the partition to disk. After this is completed you're ready to write a file system to the disk.

We're going to use the file system "ext3" for this drive. There are many options for this but ext3 is the easiest. Make the file system:

   mkfs.ext3 /dev/sda1

Note the 1 after sda. This means you want to apply the filesystem to partition 1 of sda. From now on when you refer to this drive, make sure you target the right partition and not the whole drive.

Next you want to mount the drive to a folder on your root file system. We're going to create an "external" folder in the root media folder.

   mkdir /media/external

Next we need to mount the hard drive to this folder with

   mount /dev/sda1 /media/external

Congratulations. If that all worked, the folder /media/external is your external hard drive. To see if it worked, type

   df -h

This will show you all the file systems on the server and where they are mounted. This is also a good way to see how much space is used in each section. Yours should look similar to mine below

   Filesystem            Size  Used Avail Use% Mounted on
    rootfs                507M  291M  217M  58% /
    tmpfs                 252M     0  252M   0% /lib/init/rw
    varrun                252M  596K  252M   1% /var/run
    varlock               252M     0  252M   0% /var/lock
    udev                  252M   20K  252M   1% /dev
    tmpfs                 252M     0  252M   0% /dev/shm
    tmpfs                 252M   35M  218M  14% /var/cache/apt
    /dev/sda1             276G   53G  209G  21% /media/external
    /dev/mmcblk0p1        938M  178M  713M  20% /media/sd

The last two lines in that display show the two drives I have hooked up. the /dev/sda1 is the external hard drive and the /dev/mmcblk0p1 is a SD card I have attached.

Next you want to make sure that the drive automatically mounts when you start the server. You'll want to edit the fstab file.

   vi /etc/fstab

Add the line

   /dev/sda1 /media/external ext3 defaults 0 0

to the end of the file. This will ensure that the drive mounts automatically should you have to restart the server.

Conclusion

By now you should have a fully set up Ubuntu server to work with. We've found the device on the network, set up the networking and added an external hard drive. These are the first steps to setting up your media server. The current state of your server can be used for anything you wish. In the next post, I will be going over how to set up a Samba File share server so that you and others without command line experience may interact with the files on the server through a GUI environment on your local computer.

Short URL: http://gl2.ca/a