Ubuntu – Howto Easily Setup RAID 5 with LVM

 

Some notes for me to follow next time I do it:

  1. Install mdadm and S.M.A.R.T. drive monitoring
    # apt-get install mdadm smartmontools
  2. Enable smartd
    # vi /etc/defaults/smartmontools

    uncomment the “start_smartd=yes” line

  3. Edit smartd config and tell it what drives to monitor
    # vi /etc/smartd.conf

    add these lines to monitor each drive:

    /dev/sdc -a -I 194 -W 4,45,55 -R 5 -m your@email.com
    /dev/sdd -a -I 194 -W 4,45,55 -R 5 -m your@email.com
    /dev/sde -a -I 194 -W 4,45,55 -R 5 -m your@email.com
  4. Partition the 3 drives into “Linux Raid Autodetect” partitions:
    # fdisk /dev/sdc

    n (new)
    p (primary)
    1 (1st primary)
    t (change type)
    fd (set type to linux raid autodetect)
    w (write changes and exit fdisk)
    repeat for /dev/sdd and /dev/sde

  5. Create the raid 5 array on the 3 drives:
    # mdadm --create /dev/md0 --level=5 -n 3 /dev/sdc1 /dev/sdd1 /dev/sde1
  6. Build a new mdadm.conf file, first grab a description of all running raid instances:
    # mdadm --detail --scan
    ARRAY /dev/md0 level=raid5 num-devices=3 metadata=00.90 spares=1
      UUID=b144b150:b3b4ff34:2bababc5:c86c0f3a
    Then copy and paste this into the /dev/mdadm/mdadm.conf file (remove old default val) so the mdadm.conf file should look something like:
    DEVICE partitions
    CREATE owner=root group=disk mode=0660 auto=yes
    HOMEHOST <system>
    MAILADDR your@email.com
    ARRAY /dev/md0 level=raid5 num-devices=3 metadata=00.90 spares=1
    UUID=b144b150:b3b4ff34:2bababc5:c86c0f3a (all on 1 line)
  7. Check status of raid:
    # mdadm --detail /dev/md0

    this shows rebuild state.

  8. Initialize the entire md0 raid array for LVM use.
    # pvcreate /dev/md0
  9. Create the volume group
    # vgcreate vg1 /dev/md0
  10. Create a logical volume (something you can mount – where files are stored) but make it the entire size of the raid 5 array.. first have to find out current size:
    # vgdisplay vg1 | grep "Total PE"
       Total PE              715399
    # lvcreate -l 715399 -n lv1 vg1 /dev/md0
       Logical volume "lv1" created
  11. Make the file system on our new lv1 volume:
    # mkfs.reiserfs /dev/vg1/lv1
  12. Make the dir where you want to mount array:
    # mkdir /data
  13. Add entry to fstab
    # vi /etc/fstab
    /dev/mapper/vg1-lv1  /data      reiserfs auto       0       0
  14. Mount the new LVM raid 5 array:
    # mount /data
  15. Check it worked:
    # df -h
    /dev/mapper/vg1-lv1   2.7T  202M  2.6T   1% /data
  16. Done.

Edit: I have now re-done this without LVM. Click here to see those steps instead.

2 thoughts on “Ubuntu – Howto Easily Setup RAID 5 with LVM

  1. Joe H

    Hey, thanks for this article. I know it’s 4 years later, but with the removal of mdadm from the Anaconda installer and the Ubuntu installer you are left without any auto tools at all to get set up with a mdadm RAID array on these mainstream distros. It’s nice to find a quick guide like this.

    small note to anyone finding this, the /dev/mdadm/mdadm.conf should be /etc/mdadm/mdadm.conf

    Thanks again,

    Joe

    Reply
  2. PHP Trivandrum

    Just now tried this on a server install. Though there was some hurdles, the article helped me take it through. First, in step two it should be /etc/default/smartmontools and not “/etc/defaults/smartmontools”. Second the lvm commands were not installed by default, and had to install it using apt-get install lvm2

    Reply

Leave a Reply to Joe H Cancel reply

Your email address will not be published. Required fields are marked *