USB Device RAID 0

Jarret B

Well-Known Member
Staff member
Joined
May 22, 2017
Messages
339
Reaction score
369
Credits
11,689
Redundant Array of Inexpensive Disks (RAID) is an implementation to either improve performance of a set of disks and/or allow for data redundancy. Reading and writing performance issues can be helped with RAID. RAID is made up of various levels. This article covers RAID Level 0 and how to implement it on a Linux system.

RAID 0 Overview

RAID 0 is sometimes referred to as Data Striping without Parity. RAID 0 is the implementation of 2 or more hard drives which are written to in block succession. The meaning of this is that data is written to the first drive in the RAID Array to fill one block. The data is written to each disk one block at a time until the data is completely written. The block size varies on the drive's configuration.

NOTE: Parity is the addition of redundancy which is covered in another article.

Let's look at how to determine the block size of drive. In my example, I am using USB Sticks which are 4 GB each (3.73 GB). To get a list, I use the terminal command:

lsblk

You should see a listing similar to the following:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 74.5G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 4.4G 0 part /boot
├─sda3 8:3 0 34.2G 0 part /
├─sda4 8:4 0 31.3G 0 part /home
└─sda5 8:5 0 4.7G 0 part [SWAP]
sdb 8:16 1 3.7G 0 disk
└─sdb1 8:17 1 3.7G 0 part /media/jarret/ORANGE
sdc 8:32 0 2.7T 0 disk
└─sdc1 8:33 0 2.7T 0 part /media/jarret/My Book
sdd 8:48 1 3.7G 0 disk
└─sdd1 8:49 1 3.7G 0 part /media/jarret/GREEN
sde 8:64 1 3.7G 0 disk
└─sde1 8:65 1 3.7G 0 part /media/jarret/BLUE

To find the Block Size of a drive, such as sde1, use the following command:

sudo blockdev --getbsz /dev/sde1

My result was 512 bytes for the block size. So with these drives, 512 bytes are written to one drive and then the next 512 bytes are written to the next drive and so on until the last drive is written to and the next block is used on Drive 1 and so on until the file is completely written.

NOTE: Be aware that if one drive of the RAID Array fails, then all data is lost on all drives. To prevent the loss of data, then you would need another RAID Level which supports redundancy.

HARDWARE

The three USB drives I can use are called ORANGE, GREEN and BLUE. I named them from the color of the thumb drive. The drives are all Sandisk Cruzer Switches which are USB 2.0 compliant and have a storage of 4 GB (3.7GB).

NOTE: When dealing with RAID arrays, all disks should be the same size. If they are not, they must be partitioned to be the same size. The smallest drive in the array sets the usable size of all of the disks.

I placed all three USB sticks in the same hub and tested the write speed. A file was written to each and timed. The size of the file was 100 MB and took an average time of 12.667 seconds making the average write speed 7.89 MB/sec. I performed a read test and had an average read time of 4 seconds making the average read time of 25 MB/sec.

To set up the RAID Array, you use the command 'mdadm'. If you do not have the file on your system, you will receive an error in a terminal when you enter the command 'mdadm'.

To get the file on your system, use Synaptic or the like for your Linux distro.

Once installed, you are ready to make a RAID 0 Array.

Creating the RAID Array

Open a terminal and type 'lsblk' to get a list of your available drives. Make a note of the drives you are using so you do not type in the wrong drive and add it to the Array.

NOTE: Entering the wrong drive can cause a loss of data.

From the listing of the command from above, I am using sdb1, sdd1 and sde1. The command is as follows:

sudo mdadm --create /dev/md0 --level=0 --raid-devices=3 /dev/sdb1 /dev/sdd1 /dev/sde1 --verbose

The command creates (--create) a RAID Array called md0. The RAID Level is 0. and three devices are being used to create the RAID Array – sdb1, sdd1 and sde1.

The following should occur:

jarret@Symple-PC ~ $ sudo mdadm --create /dev/md0 --level=0 --raid-devices=3 /dev/sdb1 /dev/sdd1 /dev/sde1 --verbose
mdadm: chunk size defaults to 512K
mdadm: /dev/sdb1 appears to be part of a raid array:
level=md0 devices=0 ctime=Wed Dec 31 19:00:00 1969
mdadm: partition table exists on /dev/sdb1 but will be lost or
meaningless after creating array
mdadm: /dev/sdd1 appears to be part of a raid array:
level=md0 devices=0 ctime=Wed Dec 31 19:00:00 1969
mdadm: partition table exists on /dev/sdd1 but will be lost or
meaningless after creating array
mdadm: /dev/sde1 appears to be part of a raid array:
level=md0 devices=0 ctime=Wed Dec 31 19:00:00 1969
mdadm: partition table exists on /dev/sde1 but will be lost or
meaningless after creating array
Continue creating array?

