Friday, February 29, 2008

Hardware Assembly and Installation

This section of the tutorial shows the steps I took to build the box itself.

As a side note, it's always a good idea to plug in the motherboard to the power supply before getting started and turning it on to ensure the motherboard isn't dead on arrival. You should hear a beep if its working correctly... moving on...

Below is a picture of all the hardware that went into the box. The list of this hardware is on the previous page.











The first step was installing the processor on the motherboard. This is usually pretty simple to accomplish and usually just entails lining up the processor (making sure the symbol on the corner matches the symbol on the motherboard to ensure its oriented properly), and turning the lever to lock the processor down.





Next I added the fan onto the top of the processor. Some processor / fan combinations require using an insulating gel of some kind. This particular fan has a thermal pad on the bottom and does not require that anything be added between them. Lock the fan down by following the instructions that came with the processor and plug the fan in.







Once this is done, its time to add the RAM. This is pretty self-explanatory...





Now it's time to insert the motherboard into the case. Below is a picture of the case I'm using.





Before I inserted the motherboard, I first had to remove the I/O panel on the back of the case and insert the one that came with the motherboard.





Now that that's done, it's time to place the motherboard into the case and screw it down.








Now that the mobo's in... the real fun begins. The next thing I did was I installed the video card. They are pretty easy to install... just insert into the PCI slot (for PCI cards).

Here's a couple pics of the nvidia 8500GT before and after install.








Next I installed the CD/DVD drive and the floppy drive. I popped off the front of the case and removed the panel-covers that were covering the slots for each. Then I inserted the drives and locked them into place. (on my case this is as simple as turning the locking handles. some cases make you screw them into place)











Once those are in, it's time to start inserting hard drives. As i described in the overview... I'm going to be installing one 160gb hard drive to hold the operating system and applications as well as four-500 gb hard drives that are going to be setup as a RAID array and used for file storage.

Here's a picture showing the hard drives placed in the case. (the top one I had to place in a slot not generally used for hard drives... it still worked fine though)





Now it's time to start on connections. I urge you to refer to your motherboard instructions for specific instructions on how to setup all the connections.

I first connected the cables leading to the front power-button, USB connections, and indicator LEDs. These generally go in / near the F_panel.





Then it was time to start connecting all the SATA (and my one non-SATA device, the floppy drive). The picture probably doesn't do this justice but it should be relatively self explanatory. Find your SATA ports on your motherboard and connect them to your various SATA devices (in my case the 5 hard drives and the CD/DVD drive) via SATA cables. As a side note... my motherboard only came with 4 SATA cables for the 6 SATA slots it has, so I had to pick up two additional cables.

I also connected power cables to all the various devices, including the hard drives, floppy and CD/DVD drives, motherboard and fan.





Once all your connections are established, you're ready to fire it up and test it out. I recommend leaving the case off for a bit because you'll need to go back in and unplug things later in this tutorial. Also if you messed up any of the connections, you can get back in faster to fix them.

Here's a picture of the finished case sitting next to my sub woofer. (complete with stickers - though I'm still waiting on my ubuntu stickers)





Here's a picture of my entertainment center with its latest addition (bottom right). Sorry it's kinda dark.







Continued: Operating System & Hard Drive Configuration

Auto-startup of LIRC and Elisa

The next thing I wanted to do was have all of this startup by itself when I turn on my computer. That meant making the media-user auto-login, getting LIRC to start up and then getting Elisa to start up... all automatically.

First I made it so my media-user logs in automatically at startup. I believe you can access this screen in the System menu somewhere, but the location escapes me.

So I did it this way, open a terminal and type:

sudo gdmsetup

This will bring up a window with login preferences. Select the security tab, check "Enable automatic Login" and select the media-user.

Now your media-user will auto-login when the system boots. You can always change users once you're logged in if you would like, but I just use my remote connection instead and leave the media-user logged in all the time.

The next step is to get LIRC to start up automatically. Because the command to start LIRC requires root access (sudo), you need to give yourself permission to execute the command without a password.

To do this, type the following in the terminal:

export EDITOR=gedit && sudo visudo

Change the DEFAULTs line to be:

'Defaults !lecture,tty_tickets,!fqdn,env_keep+="DISPLAY HOME"

At the very end of the file, add the following line (replacing username with your username)

username ALL = NOPASSWD: /etc/init.d/lirc start

Save and Exit.

Now go to system -> preferences -> sessions and add a new startup program. Name it LIRC or something and give it a description if you'd like. For the command use:

sudo /etc/init.d/lirc start

Now the LIRC utility will start (enabling your remote control)

In order for elisa to start automatically, you have to also add it to the session -> startup programs. However, if you just type elisa in there, it will startup before your lirc gets a chance to start up, and the remote wont work.

There may be a better way to do this, but this way works and its easy.

