Configuring the raid array

This article is part of a series about setting up a home server. See this article for further details.

Most of this can actually be achieved with the GUI these days, RedHat’s disk utility has improved a lot since the version that was included with karmic. To load it go to Settings > Administration > Disk Utility.

Make sure all the disks to be used have no partitions on them, then go to Create > Raid array.
512KiB was the default stripe size and is what I used initially, but I later switched to a 128KiB stripe. The example below uses a 512KiB stripe.

Also, it is a good idea to reduce the size to 128mb or so below the max capacity. Drives of the same advertised capacity can vary slightly in actual size, and if you replace a disk you don’t want the rebuild to fail because the drive is a few megabytes too small.

After selecting the disk members and pressing create the array will be in a “degraded” state until all the disks are synchronised. The amount of time it takes depends on the size of the array, but I’d suggest letting it finish before proceeding, I received errors in disk utility if I tried to create a partition too soon.

Also note that I’ve used the GPT partitioning scheme. GPT is designed to replace the old MBR scheme which has some limitations and can be restrictive these days, so I elected to use GPT. MBR is a safer option if your array is less than 2TB. If you use new hard drives with 4096-byte sectors such as Western Digital “advanced format” drives, you should use GPT. The use of GPT means that fdisk cannot be used, because it doesn’t support it. In its place we use parted and gdisk (“aptitude install gdisk” if you don’t yet have it).

Creating a partition on the array

The only slightly tricky part is creating a partition that is aligned with the raid stripe. You can’t create a partition starting at sector 0 because that’s where the partition table lives, so disk utilities will always offset the start of the first partition. However in order to get the best performance you need to align the partitions with the stripe size.

After creating a partition with disk utility I was greeted with the following:

It appears that disk utility isn’t quite intelligent enough to create properly aligned partitions on its own just yet.

In my case the partition was offset by 17.4KiB, which doesn’t align with the stripe size of 512KiB:

I found the easiest way to get a properly aligned partition was to create a partition in disk utility with no file system, and note the offset given to you by the warning message that appears after the partition has been created. Then, simply delete the partition and use gdisk to create the partition with the original offset plus the figure given to you in the warning.

To get the existing offset, run “parted /dev/md0”, type “unit b” to switch the working units to bytes and type p to print a list of partitions on the volume.

In my example the original offset was 17408 bytes (34 sectors * 512 bytes/sector), and the partition was out of alignment by 506880 bytes. This means it should actually be at byte 524288, which also happens to match the stripe size of 512KiB.

gdisk works in sectors however, so we need to divide the result by 512, giving sector 1024 (524288/512=1024). So in this example you would run gdisk, type n to create a new partition, enter 1024 for the first sector, and accept the default for the last. For the current type I used code 0700, which is “Linux/Windows data”.

The second time around I used a stripe size of 128KiB (it seemed more “normal”), and with this stripe you would offset the start of the partition by 256 sectors (131072 bytes). I don’t believe the stripe size matters much – larger stripe sizes probably perform marginally better with larger files but I wanted something more general purpose as there will be a lot of small documents as well as large photos.

An example of creating a partition in gdisk follows. Note that I’m using /dev/null in this example to avoid destroying my laptop, you would probably want to use the actual blank raid array, which is likely to be /dev/md0. You can delete partitions with gdisk (with d), but for the newbies it’s probably easier to delete any previous attempts in the gui disk utility first.
sudo gdisk /dev/null
GPT fdisk (gdisk) version 0.5.1

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-18446744073709551582, default = 34) or {+-}size{KMGT}: 256
Last sector (256-18446744073709551582, default = 18446744073709551582) or {+-}size{KMGT}:
Current type is 'Unused entry'
Hex code (L to show codes, 0 to enter raw code): 0700
Changed system type of partition to 'Linux/Windows data'

Command (? for help): w

Final checks completed. About to write GPT data. THIS WILL OVERWRITE EXISTING
MBR PARTITION!! THIS PROGRAM IS BETA QUALITY AT BEST. IF YOU LOSE ALL YOUR
DATA, YOU HAVE ONLY YOURSELF TO BLAME IF YOU ANSWER ‘Y’ BELOW!

Do you want to proceed, possibly destroying your data? (Y/N) Y
OK; writing new GPT table.
The operation has completed successfully

Creating the file system

Next create the file system on the partition:
mkfs.ext4 /dev/md0p1

I haven’t yet investigated tuning an ext4 partition for raid 5 arrays. There are probably some tweaks to be made here, please comment if you have a suggestion.

Autostarting and mounting the array

At this point you should have a working raid array, shown as running in disk utility and an ext4 partition on the disk. If you reboot you will notice that the array doesn’t start automatically, you have to go into the disk utility and start it manually each time.

Getting it to start by itself also requires falling back to the command line. Make the array is running before proceeding.

