Personal tools
You are here: Home Team Members Dave Riches Software Raid In Fedora

Software Raid In Fedora

by dcr226 last modified Feb 16, 2011 09:18 AM
— filed under:

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

     
  1. 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)

  1. 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

  1. Use fdisk to partition the first drive, making it read for raid use:
  2. 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

 
  1.  Backup the partitioning information from drive 1 to ensure the partition layouts will match
  2. 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.
  3. Copy the partition layout to sdc:
  4. 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
  5. Now create the raid device, in our case we will be creating a raid level 1 with 2 devices, sdb1 and sdc1:
  6. 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:
  7. Confirm your array is functioning:
  8. 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>
  9. Create a mdadm.conf from your current configuration:
  10.  mdadm --detail --scan > /etc/mdadm.conf
  11. Last, but not least - you need to use dracut to rebuild the initramfs with the new mdadm.conf

  12. mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).old.img

    dracut --mdadmconf /boot/initramfs-$(uname -r).img $(uname -r)
  13. Now you can format your raid array with whatever format you choose, for example:
  14. mkfs.ext4 /dev/md0
  15. And mount your array:
  16.  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.

  1. The command 'mount' should show your mounted /dev/md0
  2. cat /proc/mdstat should show the condition of your array
  3. 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.
  4. You can also software simulate a drive failure by executing the following command:
  5. 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

Added Reading

Document Actions
Log in


Forgot your password?
New user?