I wrote a simple bash script 'elisa-start' in my media-user's home directory.

vi ~/elisa-start

Add the following in the file:

#/bin/bash/
sleep 15 && elisa

This script, when executed, will wait about 15 seconds, and then execute Elisa. I don't recommend going much faster than 15 or elisa boots before LIRC initializes.

To modify the permissions on the file so everyone can access / execute the file, type:

sudo chmod 777 /home/username/elisa-start

Now go back to system -> preferences -> sessions and add another new program. Call it elisa and add a description if you'd like. For the command use (replacing username with your media-user's name):

/home/username/elisa-start

That should do it. You can try restarting X (ctrl - alt - backspace) to test if the LIRC + Elisa startup works correctly, or you can restart the computer to make sure the user auto-logs in and the LIRC and Elisa start-ups work.



Thats it! You're done! Have fun!

Setting up a Remote Connection

One piece of functionality I wanted was the ability to log in remotely and run applications while I'm watching a video in Elisa.

The first step to this process was creating an additional user, which is pretty self explanatory. Basically I will have two users, a remote-user, which I will use for running applications, downloading, surfing the net, or whatever else; and a media-user, which will run Elisa.

So to create another user go to System -> Administration -> Users and Groups and add a new user. Make sure to make this user an administrator.

Now that you have two users, the next step is to install NX server. This will serve as a Remote Desktop server that you can connect to from any other machine that has the client installed.

Before you install NX Server, make sure to install ssh first:

sudo apt-get install openssh-server

To install nx server, visit the following web site:

http://www.nomachine.com/download-package.php?Prod_Id=5

You'll need to install the client, node, and server (in that order) on the host machine. Click the download buttons to download and install each of the programs.

To start the service, just enter the following in the terminal:

sudo /usr/NX/bin/nxserver --start

That should do it. The service should automatically start itself in the event of a reboot / shutdown.

To connect to your machine from another computer, go to the same web site on the other computer and download just the NX Client.

If you're setting this up on a laptop, I recommend setting up two connections, one to be used when you're home and on the same LAN, and one to be used when you're away from home.

Open the client and the connection wizard will pop up. To setup the home connection, type in a name for the connection (can be anything), for the host, type in the local IP address (generally 192.168.1.???), leave the port at 22 (unless you changed it), and select LAN for the connection type. Save the connection and when the login screen comes up, enter the login / password information for the remote-user you created on your media center PC.

To setup an away-from-home connection, open the client again to see the connection wizard. Again type in a name for the connection, the IP address of the computer (you may have to look this up as most people have dynamic IP addresses - there is an alternative method I will discuss in a minute), leave the port as is, and select ASDL (most likely) for your connection type. Save the connection. You will again be prompted for login information and again enter the login / password for the remote-user on your media center PC.

The alternative to using an IP address (which often changes) in the above step is to use a dynamic DNS service. I use no-ip's free ManagedDNS service: http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html

Register for this free service from your home network, and you won't have to remember your IP address anymore. You can select a user name and a domain name (like 'myuser.no-ip.org') and can enter that instead of the IP address in the above step. Just make sure to forward port 22 in your router to the correct local machine. (this means using a static IP address on your local network). This will also work for ftp-servers or web servers or whatever. It basically is a domain configured to route traffic to your router. When you type in a port, your router will forward it to whatever machine you've specified in your router settings.



Continued: Auto-startup of LIRC and Elisa

Setting up the Remote Control (LIRC)

Now I want to setup a remote control to navigate through Elisa instead of using the mouse. I chose the standard windows media remote control and receiver because it is one of the most supported remotes available.

For a list of supported remotes, visit: http://www.lirc.org/

Plug in the receiver for the remote control (usually USB).

The following information is available from this tutorial for installing LIRC on Ubuntu (Gutsy): https://help.ubuntu.com/community/InstallLirc/Gutsy)

Install lirc by opening a terminal and typing:

DEBIAN_FRONTEND=gnome sudo apt-get install lirc

After the install, you can test the remote by typing 'irw' in the terminal. This will appear to make the terminal "hang".

Press buttons on the remote control. You should see them come up on in the terminal. To end testing, hit 'ctrl-c'.

Now you need to map the buttons on your remote control to the application you're using.

Install the button mappings application which will generate mapping files (lircrc files) for MythTV, Xine, MPlayer, VLC, Totem, & Elisa by running:

sudo apt-get install mythbuntu-lirc-generator

I used the following command to generate just the elisa lircrc file in the current directory.

mythbuntu-lircrc-generator -l ./elisa.lirc --mythtv 0 --mythtv_lircrc 0 --mplayer 0 --totem 0 --xine 0 --vlc 0 --xmame 0 --xmess 0

I posted the file I used here if you want to use that instead of generating one.

