How To Create RAID Arrays with mdadm on Ubuntu 16.04
Last updated
Last updated
Find the active arrays in the /proc/mdstat file by typing:
Unmount the array from the filesystem:
Then, stop and remove the array by typing:
Find the devices that were used to build the array with the following command:
After discovering the devices used to create an array, zero their superblock to reset them to normal:
You should remove any of the persistent references to the array. Edit the /etc/fstab
file and comment out or remove the reference to your array:
Also, comment out or remove the array definition from the /etc/mdadm/mdadm.conf file:
Finally, update the initramfs again:
At this point, you should be ready to reuse the storage devices individually, or as components of a different array.
The RAID 5 array type is implemented by striping data across the available devices. One component of each stripe is a calculated parity block. If a device fails, the parity block and the remaining blocks can be used to calculate the missing data. The device that receives the parity block is rotated so that each device has a balanced amount of parity information.
Requirements: minimum of 3 storage devices
Primary benefit: Redundancy with more usable capacity.
Things to keep in mind: While the parity information is distributed, one disk’s worth of capacity will be used for parity. RAID 5 can suffer from very poor performance when in a degraded state.
To get started, find the identifiers for the raw disks that you will be using:
As you can see above, we have three disks without a filesystem, each 100G in size. In this example, these devices have been given the /dev/sda
, /dev/sdb
, and /dev/sdc
identifiers for this session. These will be the raw components we will use to build the array.
To create a RAID 5 array with these components, pass them in to the mdadm --create command. You will have to specify the device name you wish to create (/dev/md0 in our case), the RAID level, and the number of devices:
The mdadm tool will start to configure the array (it actually uses the recovery process to build the array for performance reasons). This can take some time to complete, but the array can be used during this time. You can monitor the progress of the mirroring by checking the /proc/mdstat file:
Next, create a filesystem on the array:
Create a mount point to attach the new filesystem:
You can mount the filesystem by typing:
Check whether the new space is available by typing:
The new filesystem is mounted and accessible.
To make sure that the array is reassembled automatically at boot, we will have to adjust the /etc/mdadm/mdadm.conf file.
Before you adjust the configuration, check again to make sure the array has finished assembling. Because of the way that mdadm builds RAID 5 arrays, if the array is still building, the number of spares in the array will be inaccurately reported:
The output above shows that the rebuild is complete. Now, we can automatically scan the active array and append the file by typing:
Afterwards, you can update the initramfs, or initial RAM file system, so that the array will be available during the early boot process:
Add the new filesystem mount options to the /etc/fstab file for automatic mounting at boot:
Your RAID 5 array should now automatically be assembled and mounted each boot.