| |

LFCS 94 ๐Ÿง RAID with mdadm โ€” Creating Arrays

โฑ๏ธ Estimated read: 10 min | |

The previous chapter established the theory of RAID levels. This chapter translates that theory into practice. mdadm is the userspace tool that communicates with the Linux kernel’s multiple device (md) driver to assemble physical block devices into a logical RAID array. The command syntax is denseโ€”a single invocation can specify the array name, RAID level, number of devices, metadata format, chunk size, and spare disks. On the LFCS exam, you must construct this command correctly, create a filesystem on the resulting array, and ensure it persists across reboots.

Key point: The --create command is a single atomic operation that configures the array, writes metadata to every member disk, and starts the initial synchronization. If the command is malformed, the disks may be left with partial metadata that must be cleared before retrying.


Why mdadm exists

The kernel interface problem. The Linux kernel implements software RAID through the md driver. The driver accepts configuration through ioctl calls and sysfs, but these interfaces are not designed for human use. mdadm translates a readable command line into the low-level operations the driver requires. Without it, creating a RAID array would require writing a C program that calls ioctl on /dev/md* .

The metadata problem. Every disk in a RAID array carries a superblockโ€”a small block of metadata that identifies the array UUID, the disk’s role, the RAID level, and the chunk size. When the system boots, the kernel reads these superblocks to assemble the array automatically. mdadm writes this metadata during creation and can update it when the array configuration changes. The metadata format matters: version 1.2 (the modern default) stores the superblock 4 KiB from the start of the device, while version 0.90 (the legacy format) stores it at the end and limits arrays to 2 TB per device .

The naming problem. The array device is named /dev/mdX or /dev/md/name. The name is not arbitraryโ€”it is stored in the metadata and used by the kernel to identify the array during assembly. If two arrays have the same name, the assembly process may attach the wrong disks. mdadm provides the --name option to set a persistent name, but the default naming scheme (/dev/md0, /dev/md1) is usually sufficient for exam scenarios .

The sync problem. When a RAID 1 or RAID 5 array is created, the member disks may contain different data. The kernel begins a background synchronization (resync) that copies the data from one disk to the others or computes the initial parity. During this process, the array is functional but degradedโ€”performance is lower, and a disk failure at this stage is unrecoverable. mdadm --detail and /proc/mdstat show the sync progress .

The trade-off. mdadm is flexible but unforgiving. A typo in the device list can include the wrong disk and destroy existing data. The --create command does not prompt for confirmation if the disks already contain a filesystem signature. The safe workflow is to verify device names with lsblk and clear existing signatures with wipefs before creating the array.


a. Creating a RAID 1 array

RAID 1 is the simplest array to create and the most common exam scenario. It requires exactly two devices (or more, if you want additional mirrors) of equal or near-equal size. The command specifies the array device, the RAID level, the number of devices, and the member disks.

# Clear any existing filesystem or RAID signatures
sudo wipefs -a /dev/sdb
sudo wipefs -a /dev/sdc

# Create the RAID 1 array
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc

The --level=1 (or -l 1) specifies mirroring. The --raid-devices=2 (or -n 2) declares that the array uses two active disks. The member disks follow as positional arguments. After the command completes, mdadm writes the superblock to both disks and the kernel begins the initial resync .

The resync can take minutes or hours depending on disk size. The array is usable during this time, but cat /proc/mdstat shows the progress:

md0 : active raid1 sdc[1] sdb[0]
      976630464 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  0.5% (5000000/976630464) finish=120.0min speed=135000K/sec

The [UU] notation indicates that both disks are up. If one disk fails, it becomes [U_] and the array is degraded .


b. Creating a RAID 5 array

RAID 5 requires at least three devices. The command is structurally identical to RAID 1, but the level changes and the device count increases.

# Create a three-disk RAID 5 array
sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd

The initial parity computation is more intensive than RAID 1 mirroring. The resync process reads every block and computes the parity, which can take longer on large drives. The array is functional during this period, but performance is degraded .

RAID 5 also supports spare disks. A spare is not part of the active array but is automatically used for reconstruction if an active disk fails. The --spare-devices (or -x) option adds spares at creation time:

# RAID 5 with three active disks and one spare
sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 --spare-devices=1 /dev/sdb /dev/sdc /dev/sdd /dev/sde

The total number of devices on the command line must equal the number of active devices plus the number of spares. In this example, four disks are listed: three active, one spare .


c. Metadata format and chunk size

