Raid 5

Dec 16, 2013
2 min read
Jun 30, 2023 16:33 EEST

Install at first the raid tools:

emerge -av sys-fs/mdadm

Load the raid module:

modprobe raid5

Create partitions on the three hard-disks with fdisk and type fd.

fdisk /dev/sdb
fdisk /dev/sdc
fdisk /dev/sdd

Create md devices:

cd /dev && MAKEDEV md

New create the raid with:

mdadm --create /dev/md0 --level 5 --raid-devices 3 /dev/sd[[bcd]]1

To see progress on build:

watch -n 1 cat /proc/mdstat

Store raid in config file:

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

To see more details for raid:

mdadm --detail /dev/md0

Sending EMail in Case of an Error

Edit the file /etc/mdadm.conf and add there:

MAILADDR idefix@server.idefix.lan

Test email delivery:

mdadm -Ft --scan

In Case of Failure

You can see in /proc/mdstat which device failed:

md0 : active raid5 sdb1[3] sdd1[2] sdc1[1]
      2930271872 blocks level 5, 64k chunk, algorithm 2 [3/2] [_UU]

Remove it with:

mdadm -r /dev/md0 /dev/sdb1

Create a partition on the new disk with type 0xFD and add it to the raid with:

mdadm -a /dev/md0 /dev/sdb1

You can see now in /proc/mdstat that the raid is recovering the data:

cat /proc/mdstat

Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] [faulty]
md0 : active raid5 sdb1[3] sdd1[2] sdc1[1]
      2930271872 blocks level 5, 64k chunk, algorithm 2 [3/2] [_UU]
      [>....................]  recovery =  0.8% (12625280/1465135936) finish=302.8min speed=79923K/sec

unused devices: <none>

Create LVW2

emerge -av lvm2
rc-update add device-mapper boot
rc-update add lvm boot

Scan for devices:

vgscan

mdadm -Ac partitions -m 0 /dev/md0

Convert a normal raid to lvm2

At first we create our backup storage. For this create partition on the disks and select as type raid autodetect. Now we create the raid with:

mdadm --create /dev/md0 --level=stripe --raid-devices=2 /dev/sde1 /dev/sdf1

Now we create the lvm2:

vgscan
vgchange -a y
pvcreate /dev/md0
vgcreate vg /dev/md0
lvcreate -L20G -nyavdr vg
lvcreate -L3T -nbackup-video0 vg
mkfs.ext4 /dev/vg/backup-video0

Now we mount the disks:

mount /dev/vg/backup-video0 /mnt/backup-video0
mount video:/video0 /video0

Now we copy the data:

cd /video0
rsync -av --delete . /mnt/backup-video0/

Online Resize Raid5

Replace the first disk with a new one like it is descriped in case of a disk failure. Wait till the raid is restored. Repeat that step for every disk in your raid.

Now we have to resize the raid:

mdadm -G /dev/md0 -z max

You have to wait till the resize is complete, check with:

cat /proc/mdstat

Now we resize the lvm:

pvresize /dev/md0

Now we resize the logical volume:

lvresize -l +100%FREE /dev/vg/video0

Now we resize the filesystem, I use ext4 so do:

resize2fs /dev/vg/video0

Related Posts