If you want to generate all the lircrc files for the above applications, run this instead:

mythbuntu-lircrc-generator

Copy the generated elisa lircrc file (I renamed mine to elisa.lirc) to this directory:

/usr/lib/python2.5/site-packages/elisa/plugins/lirc_plugin/data/lirc

Edit the lirc_input section of the elisa.conf file (in ~/.elisa/) so it looks like this:

[lirc:lirc_input]
# filename of the LIRC config map to use
lirc_rc = 'elisa.lirc'

You also need to start the LIRC application by running:

sudo /etc/init.d/lirc start

Now to test it out... Start up Elisa and try navigating through the menus with your remote control.


Continued: Setting up a Remote Connection

Setting up Elisa Media Center

First add the Elisa to your software sources.

There's a page with the different sources here: https://code.fluendo.com/elisa/trac/wiki/Packages

Go to System -> Administration -> Software Sources and click on the Third Party Software tab. Click Add and enter (for Gutsy):

deb http://elisa.fluendo.com/packages gutsy main

Then you need to add the key... open a terminal and enter:

wget http://elisa.fluendo.com/packages/philn.asc -O - | sudo apt-key add -

Next do an update:

sudo apt-get update

Now you're ready to install elisa. In the terminal type:


sudo apt-get install elisa-extra
or
sudo apt-get install elisa

I recommend getting elisa-extra as it has some extra plugins etc... After it's done installing, it will be ready to run by going to Applications -> Sound & Video -> Elisa Media Center, or just typing Elisa in the terminal.

By default, Elisa uses the audio / video / image folders in your home directory as your media library. If you're like me and want to use a different location, like the RAID array you just setup, you can modify the elisa.conf file to add additional locations. The elisa.conf file is located in /.elisa/ directory in your home directory. Before editing this, you should close elisa (hit escape).

To edit elisa.conf:

sudo vi ~/.elisa/elisa.conf

I configured elisa.conf to include additional media locations. There's a simple explanation on the elisa wiki site at: https://code.fluendo.com/elisa/trac/wiki/FirstRun

My modifications look like this. I modified the locations_builder section as follows:

[xmlmenu:locations_builder]
locations = ['file:///mnt/raid/movies','file:///mnt/raid/audio', 'file:///mnt/raid/images']
auto_locations = 0