First we need to get the config line:
mdadm --detail --scan
You should get a line like the following:
ARRAY /dev/md0 level=raid5 num-devices=4 metadata=01.02 name=:Raid5 UUID=7198dc4b:0b61431d:99f71126:c2d41815
Paste this line into /etc/mdadm/mdadm.conf, below the line that says “definitions of existing MD arrays”. Reboot, load disk utility and you should see that your array has been started automatically.

Automounting the file system on the array simply involves putting a line in /etc/fstab, which unfortunately every technical Linux user still needs to know about (it seems to be the most prominent legacy hangover, but it’s still a pretty good system when you know how it works). My line is as follows:
UUID=47b4d934-c0c3-46c6-b9f7-09c1c7a94774 /media/data ext4 rw,nosuid,nodev 0 1
Note that the UUID here is the UUID of the partition and not the raid array. To get the UUID of your partition, use the command “sudo blkid” and note the UUID of the partition on your raid array, which should be /dev/md0.

Another useful command is “cat /proc/mdstat” which gives some info about active arrays.

You shouldn’t need to create the mount point in /media, in my experience this happens automatically.

Next part – Creating user accounts and setting up the file shares

OS and package installation

This article is part of a series about setting up a home server. See this article for further details.

I did a simple install of Ubuntu using the alternate media written to a USB stick. You could use the ordinary desktop CD, or Ubuntu server (but you will need to install a lot more packages on the server version). I did not configure the raid arrays on install. The reason for this is that I didn’t have all the disks ready, but I didn’t want to install OS data on them anyway.

Installing packages

For media playback, the medibuntu repository is essential. See the Medibuntu site for more info, but the commands I used (lifted straight off the Medibuntu site) are:
sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update

sudo apt-get --yes install app-install-data-medibuntu apport-hooks-medibuntu

Next I installed some additional software:

aptitude install openssh-server backintime-gnome gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg ntp samba winbind libpam-smbpass apache2.2-bin lib-apache2-mod-dnssd mdadm

