Setting up Raid? Here is a quick Guide

 So you have some Disks and you want to archive things now, here's some help lol


Here is a step-by-step of me setting up RAID 5 on 15x 10TB drives using mdadm 


Important Pre-requisites:

  • mdadm installed: sudo apt install mdadm (for Debian/Ubuntu based systems like Pop!_OS)

  • Root privileges: Commands will use sudo.


Step 0: Identify your Partitions Before starting, ensure you have a clear list of the partitions you intend to use. For this guide, we are using the 15 x 9.1TB partitions identified previously:

/dev/sde1 /dev/sdq1 /dev/sdr1 /dev/sds1 /dev/sdz1 /dev/sdaa1 /dev/sdab1 /dev/sdac1 /dev/sdad1 /dev/sdae1 /dev/sdaf1 /dev/sdag1 /dev/sdah1 /dev/sdai1 /dev/sdaj1

WARNING: ALL DATA ON THESE PARTITIONS WILL BE DESTROYED.


Step 1: Zero Out Existing mdadm Superblocks This step clears any old RAID metadata from the partitions, ensuring they are clean for the new array. Even if you suspect they are clean, running this command is harmless for non-RAID partitions and essential for those that might have old metadata.

Bash
sudo mdadm --zero-superblock /dev/sde1 /dev/sdq1 /dev/sdr1 /dev/sds1 /dev/sdz1 /dev/sdaa1 /dev/sdab1 /dev/sdac1 /dev/sdad1 /dev/sdae1 /dev/sdaf1 /dev/sdag1 /dev/sdah1 /dev/sdai1 /dev/sdaj1
  • Expected Output: You might see "Unrecognised md component device" for some partitions. This is normal and means no old superblock was found on that device, confirming it's clean. For other partitions, mdadm will simply zero the superblock without a specific message.


Step 2: Create the RAID 5 Array This command initializes your RAID 5 array. We'll name it /dev/md1.

Bash
sudo mdadm --create /dev/md1 --level=5 --raid-devices=15 /dev/sde1 /dev/sdq1 /dev/sdr1 /dev/sds1 /dev/sdz1 /dev/sdaa1 /dev/sdab1 /dev/sdac1 /dev/sdad1 /dev/sdae1 /dev/sdaf1 /dev/sdag1 /dev/sdah1 /dev/sdai1 /dev/sdaj1
  • Explanation of options:

    • --create /dev/md1: Creates a new array named md1.

    • --level=5: Specifies RAID level 5.

    • --raid-devices=15: Tells mdadm to use all 15 specified devices.

  • Confirmation: You will be prompted to confirm the creation. Type y and press Enter.

  • Expected Output: mdadm: Defaulting to version 1.2 metadata and mdadm: array /dev/md1 started.


Step 3: Monitor Array Synchronization (Optional but Recommended) After creation, the array will immediately begin synchronizing (or "resyncing"). This process involves calculating and writing parity data across all drives and can take a very long time for large drives (hours to days). The array is usable during sync, but performance might be slightly degraded.

Bash
cat /proc/mdstat
  • Expected Output: Look for a line similar to [>....................] resync = XX.X% which indicates the progress. Do not interrupt this process.


Step 4: Create a Filesystem on the New RAID Array Once the array is created (you don't have to wait for sync to finish to do this), you need to format it with a filesystem. ext4 is a common and robust choice. For very large arrays, XFS is also a popular option.

Bash
sudo mkfs.ext4 -F /dev/md1

(Alternatively, for XFS: sudo mkfs.xfs -f /dev/md1)

  • Verification: You can check if the filesystem was created successfully:

    Bash
    sudo blkid /dev/md1
    

    You should see TYPE="ext4" (or xfs) in the output.


Step 5: Create a Mount Point and Mount the Array A mount point is a directory where the contents of your RAID array will be accessible.

Bash
sudo mkdir /mnt/raid5data
sudo mount /dev/md1 /mnt/raid5data
  • Verification: After mounting, you should see your new array listed in df -h:

    Bash
    df -h
    

    Look for a line showing /dev/md1 mounted at /mnt/raid5data with the expected large capacity.


Step 6: Configure Automatic Mounting with /etc/fstab To ensure your RAID array is automatically mounted every time your system boots, you need to add an entry to the /etc/fstab file.

  1. Get the UUID of your RAID array:

    Bash
    sudo blkid -s UUID -o value /dev/md1
    

    Copy the UUID (e.g., bfafcdb9-e4b7-7310-2285-8ce38d46).

  2. Edit the /etc/fstab file:

    Bash
    sudo nano /etc/fstab
    

    Add the following line to the very end of the file, replacing YOUR_MD1_UUID with the actual UUID you copied:

    UUID=YOUR_MD1_UUID /mnt/raid5data ext4 defaults,nofail 0 0
    
    • UUID=...: Identifies the array by its unique ID.

    • /mnt/raid5data: The mount point.

    • ext4: The filesystem type (match what you used in Step 4).

    • defaults: Standard mounting options.

    • nofail: Crucial! Prevents the system from getting stuck at boot if the array isn't available.

    • 0 0: dump utility setting (0 to disable) and fsck pass (0 to disable for RAID).

  3. Save and exit the editor (in Nano: Ctrl+X, then Y, then Enter).


Step 7: Update mdadm.conf and Initramfs for Boot Assembly This step ensures your system knows how to assemble the RAID array very early in the boot process.

  1. Update mdadm.conf:

    Bash
    sudo mdadm --detail --scan --verbose | sudo tee /etc/mdadm/mdadm.conf
    
    • This command scans for all active RAID arrays and writes their configuration to /etc/mdadm/mdadm.conf. You should see entries for both md0 and your new md1 array printed to the screen as they are written to the file.

  2. Update Initramfs:

    Bash
    sudo update-initramfs -u
    
    • This command regenerates the initial RAM filesystem, which contains the necessary modules and configuration to detect and assemble your RAID array before the main system starts.

    • (Note: On some distributions like Fedora/CentOS, the command might be sudo dracut -H -f)


Final Verification: After completing all steps, perform a reboot:

Bash
sudo reboot

Once your system is back up, log in and verify:

  • Is the array assembled?

    Bash
    cat /proc/mdstat
    

    You should see md1 listed as active (and resync might still be running).

  • Is the array mounted?

    Bash
    df -h
    

    You should see /dev/md1 mounted at /mnt/raid5data.

  • Can you write to it?

    Bash
    sudo touch /mnt/raid5data/test_file.txt
    ls /mnt/raid5data/

Comments

Popular Posts