|
Linux RAID How-to - Configuring RAID |
|
|
|
|
Written by Tom Hirt
|
|
Thursday, 04 June 2009 14:07 |
|
Page 2 of 2
Configuring RAID
We are now ready to begin our first Linux software RAID configuration. The following steps will walk you through creating a RAID 5 array created from 3 physical disks. Let's get to it!
- Begin by inspecting your system for available devices to create your RAID array
[root@Linux01 ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1305 10377990 8e Linux LVM
Disk /dev/sdb: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Disk /dev/sdc: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Disk /dev/sdd: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System [root@Linux01 ~]#
|
Note: You'll notice dev/sda is in use (contains operating system etc.) but /dev/sdb, /dev/sdc and /dev/sdd are available.
- Create a primary partition of type fb on each of the devices that will be used in the RAID array. In the example below, we will create a primary partition on /dev/sdb. This step should be repeated for each device in the array (i.e. /dev/sdc and /dev/sdd)
[root@Linux01 ~]# fdisk /dev/sdb
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-522, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): Using default value 522
Command (m for help): t Selected partition 1 Hex code (type L to list codes): fb Changed system type of partition 1 to fb (Unknown)
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks. [root@Linux01 ~]#
|
Note: The Linux RAID driver MD only supports files system type fb
- Repeat Step #2 for the remaining devices (i.e. /dev/sdc and /dev/sdd) in the array until each device has been configured with a partition of type fb
Note: If you are using a device that contains existing partitions, you may receive the following warning when exiting fdisk: "The kernel still uses the old table. The new table will be used at the next reboot." You can avoid a reboot by using the partprobe command (i.e. partprobe /dev/sdb).
- Use the RAID admin utility to create an array from the available partitions created from Step #2
[root@Linux01 ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 mdadm: array /dev/md0 started. [root@Linux01 ~]#
|
Notes:
- If you desire a raid level other than 5, you can do so by specifying the level with the --level command line switch. Available options include:
- linear
- raid0 / 0 / stripe
- raid1 / 1 / mirror
- raid4 / 4
- raid5 / 5
- raid6 / 6
- raid10 / 10
- multipath / mp
- faulty
- The --raid-devices switch lets mdadm know how many devices will make up the RAID array. In our example, we are using 3 devices so we specified the number 3 followed by the list of devices. However, if you are using more devices, you should be sure to reflect the correct number and device list in your syntax.
|
Optionally, you can create the array with a hot spare:
[root@Linux01 ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 --hot-spares=1 /dev/sde1 mdadm: array /dev/md0 started. [root@Linux01 ~]#
|
- Monitor the creation of the array
[root@Linux01 ~]# cat /proc/mdstat Personalities : [raid6] [raid5] [raid4] md0 : active raid5 sdd1[3] sdc1[1] sdb1[0] 8385664 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_] [===>.................] recovery = 15.7% (660556/4192832) finish=0.8min speed=73395K/sec
unused devices: [root@Linux01 ~]#
|
Note: Once the recovery has reached 100%, the array will be ready for use
- Add the new array to the /etc/mdadm.conf so that it will be automatically activated upon reboot. The start-up scripts will reference the mdadm.conf file upon boot and start any arrays listed within this file. If the array is not listed in the /etc/mdadm.conf file, you will have to start the array manually.
The following was added to the /etc/mdadm.conf file to satisfy our configuration for the RAID5 array with the 3 devices (sdb1, sdc1 and sdd1):
ARRAY /dev/md0 level=raid5 num-devices=3 devices=/dev/sdb1,/dev/sdc1,/dev/sdd1
|
Note: The mdadm.conf file is used to store configuration parameters for all of your Linux software RAID devices. The above entry will satisfy the minimum requirements in-order for mdadm to start your array. We'll explore other parameters of this file in future kb's.
- Overlay the new RAID device with a file-system
[root@Linux01 ~]# mke2fs -j /dev/md0 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 1048576 inodes, 2096416 blocks 104820 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2147483648 64 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@Linux01 ~]#
|
- Mount the file-system and verify its functionality
[root@Linux01 ~]# mkdir /RAID5 [root@Linux01 ~]# mount /dev/md0 /RAID5/ [root@Linux01 ~]# ls -al /RAID5/ total 28 drwxr-xr-x 3 root root 4096 Jun 11 09:33 . drwxr-xr-x 29 root root 4096 Jun 11 09:35 .. drwx------ 2 root root 16384 Jun 11 09:33 lost+found [root@Linux01 ~]#
|
- Update the /etc/fstab file to auto mount the RAID device upon subsequent system reboots
The following was added to our /etc/fstab to support the RAID5 array we configured in this example:
| /dev/md0 |
/RAID5 |
ext3 |
defaults |
0 |
0 |
|
Note: Your device and mount point may be different depending on your configuration
- If convenient, you can reboot your system to verify the RAID device will auto mount upon reboot
Nice job! Please see our other RAID KB's for advanced use and other helpful RAID tips and tricks:
Add this page to your favorite website
|
|
Last Updated on Thursday, 18 June 2009 14:59 |