Some of these warrant explanation:

  • The gstreamer plugins packages are codecs, which may or may not be legal in your country depending on its stance on patents (like anyone really pays an attention to that). However you need to ensure you have codecs available for any media you wish to play back.
  • ntp is for time synchronisation, which isn’t strictly necessary in a home environment but I like to have an accurate source of time on any network.
  • samba, winbind, libpam-smbpass, apache2.2-bin, lib-apache2-mod-dnssd are all related to file sharing. Winbind allows the system to lookup other hosts with Netbios, which Windows uses on small networks without a local DNS server (like most homes). I don’t feel it is necessary to provide a DNS server in a home with non-technical users, and to me it is for a network appliance such as an ADSL router to handle anyway.
  • apache2.2-bin and lib-apache2-mod-dnssd are required for the “personal file sharing” control panel in Gnome to work. The developer has stated that the Apache won’t be required in the future (see this bug report for details. You may not need this functionality for your home server, but I thought it was nice to have in case it’s needed.
  • mdadm is for raid
  • gdisk is for partitioning GPT partition tables. If you prefer to stick with MBR partition tables you don’t need this

Installing NeatX

NeatX is a free implementation of NoMachine’s nx server, originally written by Google for an internal project. It seems to be the easiest and quickest way to get going with Windows RDP equivalent functionality, in fact it’s just a few lines:
add-apt-repository ppa:freenx-team/ppa
aptitude update
aptitude install neatx-server

Next simply download the client from nomachine.com and away you go. There are a few rough edges and I have encountered errors on reconnect, but it’s good enough for me. It is much more efficient than VNC, and the speed increase is more than enough for me to put up with the bugs.

Internal Errors on reconnect

If you encounter internal errors when connecting, delete all directories from /var/lib/neatx/sessions. For some reason it isn’t always cleaning up properly, even if you logoff.

Next part – Configuring the raid array

An Ubuntu 10.04 Home Server

I’ve recently been setting up a home server for my parents using lucid. While it’s not quite a point and click setup process, the process is a lot more streamlined than it used to be.

They have an individual computer each running Windows 7 and, one laptop between them running XP. Mum is also a photographer and generates a large amount of data. Dad also generates a fair bit of data, less than Mum although he does do the occasional home video.

Backups are an ad-hoc affair. Mum has three hard disks in her computer which she manually copies files between and tries to ensure she has two copies of everything. Dad has a portable external drive which he backs up to infrequently. Between them, neither is confident that they’d get all their data back in the event of a disaster.

Dad also liked how my HTPC (running XBMC) worked, and decided one of those would be nice too. So I decided to setup a home server for them and solve all their computer problems. Well, almost.

I started writing this as a single article, but it got a bit long so I’ve decided to break it up into a series. This first post is an overview, the links to the other posts are at the bottom of this article.

I’m assuming a fairly good degree of technical knowledge here, but if there are any gaps you feel I should add please feel free to leave a comment. I am aiming this at a reader who is familiar with Linux and Ubuntu, has installed software with apt-get or Synaptic, is comfortable with using the command line, and understands the implications of using raid5.

Overview

This home server will perform the following tasks:

  • Play music and video via the TV
  • Present a file share to the network, with individual folders for Mum and Dad
  • Backup the contents of their folders nightly to an external hard drive
  • Provide a GUI-based remote administration interface
  • Monitor backups and the raid array, sending emails to both Mum and Dad if something is amiss

Software that needs to be configured to perform these tasks:

  • MDADM for RAID
  • Xbox Media Center (XBMC) for media playback
  • Samba for file sharing
  • Back in Time for backup
  • NeatX for remote administration

The main boot device in this case will be an IDE compact flash card. I did this partly because it makes recovery easier (just write an image to a flash card rather than a whole hard drive), but mainly because it frees up a SATA port!

The hardware components for this particular HTPC are:

  • Gigabyte M85M-US2H motherboard
  • AMD Athlon II 250
  • 2gb DDR2 ram
  • 4x640gb Western Digital 6400AAKS hard drives
  • 1x1TB Western Digital Green
  • 1x2TB Western Digital Green (in external esata case)
  • 4 Raidon/Stardom hotswap drive bays
  • IDE Compact Flash adaptor and 8gb 133x CF card

A note on raid

The 4x640gb drives are configured in a raid 5 array. Personally, this is about as large an array as I would trust Raid5 to, the future is redundancy at the file system layer, as ZFS and Btrfs are capable of. ZFS can’t be used in the Linux kernel and Btrfs isn’t even close to production-ready yet, so for now I believe Raid is still the most sensible option. But if you’re reading this in 2012, you should probably be using Btrfs instead.

Storage

The 1TB hdd is just a single disk for media to be played back on the TV. Anything here is considered replaceable (think of it like the internal HDD in a MySky or TiVO box), so it won’t be backed up at all.

The 2TB hdd is the backup drive. Each night the entire raid array is backed up to it with Back in Time, configured to take snapshots. Since it uses rsync, the backups are incremental and shouldn’t take more than a few minutes to run, depending on how much was changed during the day. Obviously as the array nears capacity fewer snapshots will be able to be kept, and once it does the idea is to replace the 2TB backup hdd with a new one, keep the old one as an archive, delete any data from the raid array that is no longer current, and start again with a fresh clean backup disk. Hopefully by then it will be a 3 or 4TB disk and they can keep more snapshots!

The file system on the backup HDD will be NTFS. This is because it supports hard links and is readable by the Windows machines, which is important for my parents when they go to retrieve files from the archive.

Final notes before we get to the nitty gritty

I had a bit of trouble getting the drive bays lined up with the ports that the OS reported they were attached to. This is important because if mdadm tells Dad that the sata disk on port x has failed, I need him to be able to know that it’s the disk in bay x. Unfortunately on the motherboard I used, Ubuntu assigns them like so:

0 – 1
1 – 3
2 – 2
3 – 4

(motherboard port – ubuntu port)

So while your motherboard may be better designed than mine, don’t assume they are in the same order. The links to the follow-up articles are below:

N900 – 3 months on

My last post on this blog was a review of the Nokia N900, and that was a whole quarter ago. The last 3 months have been hectic to say the least but I now have a lot more free time!

So how has the N900 turned out?

In short, OK.

My conclusion still stands – the N900 is not a suitable phone for most people, and it probably isn’t the best phone for me either. For developers of applications for Nokia’s QT platform it’s the reference device and thus an essential piece of kit. But the general public are better served by the existing Symbian range.

So what’s good and what’s bad?
Continue reading

Nokia N900 Buyer Review

I’ve had to think long and hard about this review. The N900 is unquestionably flawed, but it’s a leading edge device, and prescient in so many ways. It shows promise of things to come, and that promise is exciting. So does one knock it as a failed attempt at reclaiming the smart phone crown, or praise its foresight and anxiously await N900+1? Considering Nokia’s stance on the device it would perhaps be unfair to call it an attempt to retake the smart phone crown, as they never positioned it as such. But it does not deserve unreserved praise either.

To get my own personal bias out of the way – I want to love the N900. It’s a Linux-based smart phone built on open source software that doesn’t try to hide its roots. I’m a Linux geek and open source enthusiast. I dislike walled gardens such as the iPhone App Store and the artificial restrictions placed on the iPhone, so a 3GS was never an option. Android is a bit too tied to Google’s services (a company which already knows much more about me than I would like to admit), and while Nokia are certainly trying to push their Ovi suite of services, they would be foolish to make it difficult for you to use competing services. My credibility as a reviewer drops somewhat given my lack of experience in using Android, and quality time with an iPhone. I’ve had a play on devices owned by friends, but that’s not enough to get to know the ins and outs of a device.

So it’s with a bit of trepidation that I review the N900. My only real frame of reference is the aging Symbian S60 – an OS that has served us well, but is now past its use-by date and hardly the ideal operating system to compare it to.
Continue reading

It’s here!





Currently updating the firmware to the latest version, I’ll be writing a review once I’ve had a good play and am familiar with the device.

Initial impression: awesome.

Mozilla Prism – what’s the point?

Mozilla prism is a framework for packaging web apps as applications. It uses the gecko rendering engine and is basically Firefox without the user interface. My reaction upon first reading about it a couple of years ago was as per the title – this is just a web browser with a restricted interface, and thus offered no advantage over a simple desktop url shortcut.

But there actually is a good reason to use prism, and that is privacy. Prism uses seperate profiles for each application, thus if you are logged in to Gmail, you do not have to be logged in while using Firefox and have Google track all your searches in addition to indexing your email. You can use Facebook in prism and not have to worry about third party sites accessing your profile, like the much-maligned beacon “service” facilitated recently.

In short prism affords a lot of convenience for those of us that like to keep their web identities segregated, but if you’re really really paranoid about privacy then Gmail and Facebook are two sites you probably shouldn’t use.

On Ubuntu you can install Gmail for Prism with the following command:

  • aptitude install prism-google-mail

For Facebook:

  • aptitude install prism-facebook

Once the prism package is installed you can also convert any site into a prism app by going to Tools > “Convert Website to Application”.

Of Bioshock 2 and DRM

This is a game I’ve been anticipating and I’m sure I’m not the only one. I was all ready to pull the trigger on a pre-order but the DRM has given me pause.

First there’s the whole Games for Windows Live (GFWL) thing. It annoyed the hell out of me in Batman Arkham Asylum, and I’m not particularly thrilled about it here. Had I known what GFWL was when I bought Arkham Asylum I might have thought twice. I know Steam is a similar concept, but somehow it’s more tolerable, although if you buy Bioshock 2 through Steam you have to put up with both!

The game is also protected by Securom, and has a 15 activation limit enforced by GFWL. With Bioshock 1 this caused issues, and later on I believe they removed the limit (although back then the limit was enforced by Securom).

If you preorder the game it will cost $90 NZD boxed or $63 NZD on Steam. With the Steam version you effectively have to handle two (no wait, three) DRM systems – GFWL, Steam and SecuROM! It really doesn’t get much more ridiculous than that.

Boycott this is not, but I think I might vote with my feet here, even if I am in the minority. Or I’ll just wait until they remove the DRM and drop the price like they did for the original Bioshock.

My opinion of Steam and GFWL can be summed up thusly:

Steam serves the publisher while throwing the customer a bone, and while you give up some rights you do gain some conveniences. It is also cheaper.

GFWL seems to be designed to serve only the publisher, and is little more than an annoyance for gamers.

At least the pirates won’t have to deal with this crap.

More info at Arstechnica, the Steampowered Forums and the 2k Games Forums.

How Flickr ranks so highly on Google

Search Engine Optimisation (SEO) is such a murky topic, I almost cringe when I hear the term. It can be used to describe legitimate techniques such as organising your website into a structure that is easy for Google to index and renaming pages to describe their contents, but also dubious methods such as paying for links from other websites and blog spam.

Flickr uses an interesting technique. Googled for “photo sharing” lately? Flickr ranks number one, above the king of search results – Wikipedia.

How did they do it? Well here’s some html code that was generated by Flickr and posted to my blog when I clicked the “Share This” link:

<div style=”float:right;margin-left:10px;margin-bottom:10px;”>
<a href=”http://www.flickr.com/photos/al40/4241715457/” title=”photo sharing”><img src=”http://farm5.static.flickr.com/4045/4241715457_b72168688f_m.jpg” alt=”” style=”border:solid 2px #000000;” /></a>
<br />
<span style=”font-size:.9em;margin-top:0;”>
<a href=”http://www.flickr.com/photos/al40/4241715457/”>Foxdown 13</a>
<br />
Originally uploaded by <a href=”http://www.flickr.com/people/al40/”>Al404</a>
</span>
</div>
test post
<br />

The interesting part – note the value of “title” inside the name tag. What possible reason, other than SEO, could Flickr have to make the title of every single shared photo titled “photo sharing”? Every time you use share a Flickr photo this way, you’re providing a link to Flickr and boosting their name against that term. While this is certainly not as dubious as other SEO techniques, it’s also not in the spirit of the title tag or the value Google is placing on it.

Unsurprisingly, a Yahoo search also shows Flickr as number one, but Bing clearly ranks pages a different way – Flickr doesn’t appear in the first page when searching for the phrase.