Installing on software RAID

Updated 13 March 2019

Introduction

RAID (stands for Redundant Array of Independent Disks) is a data virtualization technology that combines several disks into a logical element to improve reliability (except for RAID 0) and increase performance. You do not need to buy a RAID controller to use a RAID array. Such an array is not tied to the hardware and, if necessary, can be copied to another server running Linux.

You have to understand though that RAID does not replace - and does not exclude data backup, as it protects only from a disk failure. Data may also be lost as a result of a file system failure or accidental removal. Besides, the second volume may be damaged as a result of intensive use of the RAID-array.

To install Calculate Linux on a software RAID, you have to partition one of the hard disks, copy the partition table to the other disks and finally build a RAID array from the identical partitions. The example describes how to create an RAID 5~ array on three volumes: /dev/sda, ~/dev/sdb and /dev/sdc. You can use any RAID array instead of RAID 5.

Creating a RAID array

Create two partitions on a volume, BIOS boot and a RAID partition. You can use fdisk to do so:

fdisk /dev/sda

Then enter the following:

g¶
n¶
¶
¶
+50M¶
t¶
4¶
n¶
¶
¶
¶
t¶
2¶
29¶
w¶

"¶" is the line feed character. A GPT partition table and two partitions, "BIOS boot" of 50 Mb and a future RAID, will be created.

You can also copy and run the following command, replacing /dev/sda by the name of your device:

echo -e "g\nn\n\n\n+50M\nt\n4\nn\n\n\n\nt\n2\n29\nw" | fdisk /dev/sda
 Welcome to fdisk (util-linux 2.30.2).
 Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): Created a new GPT disklabel (GUID: 3AF4A8EF-7D70-4E98-B340-7D8BFCFD1A66).

Command (m for help): Partition number (1-128, default 1): First sector (2048-23437770718, default 2048): Last sector + sectors or + size {K,M,G,T,P} (2048-23437770718, default 23437
Created a new partition 1 of type 'Linux filesystem' and of size 50 MiB.

Command (m for help): Selected partition 1
Type of partition (enter L to get the list of partition type codes): Changed type of partition 'Linux filesystem' to 'BIOS boot'.

Command (m for help): Partition number (2-128, default 2): First sector (104448-23437770718, default 104448): Last sector + sectors or + size {K,M,G,T,P} (104448-23437770718, default 234
Created a new partition 2 of type 'Linux filesystem' and of size 10.9 TiB.

Command (m for help): Partition number (1,2, default 2): Type of partition (enter L to get the list of partition type codes): 
Changed type of partition 'Linux filesystem' to 'Linux RAID'.

Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

To check the partitions, run:

fdisk -l /dev/sda
 Disk /dev/sda: 10.9 TiB, 12000138625024 bytes, 23437770752 sectors
 Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
Disk identifier: 3AF4A8EF-7D70-4E98-B340-7D8BFCFD1A66

 Device      Start        End     Sectors Size Type
/dev/sda1    2048      104447      102400    50M BIOS boot
/dev/sda2  104448 23437770718 23437666271  10.9T Linux RAID

Copy To do so, copy the partition table on /dev/sda to /dev/sdb~ and recreate the UUIDs on sdb~:

sgdisk -R /dev/sdb /dev/sda

sgdisk -G /dev/sdb

To do so, copy the partition table on /dev/sda to /dev/sdc~ and recreate the UUIDs on sdc~:

sgdisk -R /dev/sdc /dev/sda

sgdisk -G /dev/sdc

Create a RAID 5 array:

mdadm --create /dev/md0 --level=5 --raid-devices=3 --metadata=1.2 /dev/sda2 /dev/sdb2 /dev/sdc2
mdadm: array /dev/md0 started.

To monitor progress, run:

watch cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdc2[3] sdb2[1] sda2[0]
      23437403136 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      [>....................]  recovery =  0.1% (20175232/11718701568) finish=943.1min speed=206732K/sec
      bitmap: 0/88 pages [0KB], 65536KB chunk

unused devices: <none>

For faster data synchronization, set a higher synchronization speed limit:

echo 10000000 > /proc/sys/dev/raid/speed_limit_max

Check the partitioning:

lsblk /dev/sda /dev/sdb /dev/sdc
NAME    MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda       8:0    0 10.9T  0 disk  
├─sda1    8:1    0   50M  0 part  
└─sda2    8:2    0 10.9T  0 part  
  └─md0   9:0    0 21.8T  0 raid5 
sdb       8:16   0 10.9T  0 disk  
├─sdb1    8:17   0   50M  0 part  
└─sdb2    8:18   0 10.9T  0 part  
  └─md0   9:0    0 21.8T  0 raid5 
sdc       8:32   0 10.9T  0 disk  
├─sdc1    8:33   0   50M  0 part  
└─sdc2    8:34   0 10.9T  0 part  
  └─md0   9:0    0 21.8T  0 raid5

Installing Calculate

To install Calculate Linux on a software RAID, do as if it were a classic installation. Your RAID array will be partitioned automatically. To install Calculate Linux on your RAID, just run:

cl-install -D /dev/md0

You can restart your computer now.

System restoration

If a RAID volume fails, the system boot-up may take much longer, as the bootloader expects the RAID to be completely constructed.

After replacing the damaged disk (for instance, /dev/sdb), create the same partition table on it, copying from one of the disks you have already had (for instance, /dev/sda):

sgdisk -R /dev/sdb /dev/sda

sgdisk -G /dev/sdb

Now add the partition to the array:

mdadm /dev/md0 -a /dev/sdb2

Check the progress:

watch cat /proc/mdstat

To speed up the synchronization, increase the maximum speed limit:

echo 10000000 > /proc/sys/dev/raid/speed_limit_max

Note

If you replace a damaged disk with a larger one, the remaining space can also be used for new partitions.

Removing a RAID array

To remove an array, stop the RAID and delete metadata stored on it:

mdadm -S /dev/md0
mdadm: stopped /dev/md0

mdadm --zero-superblock /dev/sda2 /dev/sdb2 /dev/sdc2

Notifications

To be notified about RAID errors, you should configure email notification.

You can use any SMTP as a sender, such as mail-mta/nullmailer that comes with Calculate Linux Desktop. To configure it, run:

emerge --config nullmailer
Configuring pkg...

 * Setting /etc/nullmailer/me
 * Setting /etc/nullmailer/defaultdomain


Specify the SMTP server:

/etc/nullmailer/remotes

smtp.domain.org smtp

Start nullmailer and add it to autostart:

/etc/init.d/nullmailer start

rc-update add nullmailer

Specify the sender and the sendee:

/etc/mdadm.conf

MAILADDR inbox@domain1.com
MAILFROM outbox@domain2.com

Now let's test it:

mdadm --monitor /dev/md0 --test --oneshot