[[file:///mnt/raid/movies]]
label = 'Movies'
only_media = ['video']
location_type = 'local'

[[file:///mnt/raid/audio]]
label = 'Music'
only_media = ['audio']
location_type = 'local'

[[file:///mnt/raid/images]]
label = 'Pictures'
only_media = ['image']
location_type = 'local'

The locations line is where you add the folders you'd like to include in your media library. I also set auto_locations to 0 so it doesn't try to search for additional media. The next three sections, which are named after each of the locations I added, provide some additional detail for each location. The label is simply the name that will be displayed for that folder in Elisa. You can restrict in which section that folder will appear in the field 'only_media'. My movies directory, for example, will only show up under Videos in Elisa. The location_type should be set to local unless you are attempting to access a networked location.

At this point, you should be able to run Elisa, go into the different categories (Music, Video, Images) and see your folders.


Continued: Setting up the Remote Control (LIRC)

Setting up the RAID Array

Start by installing mdadm. Open a terminal and type:

sudo apt-get install mdadm

Once this is installed, run 'cfdisk' in the terminal to setup partitions on the RAID disks. For each hard drive that will be included in the RAID array (NOT the disk with the OS already installed), use the following partition settings:

*NOTE* each disk must have the same partition size

- use 1 primary partition, entire size of disk
- Type: 'FD' - Linux RAID autodetect

At this point you're ready to create the array.

Use the following command to create the array, which will be called /dev/md0. (replacing the number of raid-devices with the number of disks you're using and the list of hard drives at the end with your disks)

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1

This will start a 'syncing' process that you can monitor with the following command:

cat /proc/mdstat

Stop at this point! Keep running the above command periodically until resyncing is complete. It usually gives you an estimated time left. Once the resync is complete, continue...

Now you need to format the array. Run the following command to format /dev/md0:

sudo mkfs.ext3 /dev/md0

Once this is done, you need to create the config file.

Run the following command to create this file:


sudo mdadm --detail --scan --verbose > /etc/mdadm/mdadm.conf

You're almost there, the next step is to create a mount point for the RAID array. This is the physical location you will access your array and can be located almost anywhere. I made mine at /mnt/raid/.

First create a directory for the mount point:

sudo mkdir /mnt/raid/

Next you need to edit the fstab file to ensure the array will be mounted automatically on boot. To edit the file, run either:

sudo vi /etc/fstab
or
sudo gedit /etc/fstab

I would recommend the latter if you're not familiar with vi editing.

Insert the following line into the fstab file: (replacing my mount point with the one you used)

/dev/md0 /mnt/raid/ ext3 defaults 1 2

You should also comment out any lines referring to any of the drives that make up the array.

Now you just need to mount the new RAID array. Run:

sudo mount /dev/md0 /mnt/raid/

And you're done! The RAID is now setup and available at the mount point (/mnt/raid/ or whatever mount point you used) When you navigate to this directory (I setup a shortcut to it on my desktop), you'll notice the available space in the window status bar. I ended up with 1.37 TB's of space available in my RAID-5 array, which doesn't include the disk space available on the disk containing Ubuntu.


Continued: Setting up Elisa Media Center

Operating System & Hard Drive Configuration

This tutorial starts where the hardware installation leaves off...

Connect the hard drive that will contain the Operating System (and make sure the hard drives that will be in RAID are disconnected to simplify things).

Boot the system with the Ubuntu Live CD and follow the instructions to install Ubuntu.

After installing the Operating System and optionally installing any suggested updates, turn the computer off.

Connect the hard drives that will be setup in the RAID array. You have some choices at this point. You first need to decide whether to do a hardware or a software RAID. I chose software because it is easier to setup with Ubuntu and if I want to migrate the RAID array to another machine later, I just need to install the same software (as opposed to a hardware RAID where you would need the exact same motherboard). There are benefits to both types. Once you've made that decision, you should decide what RAID level you want to use.

In general, RAID-1+0 (or RAID-10) is accepted as the best RAID level available. This type of array offers exceptional failure-recovery while still maintaining a high level of performance. The only downside of RAID-10 is that it requires at least 4 drives and requires that half of them are used for parity. So in my case, using four, 500gb hard drives for the array, only two of them would be usable space, leaving me with around 900 gb's of usable space.

If you're like me and don't really like the idea of buying almost 2 TB's worth of space to only get 900 gb's out of it, I would suggest using RAID-5. There are some disadvantages to this RAID level. For one, array recovery is a little more challenging in RAID-5 compared to RAID-10 should you experience a failure. Also, small disk-writes will be faster in RAID-10 compared to RAID-5 (as you're writing to 3 disks for every write in RAID-5 compared to 2 in RAID-10). However, since I'm essentially just going to be downloading and playing media, I'm not overly concerned with these small performance differences. If you were using the array for more heavy-computing, I would suggest RAID-10.

So in summary, I chose a software, RAID-5 array. Moving on...

You may have to modify your hard drive boot order settings in the BIOS at this point to ensure your hard drive with the Operating System will try to boot first. Generally the hard drive boot order settings are in the Advanced Options in the BIOS. Move the hard drive with Ubuntu loaded on it to the top of the list, save and exit.

Boot up and log into Ubuntu.

Continued: Setting up the RAID Array

Tutorial Overview

I'm putting together a tutorial for building / installing / and configuring a linux-media-box. The system will be using a hard drive containing the Operating System (Ubuntu - Gutsy) as well as 4 additional hard drives setup in RAID-5.

Basically what I wanted to do was have a media-box using my TV as its monitor. The media-box will use Elisa as a media center front end with a M$ media remote control to navigate. I also wanted to have a user I could remote into from my laptop and run applications "behind the scenes" while the media center was running on the TV.

So here's how to make all that happen!


Here's a list of the hardware that was used:

  1. 1x - GIGABYTE GA-M57SLI-S4 rev. 2.0 Socket AM2 NVIDIA nForce 570 SLI MCP ATX AMD Motherboard

  2. 1x - AMD Athlon 64 X2 4800+ Brisbane 2.5GHz 2 x 512KB L2 Socket AM2 Processor

  3. 4x - Western Digital Caviar SE16 500GB 7200 RPM 16MB Cache SATA 3.0Gb/s Hard Drive

  4. 1x - Western Digital Caviar SE 160GB 7200 RPM 8MB Cache SATA 3.0Gb/s Hard Drive

  5. 1x - Thermaltake Wing RS 101 Black / Silver ATX Mid Tower PC Case with 430W Power Supply

  6. 2x - Patriot Signature 1GB DDR2-800 CL 5 Desktop Memory

  7. 1x -EVGA nVidia GeForce 8500GT 256MB DVI/HDCP PCI-Express Video Card

  8. 1x - SAMSUNG Black 20X DVD+R 8X DVD+RW 12X DVD+R DL 20X DVD-R 6X DVD-RW 12X DVD-RAM 16X DVD-ROM 48X CD-R 32X CD-RW 48X CD-ROM 2MB Cache SATA DVD±R Burner

  9. 1x - SONY Black 1.44MB 3.5" Internal Floppy Drive Model MPF920 Black

  10. 1x - Microsoft Media Remote & Receiver

The tutorial was broken up into the following sections:

So let's get started: Hardware Assembly & Installation