Monthly Archives: May 2012

Building a RAID 5 Storage System using Linux

Posted on by .

RAID improves storage performance and storage is important, but what’s more important is the data that is being contained. So I’ve decided to build a proof of concept in a Visualized en environment before hitting the real thing.

so after “installing” your disk, check for your disks using this command

fdisk -l

You’ll see things like this

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table

Disk /dev/sdd: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdd doesn't contain a valid partition table

Make sure that these are the drives that you’re going to work on for the RAID.

Now create a new partition (in this case the partition is going to be on /dev/sdb)

fdisk /dev/sdb

Press ‘n’ for new partition

n

Press ‘p’ for primary partition and ‘1’ for the 1st partition

p
1

After creating partitions change it to lo Linux raid auto detect

Press ‘t’ to change partition type

t

Press ‘fd’ to change it to “Linux RAID auto”

fd

Press ‘w’ to save and write the configuration

w

Repeat the above steps for the other hard disks also.

After getting the partitions up, it’s time to build the raid and it’s a simple 1 liner. 🙂

mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

Then you persist the RAID settings into a mdadm.conf file using this

mdadm --detail --scan >> /etc/mdadm.conf

Then it’s time to format the new RAID

mkfs.ext4 /dev/md0

Then it’s time to mount somewhere create a directory

mkdir -p /mnt/raid
mount /dev/md0 /mnt/raid

After that find the UUID of the raid device

ls /dev/disk/by-uuid -alh

Then add it into /etc/fstab by editing the file using a text editor like vim

vim /etc/fstab

add this line at the end of the file

UUID=<<YOUR UUID>> /mnt/raid ext4 defaults 0 0

And there you have it! a RAID 5 storage system ready to be used! 🙂

Do take note that RAID is not a backup, it is merely redundant storage with performance. You’ll still have to backup regularly into another drive which I’ll touch on later.