RAID-1 on Linux Systems
Objective
Create a RAID-1 (mirrored) array /dev/md0
using two identical disks /dev/sdb
and /dev/sdc
. The process of creating the array will go something like this:
- Partition the disks;
- Use the partitioned disks to create the array;
- Create a filesystem for the array;
- Format the array.
Back-up your data before proceeding. Tools like GParted or similar can help you decide which disks to use. Also, before starting, make sure the disks you plan to use are not mounted.
Install mdadm
If mdadm
is already installed, make sure the service is currently running and active on boot. (Graphical tools like BootUp-Manager can be useful here.)
Examining Arrays Using /proc/mdstat
The pseudofile /proc/mdstat
will provide information about the current state of RAID devices and the md
driver:
Existing Arrays
You will not be able to create a new array using partitions that are members of an existing array. Therefore, in order to reuse disks, you will need to stop any active arrays of which they are members:
Reusing the partitions on these disks also means destroying the data on them (along with the array). Whenever you attempt to create a new array using mdadm
, you will be warned about using member disks that already have a RAID superblock on them, even if they're not part of an array that's currently in use. You can suppress this prompt by using mdadm
to remove the RAID superblock from the disks that were part of an array. This command allows you to remove the superblock from more than one disk at a time:
Creating an Array
It's time to partition disks and create the array. We can partition a disk for auto-detection like so:
Now change the drive type of /dev/sdb1
to Linux RAID (0xFD) so that it can be detected automatically at boot time:
Entering w
writes the partition table to disk and exits. Now do the same for /dev/sdc
. After that, use mdadm
to create a RAID-1 array (you will probably have to unmount both disks again before proceeding):
Whenever a new mirror is created, resynchronization occurs. Check this by issuing the command cat /proc/mdstat
. The initial synchronization is complete when the progress bar no longer appears. Now create a filesystem for your new array:
Finishing Touches
You aren't obligated to create an /etc/mdadm/mdadm.conf
file, but it will make managing arrays using mdadm
much easier. Let's start by looking at the output of sudo mdadm --detail /dev/md0
:
Note the value of UUID
. You should put the line ARRAY /dev/md0 UUID=•••
in your configuration file by doing sudo gedit /etc/mdadm/mdadm.conf
(make sure to hash any other ARRAY
lines corresponding to /dev/md0
). Next, let's create a mount point for the array:
Now tell your system to automatically mount the array at boot time by putting the line /dev/md0 /media/joel/Linux auto defaults 0 0
in your file systems table via the sudo gedit /etc/fstab
command. As a one-off, you should tell the kernel take a look at the system again to figure out how to boot properly:
After rebooting, don't forget to format the array, or you won't be able to use it.