Creating a RAID array
Enough of the theory, here's how you can create a drive RAID via the command line on pretty much any flavor of Linux. Now, just like every Linux, this is simple operation if you follow the instructions. Do not be afraid and just take things one step at the time. We are going to try to be as clear as possible, but this is not a walk in the park such as Windows shenanigans.
Our example is creation of a RAID array on a virtual machine with 6 virtual 100 MB disks. If you create a RAID5 among four or more SATA disks, the creation process can range from a few minutes up to an hour or more, depending on your system performance. We will take a look at what this procedure can do for your virtual machine in a follow-up story.

Initial window, preparing for RAID initialization
First thing you need to need are the mdadm tools that are used in this guide. Not all distributions supply this with a basic setup, so you‘d need either "apt-get install mdadm" if you're on a Debian based Linux Distribution (like Ubuntu) or just check with your package manager to install the mdadm tools.
Second thing to do is to create a partition and mark it with a type that Linux will recognize as a special RAID partition.
admin@debian-vm:~$ sudo fdisk /dev/sdb
Command (m for help): m (Type in 'm') (Let's look at the options we have here)
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command action
e extended
p primary partition (1-4)
Partition number (1-4): 1 (Type in '1') (We want the whole drive, so we need just one partition)
First cylinder (1-102, default 1): (simply press ENTER to accept the default values)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-102, default 102):
Using default value 102
Command (m for help): t (Type in 't') (Now we need to set the type of the partition)
Selected partition 1
Hex code (type L to list codes): L (Type in 'L') (Just to check the options we have available)
0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot
1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris
2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx
6 FAT16 42 SFS 86 NTFS volume set da Non-FS data
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3 75 PC/IX
Hex code (type L to list codes): fd (Type in 'fd') (fd - 'Linux raid auto' is what we need)
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): p (Type in 'p') (Have a look at the new partition table)
Disk /dev/sdb: 107 MB, 107413504 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk identifier: 0x2c47d250
Device Boot Start End Blocks Id System
/dev/sdb1 1 102 104432 fd Linux raid autodetect
If you think something is wrong and decide to exit without making any changes, type in 'q'
Command (m for help): w (all fine, let's write that partition table to the disk)
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
admin@debian-vm:~$
Now you'll need to repeat that with all the drives you want to add to your RAID
example:
sudo fdisk /dev/sdc
sudo fdisk /dev/sdd

Taking it easy, just type in commands that suit your needs - all the commands are listed below.
After this is done for all the disks in your system, you can easily add all your drives to the new RAID you want to have. All you need is this little line:
mdadm --create /dev/device_name (we use mdX) --level=Y (anything from 0, 1, 10, 4, 5 or 6) --raid-devices=Z (number of drives you want to add) /dev/hdX1 or /dev/sdX1 (you'll need to know the names of the partitions you want to add and set that '1' because you want to access the first partition of that drive)
Creating a RAID0
admin@debian-vm:~$ sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: array /dev/md0 started.
admin@debian-vm:~$ cat /proc/mdstat (this will give us a brief info on our RAIDs)
Personalities: [raid0]
md0 : active raid0 sdc1[1] sdb1[0]
208640 blocks 64k chunks
unused devices: <none>
Creating a RAID1
admin@debian-vm:~$ sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: array /dev/md0 started.
admin@debian-vm:~$ cat /proc/mdstat (this will give us a brief info on our RAIDs)
Personalities: [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
104320 blocks 64k chunks
unused devices: <none>
Creating a RAID10
admin@debian-vm:~$ sudo mdadm --create /dev/md10 --level=10 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: array /dev/md10 started.
admin@debian-vm:~$ cat /proc/mdstat
Personalities : [raid0] [raid1] [raid10]
md10 : active raid10 sde1[3] sdd1[2] sdc1[1] sdb1[0]
208640 blocks 64K chunks 2 near-copies [4/4] [UUUU]
unused devices: <none>
admin@debian-vm:~$
Creating a RAID4
admin@debian-vm:~$ sudo mdadm --create /dev/md4 --level=4 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: array /dev/md10 started.
admin@debian-vm:~$ cat /proc/mdstat (so it's running in the background, let's check it)
Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md4 : active raid4 sde1[4] sdd1[2] sdc1[1] sdb1[0]
312960 blocks level 4, 64k chunk, algorithm 0 [4/3] [UUU_]
[==============>......] recovery = 72.5% (76544/104320) finish=0.0min speed=25514K/sec
unused devices: <none>
admin@debian-vm:~$ cat /proc/mdstat (do it again to check if it's done)
Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md4 : active raid4 sde1[3] sdd1[2] sdc1[1] sdb1[0]
312960 blocks level 4, 64k chunk, algorithm 0 [4/4] [UUUU]
unused devices: <none>
admin@debian-vm:~$
Creating a RAID5
admin@debian-vm:~$ sudo mdadm --create /dev/md5 --level=5 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: array /dev/md5 started.
admin@debian-vm:~$ cat /proc/mdstat
Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md5 : active raid5 sde1[4] sdd1[2] sdc1[1] sdb1[0]
312960 blocks level 5, 64k chunk, algorithm 2 [4/3] [UUU_]
[================>....] recovery = 83.3% (87552/104320) finish=0.0min speed=29184K/sec
unused devices: <none>
admin@debian-vm:~$ cat /proc/mdstat
Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md5 : active raid5 sde1[3] sdd1[2] sdc1[1] sdb1[0]
312960 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]
unused devices: <none>
Creating a RAID6
admin@debian-vm:~$ sudo mdadm --create /dev/md6 --level=6 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: array /dev/md6 started.
admin@debian-vm:~$ cat /proc/mdstat
Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md6 : active raid6 sde1[3] sdd1[2] sdc1[1] sdb1[0]
208640 blocks level 6, 64k chunk, algorithm 2 [4/4] [UUUU]
[=======>.............] resync = 39.2% (41600/104320) finish=0.0min speed=13866K/sec
unused devices: <none>
admin@debian-vm:~$ cat /proc/mdstat
Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md6 : active raid6 sde1[3] sdd1[2] sdc1[1] sdb1[0]
208640 blocks level 6, 64k chunk, algorithm 2 [4/4] [UUUU]
unused devices: <none>
That's fairly straight forward and easy. Now you can put on any kind of file system that you want to use. Ext2 or Ext3 are very common, but you can also use XFS or ReiserFS on this. It works just like a new hard drive. The name is the name you set in the /dev/mdX parameter used when the RAID was created.
Once you initiated the RAID creation process, it'll automatically run in the background and you can view at the status by looking at "/proc/mdstat". Once the creation is done, you should consider checking this device very frequently or set up mdadm to send you emails once something happens. The man pages of mdadm are very well written and will tell you everything about the capabilities of the MD modules. We strongly recommend you take a look at them before you create a RAID.
CONTINUED: Adding a spare drive, Growing your RAID and Conclusion
© 2009 - 2013 Bright Side Of News*, All rights reserved.