No announcement yet.

How to create a software RAID array with custom chunk size and more

This topic is closed.
This is a sticky topic.
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create a software RAID array with custom chunk size and more

    In this example we will create a software raid0 array. The array can change to whatever you need based on how many disks you have. So, adjust accordingly.

    Step 1. Create the /boot, /swap, and / partitions on a separate raid1 array on the same 2 disks and leave the rest of the space on the disks unformatted to be used for the raid0 array.
    Step 2. Login to the server and format the remaining space using fdisk. We will have /dev/sda3 and /dev/sdb3 for the new space. If the disks are larger than 2TB and you used parted instead of fdisk, don't forget to use the 'set' command in parted to change the flag of the new partitions to 'raid'. Run the following after creating the partition: set 3 raid on (keep in mind that the '3' is because we have sda3).
    Step 3. In this example we will create a software raid0 array with chunk size of 2MB. Run the following command:

    mdadm --create --verbose --chunk=2048 /dev/md2 --level=stripe --raid-devices=2 /dev/sda3 /dev/sdb3

    Note: You can use any number for md.../dev/md0, md1, md345 if you want. It does not matter. We used md2 because md0 and md1 were already taken by the raid1 array space for / and for swap that were created in a previous step.

    Note: If you get an error saying that /dev/sda3 and /dev/sdb3 are not found, reboot the server and check your /dev/ folder using ls /dev/sd* command to make sure they are there after the server is up. After verifying that sda3 and sdb3 are in that folder, run the mdadm command again.

    Note: If you get a device buys error, please see here:

    After the command is run successfully, your new array is being created. You can check it using mdadm --detail /dev/md2 command. (replace md2 with whatever md# you used)

    Step 4. Save the RAID configuration

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

    Note: Make sure to check that the path to mdadm.conf is correct.
    Note: After you save the configuration, check the file and comment out any old raid information that is located in that file so there are no double entries.

    Step 5. Create and mount the file system using mkfs.

    mkfs.ext4 -v -m .1 -b 4096 -E stride=512,stripe-width=512 /dev/md2

    Options explained:
    The first command makes a ext4 filesystem
    -v verbose
    -m .1 leave .1% of disk to root (so it doesnt fill and cause problems)
    -b 4096 block size of 4kb (recommended above for large-file systems)
    -E stride=512,stripe-width=512 see below calculation

    chunk size = 2048kB (set by mdadm cmd)
    block size = 4kB (recommended for large files, and most of time)
    stride = chunk / block = 2048kB / 4k = 512
    stripe-width = stride * ( (# of disks in raid array) - 1 ) = 512 * ( (2) - 1 ) = 512 * 1 = 512

    Step 6: Mount /dev/md2 as /home

    mkdir /home
    mount /dev/md2 /home

    Step 7: Update fstab

    /dev/md2 /home ext4 noatime,defaults 0 0

    Now your raid is setup. To further tweak the performance, set your readahead to 512k which is optimal for large file serving.

    To find out what your current readahead value is do 'blockdev --getra /dev/sda' (no quotes and do that command for every drive in the system to see what you have).

    To set a new value do 'blockdev --setra 512 /dev/sda' (no quotes and do this for every drive on the system where you want to change the default ra value. Can be 256, 512, ....,4096, 16384, etc..)

    Good info on software raid arrays:

    ================================================== ============
    This is a rough how to if you want to setup everything on the same raid0 partition via live cd.

    boot into livecd (not netinstaller iso). create partitions using parted (unless the disks are smaller than 2tb) instead of fdisk because it is GPT, then create the raid array with mdadm and the -c flag, then after it is created format it as ext 4 with the stride= and stripe-width= defined, then reboot into installer, do not format anything except the boot partition and then continue with the installation as you normally would.
    From Shared to Dedicated
    Professional. Painless. Polite.

  • #2
    Another great how-to can be found here:
    From Shared to Dedicated
    Professional. Painless. Polite.