Linux Software RAID

Linux software RAID

Linux software RAID is extensively documented on the Linux software raid wiki. Software RAID is configured with mdadm. Install this with:

sudo yum install -y mdadm

To experiment we need some virtual disks, so create some empty ones:

$ for i in $(seq 1 5) ; do dd if=/dev/zero of=/tmp/disk${i}.img bs=1024 count=1000000 ; done
1000000+0 records in
1000000+0 records out
1024000000 bytes (1,0 GB) copied, 9,95653 s, 103 MB/s
1000000+0 records in
1000000+0 records out
1024000000 bytes (1,0 GB) copied, 11,6938 s, 87,6 MB/s
1000000+0 records in
1000000+0 records out
1024000000 bytes (1,0 GB) copied, 13,3156 s, 76,9 MB/s
1000000+0 records in
1000000+0 records out
1024000000 bytes (1,0 GB) copied, 14,2471 s, 71,9 MB/s
1000000+0 records in
1000000+0 records out
1024000000 bytes (1,0 GB) copied, 18,1411 s, 56,4 MB/s
$ 

and configure them:

$ for i in $(seq 1 5) ; do sudo losetup -f /tmp/disk${i}.img ; done
$ 

Check that everything is ok with losetup -a:

$ sudo losetup -a
/dev/loop0: [fc00]:28591048 (/tmp/disk1.img)
/dev/loop1: [fc00]:28591105 (/tmp/disk2.img)
/dev/loop2: [fc00]:28594691 (/tmp/disk3.img)
/dev/loop3: [fc00]:28594692 (/tmp/disk4.img)
/dev/loop4: [fc00]:28581480 (/tmp/disk5.img)
$ 

Now we’re ready to create a RAID-1 array on two of these disks:

sudo mdadm --create --level=1 /dev/md1 --metadata=1.2 --raid-devices=2 --spare-disks=1 /dev/loop0 /dev/loop1 /dev/loop2

Check status of the array with:

sudo mdadm --detail /dev/md1

Now create a filesystem with mkfs.ext4 and mount it with mount.

sudo mkfs.ext4 /dev/md1

and

sudo mount /dev/md1 /mnt

Simulate disk failure with:

sudo mdadm /dev/md1 --fail /dev/loop0

Now consult the Linux Software RAID wiki pages on Detecting, querying and testing as we simulate a drive failure.

To delete this software RAID array use these commands:

sudo mdadm --stop /dev/md1
sudo mdadm --zero-superblock /dev/loop0
sudo mdadm --zero-superblock /dev/loop1
sudo mdadm --zero-superblock /dev/loop2

Leave a Reply

Your email address will not be published. Required fields are marked *