Friday, July 20, 2012

Replacing WHS 2011 with Ubuntu Server 12.04 (Part 3 - Configuring RAID5 with LVM)

To meet my capacity requirements, my HP LX195 has 3 external 1TB hard drives. While the Western Digital MyBook drives have proven reliable, I have still had disks fail and take data with them to the grave since I installed my home server unit a few years ago.

With a Linux based solution I decided to bite the bullet and figure out how to configure a RAID5 array out of the three. This reduces my over all available capacity, but should still prove sufficient. Besides, I have one USB port left for an additional drive for non-redundant bulk storage.

To do so I followed the instructions from the following site with only slight modifcation.
 http://dtbaker.com.au/random-bits/ubuntu---howto-easily-setup-raid-5-with-lvm.html

To summarize my personal steps:
  1. $ tail -f /var/log/syslog
  2. Connect drive 1, note device reported by syslog (should be sdb)
  3. Connect drive 2, note device reported by syslog (should be sdc)
  4. Connect drive 3, note device reported by syslog (should be sdd)
  5. Label all 3 drives for future reference
  6. $ sudo apt-get install mdadm smartmontools
  7. $ sudo nano /etc/defaults/smartmontools
  8. uncomment the "start_smartd=yes" line. I'm not sure if smartmontools will work with usb hard drives, but it's worth a shot
  9. $ sudo nano /etc/smartd.conf
  10. Add one line for each new drive:
    /dev/sdb -a -I 194 -W 4,45,55 -R 5

    /dev/sdc -a -I 194 -W 4,45,55 -R 5

    /dev/sdd -a -I 194 -W 4,45,55 -R 5
  11. Since my disks were already partitioned I needed to first delete the existing NTFS partitions and recreate them as Linux raid partitions. Note: be sure to evacuate the data from the disks before you repartition with fdisk! You will lose data. Thankfully I had a couple of spare drives from work that I could dump data on temporarily.
  12. $ sudo fdisk /dev/sdb
  13. In fdisk, the command sequence was "d n p 1 (default start) (default end) t fd w" This is short for delete current partition (only 1 in my case), create new partition, primary, id=1, use all space, change type to Linux RAID Autodetect, write partition table and exit.
  14. Use mdadm to create the RAID5 virtual device
    $ sudo mdadm --create /dev/md0 --level=5 -n 3 /dev/sdb1 /dev/sdc1 /dev/sdd1
  15. Read the description of all running raid instances using mdadm
    $ sudo mdadm --detail --scan
    This will return an output like:
    ARRAY /dev/md0 level=raid5 num-devices=3 metadata=00.90 spares=1
      UUID=b144b150:b3b4ff34:2bababc5:c86c0f3a
  16. Copy and paste that information into /etc/mdadm/mdadm.conf 
  17. Initilize md0 for LVM
    $ sudo pvcreate /dev/md0
  18. Create a volume group
    $ sudo vgcreate vg1 /dev/md0
  19. Before we can create a logical volume that can be mounted, we need to know the available space in the array
    $ sudo vgdisplay vg1 | grep "Total PE"
    Total PE             476932
  20. Now create the logical volume
    $ sudo lvcreate -l 476932 -n -lv1 vg1 /dev/md0
    Logical volume "lv1" created
  21. Format the logical volume with the file system of choice. I opted to use ext4 since that's what ubuntu chose for /
    $ sudo mkfs.ext4 /dev/vg1/lv1
  22. Make a mount point
    $ sudo mkdir /data/external
  23. Add an entry to fstab
    $ sudo nano /etc/fstab
    /dev/mapper/vg1-lv1  /data/external    ext4    errors=remote-ro    0    1
  24. Mount the new volume and verify
    $ sudo mount -a
    $ df -h
    /dev/mapper/vg1-lv1    1.9T   28G  1.7T   2% /data/external
Simply right?

No comments: