Posts Tagged ‘server’

Software RAID On Linux

Sunday, August 3rd, 2008

A couple of months ago I scored a free computer from one of my brother’s friends because it was broken. It’s some kind of Pentium 4 with 500MB of RAM. With the addition of one of my spare video cards, it was perfect for a backup gaming computer (well, games like Warcraft and BF2).

I had been hosting a couple of websites off my windows Vista computer and decided to move all the server stuff over to that extra computer. So I installed the Linux distro Ubuntu Server on it and moved the computer into my wardrobe, where I administer it from an SSH shell.

I had been hosting a cool website called Ampache, a PHP + MySQL solution that indexes all your music and lets you listen to it anywhere, from a browser (with a login). So the server was serving up the music that was located on my Vista machine, and accessing the music through Windows File Sharing. This was not ideal if I wanted to turn off the Vista computer or play around with OSX86. The hard drive I had in the linux computer was a 40GB, so along with the linux stuff taking up about 5GB, there wasn’t enough space to copy all my music onto it.

So I stuck a spare 30GB hard drive in the server and read up on Software Raid for Linux.

I decided to use the RAID specification called ‘linear’, which basically works by appending partitions together. When the first partition is filled, the next one is used seamlessly, with it all appearing as one partition to the system. But I couldn’t use the 40GB partition which had the Linux operating system on it, otherwise I would lose all the data on that one.

I found a distribution of Linux on DistroWatch.com called ‘Parted Magic’. It’s about 50MB and just contains the tools required to partition your hard drives however you want. I resized the Linux partition to 8GB (non destructively) and used the remaining space for a secondary partition. Combined with the second hard drive and Software RAID, this would give me about 60GB – perfect storage on the server for my music.

Back in Linux now, the steps required for setting up Software RAID were surprisingly few.

  1. Identify the partitions / hdds you will be using for the RAID device, i.e. find out their device names (/dev/sdb1 etc).
  2. Backup your data
  3. Run ‘cat /proc/mdstat‘ to check whether your kernel has RAID support. if the file is non existent, then either your kernel does not support RAID and you need to change it, or you need to load the kernel module. If typing ‘modprobe md‘ is successful, you have loaded the RAID kernel module. You will need to make sure this module is loaded on bootup, so add the ‘md’ module to your kernel startup file. This may be at /etc/modules.autoload, /etc/modules.autoload.d/, /etc/modules.conf or somewhere similar.
  4. Install the mdadm tool by running ‘apt-get install mdadm‘ as root or superuser.
  5. Depending on which type of RAID device you want to setup, refer to the Software RAID Howto for the specific command. Disregard talk of /dev/raidtab and mkraid, just use the mdadm tool. The command I used for a Linear RAID of 2 disks was: ‘mdadm --create --auto yes --verbose /dev/md0 --level=linear --raid-devices=2 /dev/sdb1 /dev/sda3
  6. If that is successful, you will see something like ‘mdadm: chunk size defaults to 64K, mdadm: array /dev/md0 started.‘ This has created your RAID device at /dev/md0
  7. Create ext3 filesystem with ‘/sbin/mkfs -t ext3 /dev/md0
  8. Mount: ‘mkdir /mnt/raid && mount /dev/md0 /mnt/raid
  9. Add entry to /etc/fstab

Excellent, a 60GB combined partition out of 2 hard drives. I could add more in the future if I want. All that was left was to create a SAMBA share, and then setup Synctoy 2.0 to sync my music to the server every night.