Software Raid In Fedora
Software raid can be really useful for a variety of different scenarios. The different types of raid available and their individual pros and cons are outside of the scope of this howto, but for the purposes of this document, we will be discussing raid 1. Although RAID 1 should not be considered a backup solution, it does provide fault tolerance by mirroring two drives, and allowing the array to function on only one drive whilst the second is replaced in the event of failure.
Applicable to Fedora Versions
Fedora 13 +Requirements
- mdadm - installed by default
Doing the Work
The remainder of this document uses commands on a bash shell. This can either be inside a terminal or logged into the console (init 1 or 3)
- Determine which drives you want to create the array from
su -c "fdisk -l"
This will display a partition information for the available block devices on the system. In our case, we have two drives that we want to create the array from, brand new and unformatted, our raid members are sdb and sdc
Disk /dev/sdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006eada
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1045 7875584 8e Linux LVM
Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
- Use fdisk to partition the first drive, making it read for raid use:
su -c "fdisk /dev/sdb"
Press n to create a new partition, then p for primary, then 1 for partition number 1. Agree to the default options to use the maximum space on the device. Next change the partition type by pressing 't' , then typing 'fd' to select Linux Raid Autodetect.
running su -c "fdisk -l /dev/sdb1" should now return something like:
#su -c fdisk -l /dev/sdb"
Disk /dev/sdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x49f5ea74
Device Boot Start End Blocks Id System
/dev/sdb1 1 65270 524281243+ fd Linux raid autodetect
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006eada
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1045 7875584 8e Linux LVM
Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x698fc7ee
Device Boot Start End Blocks Id System
/dev/sdc1 1 65270 524281243+ fd Linux raid autodetect
- Backup the partitioning information from drive 1 to ensure the partition layouts will match
- Copy the partition layout to sdc:
- Now create the raid device, in our case we will be creating a raid level 1 with 2 devices, sdb1 and sdc1:
- Confirm your array is functioning:
- Create a mdadm.conf from your current configuration:
- Last, but not least - you need to use dracut to rebuild the initramfs with the new mdadm.conf
- Now you can format your raid array with whatever format you choose, for example:
- And mount your array:
su -c "sfdisk -d /dev/sdb > raid.layout"
This will create a file, raid.layout which will be used in the next step to copy the partition layout to sdc.
su -c "sfdisk --force /dev/sdc < raid.layout"
If you now run fdisk -l you should see identical partition layouts for sdb and sdc:
Disk /dev/sdb: 536.9 GB, 536870912000 bytes 255 heads, 63 sectors/track, 65270 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x9e5ea403 Device Boot Start End Blocks Id System /dev/sdb1 1 65270 524281243+ fd Linux raid autodetect Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0006eada Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 1045 7875584 8e Linux LVM Disk /dev/sdc: 536.9 GB, 536870912000 bytes 255 heads, 63 sectors/track, 65270 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sdc1 1 65270 524281243+ fd Linux raid autodetect
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
you should now be greeted with a message to say the raid has been started:
cat /proc/mdstat
and you should get something like:
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
524280083 blocks super 1.2 [2/2] [UU]
[>....................] resync = 0.0% (135488/524280083) finish=902.5min speed=9677K/sec
unused devices: <none>
mdadm --detail --scan > /etc/mdadm.conf
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).old.img
dracut --mdadmconf /boot/initramfs-$(uname -r).img $(uname -r)
mkfs.ext4 /dev/md0
mount /dev/md0 /mnt/my-raid
How To Test
There are many ways to test a raid array, but we will run through a couple of them here.
- The command 'mount' should show your mounted /dev/md0
- cat /proc/mdstat should show the condition of your array
- You can simulate a failure by shutting down the machine, disconnecting one of the drive's power supply and rebooting. cat /proc/mdstat should now show a degraded array.
- You can also software simulate a drive failure by executing the following command:
mdadm /dev/md0 --fail /dev/sdb1
If successful, /proc/mdstat will say something like:
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0](F)
524280083 blocks super 1.2 [2/1] [_U]
unused devices: <none>
More Information
Disclaimer
We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #fedora on irc.freenode.net

