Linux Create Software RAID 1 (Mirror) Array

In Linux, you can create a software RAID 1 (mirror) array using the mdadm utility. Here are the steps to create a RAID 1 array:

  1. Check the current disk configuration using the fdisk command:
    # fdisk -l
  2. Partition the disks that will be used in the RAID array using the fdisk command:
    # fdisk /dev/sdb
    # fdisk /dev/sdc

    Note: Replace /dev/sdb and /dev/sdc with the appropriate disk device names for your system.

  3. Create a RAID 1 array using the mdadm command:
    # mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

    Note: Replace /dev/md0, /dev/sdb1, and /dev/sdc1 with the appropriate device names for your system. The --level=1 option specifies that the array should be a RAID 1 (mirror) array, and the --raid-devices=2 option specifies that there will be two disks in the array.

  4. Format the RAID array using the mkfs command:
    # mkfs.ext4 /dev/md0

    Note: Replace /dev/md0 with the appropriate device name for your system.

  5. Create a mount point for the RAID array:
    # mkdir /mnt/raid1
  6. Mount the RAID array using the mount command:
    # mount /dev/md0 /mnt/raid1

    Note: Replace /dev/md0 and /mnt/raid1 with the appropriate device and mount point names for your system.

  7. Add the RAID array to the mdadm configuration file so that it will be automatically assembled at boot time:
    # mdadm --detail --scan >> /etc/mdadm.conf
  8. Update the initramfs image to include the RAID array configuration:
    # update-initramfs -u

    Note: This step may not be necessary on all systems, depending on the distribution and version of Linux.

Once the RAID array is created and mounted, you can use it like any other file system. The data written to one disk will be mirrored to the other disk, providing redundancy in case of a disk failure.

Leave a Comment