Red Hat Software Raid
This is a quick and dirty document on software raid there are many more documents on the web that go into greater detail, the following is covered in this document:
The following was tested using a centos 4 installation on Dell hardware, three partitions have already been created /dev/sdb10, /dev/sdb11 and /dev/sdb12 all are 1Gb in size.
Set the partition type
Set partition type | [root]# fdisk /dev/sdb Partition ID (L to list options): fd Note: repeat above for /dev/sdb11 and /dev/sdb12 fd = raid autodetect |
Create partiton copy to new disk
create partition table of new disk | sfdisk -d /dev/sda | sfdisk /dev/sdb Note: this is like the prtvtoc ... | fmthard ... command in Solaris |
Create the array
Using mkraid | 1. Update the configuration file /etc/raidtab with these lines of code 2. Now make the RAID device md0 and create a filesystem on it 3. Now add entry to /etc/fstab and mount it: Add line to fstab: Create the mount point: Mount the mirror: |
Using mdadm | mdadm -C /dev/md0 -l1 -n2 /dev/sdb10 /dev/sdb11 -x1 /dev/sdb12 |
mdadm configuration file
detail, examine and assemble | detail = applies to the whole array which is currently active examine = applies to the devices which are a component of the array assemble = assemble the array using all devices (will use config file first then scan devices) |
Commands |
|
Saving the configuration | echo "DEVICE partitions" > /etc/mdadm.conf Note: by default the system will look in /etc/mdadm.conf then /etc/mdadm/mdadm.conf |
Lost the configuration file | echo "DEVICE partitions" > /etc/mdadm.conf mdadm --examine --scan >> /etc/mdadm.conf mdadm --assemble --scan |
/proc/mdstat | cat /proc/mdstat |
lsraid | lsraid –a /dev/md0 |
mdadm | mdadm --detail /dev/md0 mdadm -D /dev/md0 |
Display device configuration | mdadm --misc -D /dev/md0 mdadm --misc -E /dev/sdb11 |
raidtools | raidsetfaulty /dev/md0 /dev/sdb11 |
mdadm | mdadm -–manage /dev/md0 –f /dev/sdb11 |
Use the above “check the array” options to see that the disk has been faulted.
Remove a disk from the array
To remove a disk from the raid array use the following commands, the disk has to be faulty not faulted (see above) to allow this option to work, at this point the disk can be physically removed.
raidtools | raidhotremove /dev/md0 /dev/sdb11 |
mdadm | mdadm --manage /dev/md0 –r /dev/sdb11 |
Use the above “check the array” options to see that the disk has been removed.
Add a disk to the array
Adding a disk to the array could result in two outcomes, if the array is already degraded the new will be used to fix the fault (if a hot spare has not already been used), if not then the disk will be used as a hot spare.
raidtools | raidhotadd /dev/md0 /dev/sdb11 |
mdadm | mdadm --manage /dev/md0 –a /dev/sdb11 |
Use the above “check the array” options to see that the disk has been added.
Extend/Shrink the array
grow | ## First you need to change the configuration mdadm --grow /dev/md0 -n3 ## Then you can add the disks mdadm --manage /dev/md0 -a /dev/sdb12 ## Now you can resize the filesystem resize2fs /dev/md0 |
shrink | ## MAKE SURE EVERYTHING IS BACKED UP |
Change the type from raid 1 to raid 5
It is possible to change the type of the array from a raid 1 to a raid 5, I would advise to backup first but it worked without any problems for me
change from raid 1 to raid 5 | ## First you need to unmount any filesystem from the array ## Once the array has started then mount it again and check everything |
Starting and stopping array
raidtools | raidstop /dev/md0 raidstart /dev/md0 |
mdadm | ## Make sure you have the configuration /etc/mdadm.conf file created -S stopping |
Remove the Array
Remove the array | mdadm --stop /dev/md0 ## Once you run the below command there is no going back |
Restore the Array
Restore the array | ## standard header for mdadm.conf file ## get the information from the disks and append that information to mdadm.conf file ## use the mdadm.conf file to start the array |
Persistant-superblock
When an array is initialised with the persistent-superblock option in the /etc/raidtab file, a special superblock is written in the beginning of all disks participating in the array. This allows the kernel to read the configuration of RAID devices directly from the disks involved, instead of reading from some configuration file that may not be available at all times.
Autodetection
Autodetection allows the RAID devices to be automatically recognized by the kernel at boot-time, right after the ordinary partition detection is done.