Linux RAID-1 [5]

Just for future reference I think it is a good idea to write up the steps that are necessary to create a RAID-1 array. This guide is for Linux Mint 17.03 the version of Linux I am running on most of my computers. Refer to the source documents if you wish to create a different type of array. All these documents assume root rights so you either use sudo before each command as needed or open up a root shell.

The first stage is to configure the kernel with any additional kernel modules that are required to be loaded at boot time. To check if these are loaded, type

cat /proc/mdstat

The output of this command should refer to certain RAID personalities. For example on my system it reads

Personalities: [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]

This tells you what kind of RAID arrays you can run in your system. If information relating to your particular preference in RAID arrays is missing, you will need to ensure the required modules are loaded into the kernel. For the current session you can use these commands to immediately load these modules:

modprobe raid1

There is also a reference in the source documents to loading the md module in the same way but all my systems gave an error message stating they could not load the module.

To install these modules permanently, edit /etc/modules to add raid1 and md to the end of the file. This will still work even if there is no md module in your system.

The second stage is to install the mdadm package:

apt install mdadm

Once this has installed successfully we can move on to the task of creating our RAID-1 array. Here we are assuming the volumes to be assembled into the array have already been identified and are ready to go.

Assuming a two disk mirror with no additional spares the command would look like this (in my case):

mdadm –create –verbose /dev/md0 –level=mirror –raid-devices=2 /dev/sda1 /dev/sdd1

The form of the command is to specify in turn the mountpoint of the new array, the type of array, the number of devices to be added and the mount points of those devices.

The next thing is to do another iteration of

cat /proc/mdstat

which gives a progress indication of the building of the array. Another way to see this progress is to open the Disks gui tool. The new array will be visible along with an informational display including the progress and expected ETA of this task.

You need to save the configuration information by adding it to the end of /etc/mdadm/mdadm.conf. Please note this is the specific location for Ubuntu-based distributions, and other distributions may use a different location. Issue the following command

cat /etc/mdadm/mdadm.conf

If there is not an ARRAY statement for the array you just created, for example:

ARRAY /dev/md0

then this information needs to be obtained from the output of this command

mdadm –detail –scan

You can add this directly to the mdadm.conf file with this command

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

It is recommended not to run this command until the array has finished initialising.

This information is needed in the mdadm.conf file in order to start the array at boot up and if it is not in the file the array may not start. This in turn could cause the system to halt during startup with a disk load error. So it is important to take note of this point.

The next step is to create and format a partition on the new md device. Give this partition a recognisable name for the next step.

To have the array mounted automatically at bootup you need the correct UUID for it. Which you can get from the blkid command. N.B. if you are not running this command as root, it will not output anything.

Before I got to this I rebooted the system, and then found that my array was renamed as /dev/md127. The blkid command output a line reading this:

/dev/md127: LABEL=”Data” UUID=”581966fb-0d41-4dac-bef3-c6de6267ec9e” TYPE=”ext4″

In order to have this RAID drive mounted at startup, it must be added to the /etc/fstab file. The command in this file typically looks like

 UUID=581966fb-0d41-4dac-bef3-c6de6267ec9e /newhome        ext4    defaults        0       2

Note the UUID obtained above when creating this line. The mount point, file system and some other parameters that I don’t know about must be included in the line you enter.

Once you have saved the changes to /etc/fstab then check your work by typing

mount -a

This will apply the mount point you just specified from the file. If there are no problems with this then you should be able to reboot and the system will come back up with the array mounted to the specified mount point.

This should complete the creation of the array.

Originally part 6 was going to show how to move the home drive to the new partition. Basically I just followed the instructions from the website below. Part 6 is now about reconnecting the RAID array after installing a new version of the operating system.

References:


by

Tags: