Tag: raid

  • How to delete an mdadm RAID Array

    How to delete an mdadm RAID Array

    Deleting a software RAID array will result in all data stored in the devices being lost. So be careful when you remove a RAID array, take backups in case needed.

    Before you can remove the software RAID array, you need to unmount it.

    umount /dev/mdX

    Where /dev/mdX is the device name for the RAID device you need to remove.

    Find the disk used to create the RAID with the command

    mdadm --detail /dev/mdX

    Stop the RAID device with the command

    mdadm --stop /dev/mdX

    Now you need to run the following commands for each storage device that are part of the RAID device.

    mdadm --zero-superblock /dev/sdXY

    IMPORTANT: you need to run this for each member of the RAID device.

    Finally, edit /etc/mdadm/mdadm.conf, and remove the entry for the RAID array.

  • RAID getting created as /dev/md127

    RAID getting created as /dev/md127

    When I create software RAID with mdadm, it gets created as /dev/md127, instead of /dev/md0 I specified while creating RAID.

    RAID /dev/md127

    To fix this, you need to add RAID definition in /etc/mdadm/mdadm.conf, this can be done with

    mdadm --detail --scan >> /etc/mdadm/mdadm.conf
    

    Now run command

    update-initramfs -u
    

    Reboot the server, after reboot, RAID device will be named properly.

  • How to  Setup Software RAID 0 on Linux Server

    How to Setup Software RAID 0 on Linux Server

    RAID 0 allows you to combine multiple disks into one large disk. Only use RAID 0 if the data is not important to you, for example, a backup server. If one disk fails in a RAID 0 array, all the data will be lost.

    To create a software RAID 0 with 2 or more disks, first, we need to prepare the disks to be used as RAID members. Run the following commands on each of the disks we will be adding to the RAID 0 array.

    parted /dev/sdX mklabel gpt
    parted /dev/sdX mkpart primary ext4 0% 100%
    parted /dev/sdX set 1 raid on

    Replace /dev/sdX with actual device names and run the commands for all devices you will be adding to the RAID 0.

    Create RAID 0

    To create RAID 0, run the following command

    mdadm --create --verbose /dev/md0 --raid-devices=2 --level=0 /dev/sdc1 /dev/sdd1

    In the above command,

    –raid-devices=2 = number of disks in the RAID. In this case, we have 2 disks. If you have more than 2 disks, change the number accordingly.

    /dev/sdc1 /dev/sdd1 = device names, change it with your actual device names. If you have more devices, add them.

    /dev/md0 = raid device name, it can be md0, md1, md2 etc..

    Format RAID device

    Before you can use RAID device, you need to format it.

    mkfs.ext4 /dev/mdX

    Replace /dev/mdX with your actual device name.

    Updating mdadm.conf

    Run

    mdadm --detail --scan

    It will print RAID definitions like the following example

    root@grml ~ # mdadm --detail --scan
    ARRAY /dev/md0 metadata=1.2 name=grml:0 UUID=44f0ec6b:f8311a0c:382295f8:d41fa0fe
    root@grml ~ #  

    You need to edit the file

    vi /etc/mdadm/mdadm.conf 

    Add the ARRAY definitions at end of the file. If any definitions are already there, don’t repeat them.

    Mounting New RAID Device

    Before you can mount RAID device, you need to find UUID for the raid device, this can be done with command

    blkid
    

    Example

    root@grml ~ # blkid
    /dev/loop0: TYPE="squashfs"
    /dev/sda2: UUID="feacd62e-d23f-483d-8971-aa3f110fea05" TYPE="swap" PARTUUID="3019f70f-516a-493f-97cf-2aa001e1c574"
    /dev/sda3: UUID="f162656d-bde9-4b14-8823-21e2a1618a2d" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="1fd4e63f-33a4-4c52-bc00-915c9d7965b8"
    /dev/sda4: UUID="52ceb7c4-f065-4cc7-9c19-276a98be29a8" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b8f92699-2892-482c-8abe-b90ca91b5fc0"
    /dev/sdb1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="65fd2c84-1217-2df7-2a2c-83046458805a" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="b197077b-4a34-4459-8230-5c2a3b1c7085"
    /dev/sdc1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="fedb9e98-dd9f-daed-fc63-4f6a86ebfc9e" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="807fda4f-d22b-4fa7-8810-839e68ae917e"
    /dev/sdd1: UUID="44f0ec6b-f831-1a0c-3822-95f8d41fa0fe" UUID_SUB="071de57a-6d12-70e8-ed6d-cefe8371e915" LABEL="grml:0" TYPE="linux_raid_member" PARTLABEL="primary" PARTUUID="76f0cbbe-858a-4153-87dd-5665d1ac9939"
    /dev/sda1: PARTUUID="9034a389-a6b2-424e-bd19-ce7e55561eba"
    /dev/md0: UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154" BLOCK_SIZE="4096" TYPE="ext4"
    root@grml ~ # 

    In this cause UUID for /dev/md0 is

    UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154"

    Edit /etc/fstab

    vi /etc/fstab

    Add

    UUID="9bd3d3ee-cc6b-43d5-91ed-627440cc9154"   /home  ext4    defaults  0       1

    In the above

    /home = is the mount point. If you need to mount the new RAID device as another folder, you need to create an empty directory first.

    UUID=”9bd3d3ee-cc6b-43d5-91ed-627440cc9154″ = replace with your actual UUID.

    Check status of raid

    To see the status of the RAID, use the command

    cat /proc/mdstat
    

    Find RAID details

    To find RAID details, use the following command

    mdadm --detail /dev/mdX

    Back to RAID

  • Creating Software RAID 5

    Creating Software RAID 5

    RAID 5 Requires 3 or more physical disks. It provides the redundancy of RAID 1 combined with the speed and size benefits of RAID 0. RAID 5 uses striping, like RAID 0, but also stores parity blocks distributed across each member disk. In the event of a failed disk, these parity blocks are used to reconstruct the data on a replacement disk. RAID 5 can withstand the loss of one member disk.

    I have a server with 4 * 4 TB Disks. Here is parted -l result on the server.

    On this server /dev/sda, /dev/sdb, /dev/sdc and /dev/sdd are 4 TB disks and are not in use. Lets format these disk to be used as RAID 5.

    Following commands need to be executed for each of the disks.

    parted -a optimal /dev/sda
    mklabel gpt
    mkpart primary ext4 0% 100%
    set 1 raid on
    align-check optimal 1
    print
    quit
    

    This will partition the disks, set file system as raid.

    Repeat the steps for /dev/sdb, /dev/sdc and /dev/sdd.

    Now you have all disks formatted, ready to be used in raid array.

    Create RAID 5 array with command

    mdadm --create --verbose --level=5 --chunk=64 --raid-devices=4 --layout=left-symmetric /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
    

    Once raid created, you can see status with command

    cat /proc/mdstat
    

    Before we can use raid array, we need to create a file system on the raid with command

    mkfs.ext4 /dev/md0
    

    formatting raid 5 array

    Create mdadm.conf file with following command

    mkdir /etc/mdadm/
    cat /etc/mdadm/mdadm.conf
    mdadm --detail --scan >> /etc/mdadm/mdadm.conf
    cat /etc/mdadm/mdadm.conf
    

    Mount Raid 5 Array

    I want to mount the new raid 5 array as /home. For this i edited /etc/fstab, added

    /dev/md0        /home           ext4    errors=remount-ro 0       1
    

    After rebooting, i have 11 TB RAID 5 drive mounted as /home