Ubuntu RAID-5

Creating the raid

If gparted is not yet installed:

sudo apt-get install gparted

For each disk: create partition, apply, manage flags->raid.

Install mdadm:

sudo apt-get install mdadm

Create RAID:
sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1

Watch it being created:
watch cat /proc/mdstat

Edit mdadm config file /etc/mdadm/mdadm.conf, add output of
sudo mdadm --detail --scan

Create file system:
sudo mke2fs -j /dev/md0

Create mount point:
sudo mkdir /var/media
chmod a+rw /var/media

Add line to /etc/fstab:
/dev/md0 /var/media auto defaults 0 3

Information gotten from this page.

Configuring email notifications

Install msmtp:

sudo apt-get install msmtp

Create /etc/msmtprc:
# ------------------------------------------------------------------------------
# msmtp System Wide Configuration file
# ------------------------------------------------------------------------------

# A system wide configuration is optional.
# If it exists, it usually defines a default account.
# This allows msmtp to be used like /usr/sbin/sendmail.

# ------------------------------------------------------------------------------
# Accounts
# ------------------------------------------------------------------------------

# SAMs Account
account sam
host smtp.xs4all.nl
port 25
from my_email@xs4all.nl
auth login
user my_email@xs4all.nl
password ********

# ------------------------------------------------------------------------------
# Configurations
# ------------------------------------------------------------------------------

# Construct envelope-from addresses of the form "user@oursite.example".
#auto_from on
#maildomain fermmy.server

# Use TLS.
#tls on
#tls_trust_file /etc/ssl/certs/ca-certificates.crt

# Syslog logging with facility LOG_MAIL instead of the default LOG_USER.
syslog LOG_MAIL

# Set a default account
account default : sam

# ------------------------------------------------------------------------------

Test msmtp:
msmtp --pretend

If that works:
echo "This is a test e-mail from my server using msmtp!" | msmtp my_email@xs4all.nl

Use msmtp as sendmail:
sudo ln -s /usr/bin/msmtp /usr/sbin/sendmail

Edit /etc/mdadm/mdadm.conf:
MAILADDR my_email@xs4all.nl
MAILFROM meeuw@xs4all.nl

Test (should deliver an email with the contents of /proc/mdstat):
sudo mdadm --monitor --scan --test --oneshot

mdadm is already setup for monitoring (Ubuntu 8.04), but I want it to send email everytime the server is started. Edit /etc/default/mdadm and change DAEMON_OPTIONS:
DAEMON_OPTIONS="--syslog --test"

Information from this page.

Replacing a disk when the disk is still sort of functioning and the raid becomes active (not tested)

Remove faulty drive:

mdadm --manage /dev/md0 -r /dev/sdd

Set the partition table on the new drive to match those of the other drives in the array:
sfdisk -d /dev/sda | sfdisk /dev/sdd"

Add the proper partition on the new drive into the array:
mdadm --manage /dev/md0 -a /dev/sdd2"

Wait for the recovery to happen:
watch cat /proc/mdstat

Information from this page.

Replacing a disk when the disk is completely gone and has been replaced (tested on Ubuntu VM)

Partition the new disk in the same way as when creating the raid and set the raid flag.

The raid will be inactive, it has to be activated before anything can be done with it:

mdadm -R /dev/md0

Add the new disk to the raid:
mdadm /dev/md0 -a /dev/sdb1

Wait for the recovery to happen:
watch cat /proc/mdstat
page_revision: 9, last_edited: 1255672331|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License