Exercise: Introduction to Software RAID
Creating a Mirrored Array with mdadm
1 Purpose
This exercise introduces you to the powerful concept of RAID (Redundant Array of Independent Disks). You will use multiple virtual disks to create a fault-tolerant RAID 1 array, also known as a “mirror.” This is a foundational skill for anyone responsible for systems where data redundancy and uptime are critical. You will use the standard Linux tool for software RAID, mdadm.
2 What You’ll Accomplish
By the end of this exercise, you will be able to:
- Create multiple virtual disk images to serve as members of a RAID array.
- Use
mdadmto create a RAID 1 array from two block devices. - Check the status and health of a software RAID array.
- Format and mount the RAID array as a single logical volume.
- Stop and disassemble a software RAID array.
This exercise maps to the following program and course learning outcomes:
- Program Learning Outcomes (PLOs):
- 6. Maintain environment: Creating a redundant storage array is a primary method for maintaining a high-availability data environment.
- Course Learning Outcomes (CLOs):
- 4. Configure hardware and basic network components: Building a software RAID array is an advanced and powerful system configuration task.
This exercise develops the following skills, which align with the O*NET SOC Code 15-1232.00 for Computer User Support Specialists.
| Learning Objective | O*NET KSAs | Technologies Used |
|---|---|---|
| Create a software RAID 1 array. | Knowledge: Computers & Electronics Skills: Installation, Systems Analysis |
mdadm, RAID |
| Check the status of a RAID array. | Knowledge: Computers & Electronics Skills: Troubleshooting, Monitoring |
mdadm |
3 Prerequisites
This exercise requires a running Fedora 42 virtual machine with internet access and a user account with sudo privileges. We will be using the raw image and losetup method consistent with the previous exercises.
4 Step-by-Step Guide
Open a terminal window in your Fedora VM to begin.
4.1 Step 1: Install mdadm
mdadm (multiple disk and device administration) is the standard tool for managing software RAID in Linux.
Run the following command to install the package:
sudo dnf install -y qemu-img mdadm
4.2 Step 2: Create and Attach Two Virtual Disks
For a RAID 1 mirror, you need at least two identical drives. You will create two new, smaller virtual disks for this purpose using the pre-allocated raw format.
Create the first 500MB raw disk image:
qemu-img create -f raw -o preallocation=falloc disk_a.img 500MCreate the second 500MB raw disk image:
qemu-img create -f raw -o preallocation=falloc disk_b.img 500MAttach both disks as loop devices:
sudo losetup -fP disk_a.img sudo losetup -fP disk_b.imgVerify their names with
lsblkorlosetup -a. You should see two new loop devices (e.g.,loop0andloop1).
In your student notebook, write down the names of the two new loop devices.
4.3 Step 3: Create the RAID 1 Array
Now you will use mdadm to combine the two loop devices into a single mirrored array, which will appear as a new device called /dev/md0.
Run the
mdadm --createcommand. The arguments specify the name of the new array, the RAID level (--level=1), and the number and names of the devices to include.# Replace /dev/loop0 and /dev/loop1 if your device names are different sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/loop0 /dev/loop1You will be asked to confirm. Type
yand press Enter.mdadmwill begin building the array. You can watch the progress with the following command:watch cat /proc/mdstatThis will update every two seconds. Wait for the
[UU]status, which means both drives are up and synced. PressCtrl+Cto exitwatch.
4.4 Step 4: Examine and Format the Array
Use
mdadm --detailto see a detailed report of your new array’s status.sudo mdadm --detail /dev/md0Notice that the “State” is
activeand you have two active devices.Now, you can treat
/dev/md0as a single block device. Format it with anext4filesystem:sudo mkfs.ext4 /dev/md0
4.5 Step 5: Mount and Use the Array
Create a mount point:
sudo mkdir /mnt/my_raid_mirrorMount the array:
sudo mount /dev/md0 /mnt/my_raid_mirrorCheck the result with
df -h. You will see/dev/md0mounted, and its total size will be approximately 500MB, not 1GB. This is because it’s a mirror—you get the capacity of only one drive.
Take a screenshot of the mdadm --detail output and add it to your notebook.
4.6 Step 6: Clean Up
When you are finished, it is important to stop the array and detach the loop devices.
Unmount the filesystem:
sudo umount /mnt/my_raid_mirrorStop the RAID array. This deactivates
/dev/md0.sudo mdadm --stop /dev/md0Detach the two loop devices. Use the names you recorded earlier.
# Replace with your actual device names sudo losetup -d /dev/loop0 sudo losetup -d /dev/loop1
5 Reflect and Review
Now that you have completed this exercise, reflect on your experience in your Microsoft Teams Student Notebook:
- 3
mdadmcommands or flags you used. - 2 reasons you might choose to use RAID 1.
- 1 question you still have about how software RAID works.
Answer these questions in your notebook to solidify your understanding:
- What does the
--level=1flag specify in themdadm --createcommand? - You created a RAID 1 array with two 500MB disks. Why was the final usable capacity only 500MB?
- In the output of
cat /proc/mdstat, what does a status of[UU]indicate? What might[U_]indicate? - What command do you use to stop a RAID array after you have unmounted it?