NOTE: If you get an error that the device is busy, then remove 'dmraid'. In a Debian system use the command 'sudo apt-get remove dmraid' and when completed, reboot the system. After the system restarts, try the 'mdadm' command again.

Answer 'y' to the question to 'Continue creating array?' and the following should appear:

mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

The RAID Array is not created and running, but not yet ready for use.

Prepare md0 for use

You may look around, but the drive md0 is not to be found. Open the GParted application and you will see it there ready to be prepared for use.

By selecting /dev/md0 you will get an error that no Partition Table exists on the RAID Array. Select Device from the top menu and then 'Create Partition Table…'. Specify your partition type and click APPLY.

Now, create the Partition and select your file format to be used. It is suggested to use either EXT3 or EXT 4 for formatting the Array, you may also want to select the RAID Flag. Add the Partition scheme and click APPLY. The drives should be formatted as selected and the RAID Array is ready to be mounted for use.

Mount RAID Array

Before closing GParted, look at the Partition name as shown in Figure 1. My Partition name is '/dev/md127p1'. The partition name is important for mounting.

Figure 01.jpg

FIGURE 01


Go to your '/media' folder and as ROOT create a folder, such as RAID, to be used as a mount point. In a terminal, use the command 'sudo mount /dev/md127p1 /media/RAID/' to mount the RAID Array as the media device named RAID.

Now you must take ownership of the RAID Array with the command:

sudo chown -R jarret:jarret /media/RAID

The command uses my username (jarret) and group name (jarret) to take ownership of the mounted RAID Array. Use your own username and mount point.

Now, when I write to the Raid Array, my time to write a 100 MB file is an average of 5 seconds. The speed to write is now 20 MB/sec. Reading a 100 MB file from the RAID Array takes an average of 3 seconds which makes a speed of 33.33 MB/sec.

As you can see, the speed has dramatically increased(write: 7.89 MB/s to 20 MB/s and read: 25 MB/s to 33.3 MB/s). Do remember, if one drive of the Array is removed or fails, the whole Array is lost.

Auto Mount the RAID Array

To have the RAID Array auto mount after each reboot is a simple task. Run the command 'blkid' to get the needed information from the RAID Array. For example, to run it after I mounted my RAID mount point, I would get the following:

/dev/sda2: UUID="73d91c92-9a38-4bc6-a913-048971d2cedd" TYPE="ext4"
/dev/sda3: UUID="9a621be5-750b-4ccd-a5c7-c0f38e60fed6" TYPE="ext4"
/dev/sda4: UUID="78f175aa-e777-4d22-b7b0-430272423c4c" TYPE="ext4"
/dev/sda5: UUID="d5991d2f-225a-4790-bbb9-b9a48e691061" TYPE="swap"
/dev/sdc1: UUID="6fa3cd0b-5498-688c-433b-6b029ed21394" UUID_SUB="5beae050-3f06-393e-5b14-5d8e14c4ebe5" LABEL="Symple-PC:0" TYPE="linux_raid_member"
/dev/sdd1: UUID="6fa3cd0b-5498-688c-433b-6b029ed21394" UUID_SUB="bf5b1cdc-3573-1f3b-5811-16b1410b93b5" LABEL="Symple-PC:0" TYPE="linux_raid_member"
/dev/sde1: UUID="6fa3cd0b-5498-688c-433b-6b029ed21394" UUID_SUB="3ec2efa5-9adf-ad4d-83db-858538e4ee2d" LABEL="Symple-PC:0" TYPE="linux_raid_member"
/dev/md127p1: LABEL="RAID0" UUID="f2f4ce3a-667e-47a0-8918-a229e51123f9" TYPE="ext4"
/dev/sdb1: LABEL="My Book" UUID="54D8D96AD8D94ABE" TYPE="ntfs"

The needed information is the line with the partition '/dev/md127p1'. The Label is RAID and the UUID is 'f2f4ce3a-667e-47a0-8918-a229e51123f9' and the type is EXT4.

Edit the file '/etc/fstab' as ROOT using an editor you prefer and add a line similar to 'UUID=f2f4ce3a-667e-47a0-8918-a229e51123f9 /media/RAID ext4 defaults 0 0'. Here the UUID is used from the blkid command. The mount point of '/media/RAID' shows where the mount point is located. The drive format of ext4 is used. Use the word 'defaults' and then '0 0'. Be sure to use a TAB between each set of commands.

Your RAID 0 drive Array should no be completely operational for use.

Removing the RAID Array

To stop the RAID Array, you need to unmount the RAID mount point then stop the device 'md127p1' as follows:

sudo umount -l /media/RAID
sudo mdadm --stop /dev/md127p1

Once done, you need to reformat the drives and also remove the line from /etc/fstab which
enabled it to be be automounted.

Enjoy your RAID Array!
 
Last edited:

Members online


Top