The default metadata format for new arrays is version 1.2. This format stores the superblock 4 KiB from the start of the device and supports arrays larger than 2 TB. The legacy 0.90 format is limited to 2 TB per device and is only needed for compatibility with very old bootloaders. For exam purposes, the default is correct unless the question specifically requires 0.90 .

The chunk size matters for RAID 0, 5, 6, and 10. It defines the granularity of data distribution across disks. The default is 512 KiB. For large sequential workloads, a larger chunk size reduces overhead. For random workloads, a smaller chunk size distributes I/O more evenly. The --chunk (or -c) option sets it in kilobytes:

# RAID 5 with 64 KiB chunk size
sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 --chunk=64 /dev/sdb /dev/sdc /dev/sdd

The chunk size is recorded in the metadata and cannot be changed without recreating the array. For exam scenarios that do not specify a chunk size, the default is acceptable .


Complete Example Session

# ============================================
# PART 1: IDENTIFY AVAILABLE DISKS
# ============================================

# List block devices with sizes and types.
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT
# sdb and sdc are available, no filesystem.
# ============================================
# PART 2: CLEAR EXISTING SIGNATURES
# ============================================

# Remove any filesystem or RAID metadata.
sudo wipefs -a /dev/sdb
sudo wipefs -a /dev/sdc
# ============================================
# PART 3: CREATE RAID 1 ARRAY
# ============================================

# Two-disk mirror.
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
# Output: mdadm: array /dev/md0 started.
# ============================================
# PART 4: CHECK SYNC PROGRESS
# ============================================

# The array syncs in the background.
cat /proc/mdstat
# md0 : active raid1 sdc[1] sdb[0]
#       [UU]
#       [=>...] resync = 10% ...
# ============================================
# PART 5: CREATE FILESYSTEM
# ============================================

# Format the array with ext4.
sudo mkfs.ext4 /dev/md0
# ============================================
# PART 6: MOUNT AND VERIFY
# ============================================

sudo mkdir -p /mnt/raid1
sudo mount /dev/md0 /mnt/raid1
df -h /mnt/raid1
# ============================================
# PART 7: SAVE CONFIGURATION
# ============================================

# Persist array definition for boot assembly.
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf
# ============================================
# PART 8: CREATE RAID 5 WITH SPARE
# ============================================

# Three active disks, one spare.
sudo mdadm --create /dev/md1 --level=5 --raid-devices=3 --spare-devices=1 /dev/sdd /dev/sde /dev/sdf /dev/sdg
# ============================================
# PART 9: DETAILED ARRAY VIEW
# ============================================

# Show array state, UUID, chunk size, and disk roles.
sudo mdadm --detail /dev/md0

The nine parts trace the creation workflow: identifying disks, clearing signatures, creating the array, monitoring sync, formatting, mounting, persisting configuration, creating a more complex array with a spare, and inspecting the result.


Quick Reference

mdadm Create Flags

FlagPurpose
--create or -CCreate a new array
--level or -lRAID level (0, 1, 5, 6, 10)
--raid-devices or -nNumber of active disks
--spare-devices or -xNumber of spare disks
--chunk or -cChunk size in KiB (default 512)
--metadata or -eMetadata format (default 1.2)
--namePersistent array name

Minimum Disks by Level

LevelMinimum ActiveSpares Allowed
02No
12Yes
53Yes
64Yes
104Yes

Verification Commands

CommandPurpose
cat /proc/mdstatQuick status
mdadm --detail /dev/mdXFull details
lsblkBlock device tree

Best Practices

โœ… Do This:

sudo wipefs -a /dev/sdb
sudo wipefs -a /dev/sdc
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
  • โœ… Clear signatures, then create
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf
  • โœ… Persist configuration for boot assembly
sudo mkfs.ext4 /dev/md0
  • โœ… Create a filesystem after the array is active

โŒ Don’t Do This:

sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda /dev/sdb
  • โŒ Never use a disk containing existing data without verifying
sudo mdadm --create /dev/md0 --level=5 --raid-devices=2 /dev/sdb /dev/sdc
  • โŒ RAID 5 requires at least three active disks
sudo mount /dev/md0 /mnt
  • โŒ Mount only after the filesystem is created

Common Pitfalls

PitfallWhy It HappensFix
Device already in useDisk has existing signaturewipefs -a before creation
Array not assembled on bootmdadm.conf not updatedmdadm --detail --scan >> /etc/mdadm.conf
RAID 5 creation failsFewer than 3 devicesUse at least 3 for level 5
Wrong device namesTypo in device listVerify with lsblk before running
Sync takes too longLarge disksMonitor with /proc/mdstat; array is usable during sync

