Tuesday, February 9, 2010

Building a Junk Yard Network Attached Storage (NAS) Server (Part 1)

For a while now I have been searching for a NAS (Network-Attached Storage) appliance for my home office -- one that is inexpensive, supports CIF, AFS, Subversion, and above all, is quiet.  I didn't find one, so I built one.

For a while I've been starting to bump into the upper limits of my disk storage.  The storage needs of my paperless home office was quickly outgrowing my current disk capacity, causing me to be constantly trolling for files to delete.   The combined with multiple subversion repositories, VMWare virtual hard drives, developer kits, SDKs and operating system distribution ISO images was quickly consuming my local hard drives resources.

Still, I resisted the urge to throw down the cash for a NAS appliance.

However, when my quirky 1TB SimpleTech USB drive (I do not recommended purchasing SimpleTech's external drives by the way) started throwing I/O errors, and I couldn't get it to format, I knew it was time to start searching for something better. 

My critical data was safely stored on RAID-1 array, but I knew from experience RAID sometimes provides a false sense of security.  With a sense of urgency, I again started looking at NAS appliances. 

naspricesAt first, I looked at a variety of 4-bay NAS appliances.  The least expensive 4+ bay NAS (Promise NS4300N SmartStor) was priced at $292.99, and the most expensive was the ReadyNas 4TB was priced at $1479.99.

What surprised me most was that the reviews of these appliances have an average three stars (out of five).  Furthermore, in every model I investigated there were complaints about quirky firmware issues, extraordinary disk format times, poor tech support, and above all, poor performance.

Clearly, there had to be a better way.

I ultimately ended up salvaging parts from various dead PCs to create an inexpensive "Junk Yard NAS."  I junked a total of 3 PCs and kept the most modern -- the Althon64 (3800+) powered HP Pavilion a1510n.  The Athlon 64 3800+ came out in 2004 with a frequency of 2.4GHz and 512KB of L2 cache.  Clearly, we aren't going to win any races here.  I also purchased two (2) 2TB drives for an all in cost of $400.

Take 1: Gentoo (Goodbye RAID, Hello Nightly Disk to Disk Backup)

First, I installed Gentoo.  Within a few hours I had a fully functional, but minimal system.  I installed Gentoo on the first drive and broke the 2 TB drive into three partitions: a boot partition, a swap partition, and a data partition. 

Next, I started to make a  clone of the system drive.  In the event of a drive failure, I could just pull the drive and use the backup as a boot drive.  This would be especially important when the second drive was in a removable drive tray I could take with me in the event of a fire or other disaster.

   1: dd if=/dev/sda of=/dev/sdb

Unfortunately, I quickly figured out that doing a nightly disk to disk backup (with the dd utility) of a 2TB drive would take weeks at 20MB/second.  A nightly disk to disk backup would be impossible.

Take 2: Gentoo (Goodbye dd, Hello rsync)

Next, I used fdisk to parition the second disk.  For convenience, I copied the boot partition:

   1: dd if=/dev/sda1 of=/dev/sdb1

Next, I formatted the data partition, mounted the second disk and then used rsync to copy the contents of the root directory to the second drive:

rsync -ax --delete --force --exclude /mnt/mirror / /mnt/mirror/

Lastly, I setup a nightly cron script to copy the system disk to the backup disk.  It worked flawlessly for several weeks until I decided to try out FreeNAS (see the next part).

Labels: ,

Monday, September 14, 2009

Gentoo: Recovering from installing a bad kernel

Arguably, Gentoo is the best Linux distribution available.  If you have patience and don't mind tweaking you can have a system that is built from the ground up with only the features you want with a minimum of what you don't.  However, for new users, it can be intimidating. 

The price of being able to build a system and kernel with exactly the features you want (my kernel is down to 3.1MB), there are some pain points.  The biggest headache is that after spending time configuring the kernel and you reboot only to get a kernel panic.  Here is how to get back to recompile the kernel. 

Insert the CDROM and boot.  At the livecd prompt remount your drives (swap out sda with your device):

# swapon /dev/sda2
# mount /dev/sda3 /mnt/gentoo
# mount /dev/sda1 /mnt/gentoo/boot

Next, mount the proc and dev mount points, and then change root:

# mount -t proc none /mnt/gentoo/proc
# mount -o bind /dev /mnt/gentoo/dev
# chroot /mnt/gentoo /bin/bash
# env-update
>> Regenerating /etc/ld.so.cache...
# source /etc/profile

Now you can work on getting the kernel.

# cd /usr/src/linux
# make menuconfig
make && make modules_install
make install

(change the grub.conf file)
exit
umount /mnt/gentoo/proc /mnt/gentoo/dev /mnt/gentoo
reboot

Labels: ,