Real-World Examples

1. RAID 1 Mirror

sudo mdadm -C /dev/md0 -l 1 -n 2 /dev/sdb /dev/sdc

2. RAID 5 with Spare

sudo mdadm -C /dev/md0 -l 5 -n 3 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde

3. RAID 6 Array

sudo mdadm -C /dev/md0 -l 6 -n 4 /dev/sdb /dev/sdc /dev/sdd /dev/sde

4. RAID 10 Array

sudo mdadm -C /dev/md0 -l 10 -n 4 /dev/sdb /dev/sdc /dev/sdd /dev/sde

5. RAID 0 Stripe

sudo mdadm -C /dev/md0 -l 0 -n 2 /dev/sdb /dev/sdc

6. Custom Chunk Size

sudo mdadm -C /dev/md0 -l 5 -n 3 -c 64 /dev/sdb /dev/sdc /dev/sdd

7. Save Configuration

sudo mdadm --detail --scan >> /etc/mdadm.conf

8. Check Sync

watch cat /proc/mdstat

9. Format Array

sudo mkfs.xfs /dev/md0

10. Mount Array

sudo mount /dev/md0 /mnt/raid

Visual

RAID 1 Creation Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  wipefs -a /dev/sdb /dev/sdc                 โ”‚
โ”‚  (clear existing signatures)                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  mdadm --create /dev/md0 --level=1           โ”‚
โ”‚         --raid-devices=2 /dev/sdb /dev/sdc   โ”‚
โ”‚                                              โ”‚
โ”‚  1. Write superblock to both disks           โ”‚
โ”‚  2. Start kernel md driver                   โ”‚
โ”‚  3. Begin background resync                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  /proc/mdstat                                โ”‚
โ”‚  md0 : active raid1 sdc[1] sdb[0]            โ”‚
โ”‚        [UU]                                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  mkfs.ext4 /dev/md0                          โ”‚
โ”‚  mount /dev/md0 /mnt/raid1                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The array is usable immediately after creation, but the resync runs in the background.

Device Roles in RAID 5

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ /dev/sdb โ”‚ โ”‚ /dev/sdc โ”‚ โ”‚ /dev/sdd โ”‚
โ”‚ Disk 0   โ”‚ โ”‚ Disk 1   โ”‚ โ”‚ Disk 2   โ”‚
โ”‚          โ”‚ โ”‚          โ”‚ โ”‚          โ”‚
โ”‚ Active   โ”‚ โ”‚ Active   โ”‚ โ”‚ Active   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
      โ”‚            โ”‚            โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ–ผ
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚   /dev/md0   โ”‚
            โ”‚  RAID 5      โ”‚
            โ”‚  (N-1) cap   โ”‚
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

For RAID 5, the minimum is three active disks. A spare is optional but recommended.


Summary

ItemValue
Create commandmdadm --create /dev/mdX --level=L --raid-devices=N disks
RAID 1 minimum2 devices
RAID 5 minimum3 devices
RAID 6 minimum4 devices
RAID 10 minimum4 devices
Default metadata1.2
Default chunk512 KiB
Persist configmdadm --detail --scan >> /etc/mdadm.conf
Status checkcat /proc/mdstat

Key takeaways:

  • mdadm --create is atomic. It configures the array, writes metadata, and starts the sync in one command. A malformed command may leave disks in an inconsistent state .
  • RAID levels have minimum disk requirements. RAID 1 requires two, RAID 5 requires three, RAID 6 and RAID 10 require four. The --raid-devices value must match the number of active disks .
  • Spares are declared separately. The --spare-devices option adds disks that are not active but can replace failed members. The total disk count is active plus spare .
  • The array is usable during initial sync. Performance is degraded, but the filesystem can be created and mounted immediately after --create returns .
  • Configuration must be persisted. Without /etc/mdadm.conf, the array may not assemble automatically on boot. mdadm --detail --scan generates the correct entry.
  • Metadata format matters for large disks. Version 1.2 supports arrays larger than 2 TB per device. Version 0.90 is legacy and should be avoided unless required .

Remember: Creating a RAID array with mdadm is a single command that does three things: writes metadata to each disk, starts the kernel driver, and begins the initial synchronization. The command must be correct on the first attemptโ€”there is no confirmation prompt, and an incorrect device list can overwrite existing data. Verify device names with lsblk, clear signatures with wipefs, and persist the configuration with mdadm --detail --scan.

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!