CentOS6.5 create soft RAID
What is RAID?
RAID, Redundant Array of Independent Disks, formerly known as Redundant Array of Inexpensive Disks, is short for hard disk arrays. The basic idea is to combine multiple relatively inexpensive hard disks into a hard disk array group, so that the performance can reach or even exceed a hard disk with a high price and huge capacity. Depending on the selected version, RAID has the following advantages over a single hard disk: Enhanced Data Integration, enhanced fault tolerance, and increased processing capacity or capacity. In addition, the disk array looks like a separate hard disk or logical storage unit for a computer. It can be divided into RAID 0, RAID 1, RAID 1E, RAID 5, RAID 6, RAID 7, RAID 10, RAID 50, and RAID 60.
To put it simply, RAID combines multiple hard disks into one logical sector. Therefore, the operating system only treats them as one hard disk. RAID is often used on server computers, and identical hard disks are often used as a combination. As Hard Disk prices continue to decline and RAID functions are more effectively integrated with the motherboard, it has become a choice for players, especially those who need large storage space, such as video and audio production.
The initial RAID is divided into different levels, each of which has its own theoretical advantages and disadvantages. Different Levels strike a balance between the two targets, increasing data reliability and increasing storage (group) read/write performance. Over the years, applications with different RAID concepts have emerged.
How to Create a soft RAID
If you want to create a RAID, you must have a disk array card. Currently, most servers have such hardware, which is easy to create. It is a silly operation, but it will certainly be different between different vendors, but they are all similar. But today we want to discuss how to create a soft RAID without a disk array card. Let's take a look.
Preparation
- Yum install-y parted mdadm
View disk usage
- Fdisk-cul
- Disk/dev/sdb: 2147 MB, 2147483648 bytes
- 255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
- Units = sectors of 1*512 = 512 bytes
- Sector size (logical/physical): 512 bytes/512 bytes
- I/O size (minimum/optimal): 512 bytes/512 bytes
- Disk identifier: 0x00000000
- Disk/dev/sdc: 2147 MB, 2147483648 bytes
- 255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
- Units = sectors of 1*512 = 512 bytes
- Sector size (logical/physical): 512 bytes/512 bytes
- I/O size (minimum/optimal): 512 bytes/512 bytes
- Disk identifier: 0x00000000
Start
To demonstrate this, I created two 2G hard disks in the virtual machine. We can see that they are sdb and sdc respectively. We can build these two hard disks into a soft RAID 1. The operation is as follows:
- Fdisk/dev/sdb
- Command (m for help): n # Enter n and press Enter.
- Command action
- E extended
- P primary partition (1-4)
- P # Enter p and press Enter.
- Partition number (1-4): 1 # Enter 1 and press ENTER
- First cylinder (1-261, default 1): # Press ENTER
- Using default value 1
- Last cylinder, + cylinders or + size {K, M, G} (1-261, default 261): # Press ENTER
- Using default value 261
- Command (m for help): t # input t, press ENTER
- Selected partition 1
- Hex code (type L to list codes): fd # Enter fd and press ENTER
- Changed system type of partition 1 to fd (Linux raid autodetect)
- Command (m for help): w # input w, save and release
- The partition table has been altered!
- Calling ioctl () to re-read partition table.
- Syncing disks.
Now sdb is changed to a raid hard disk. You can use fdisk-cul to check whether sdc works the same way.
- Fdisk-cul
- Device Boot Start End Blocks Id System
- /Dev/sdb1 1 261 2096451 fd Linux raid autodetect
- /Dev/sdc1 1 261 2096451 fd Linux raid autodetect
- # If you directly add a hard disk to the server, you need to execute a command
- Partprobe-
- # In this way, you do not need to restart the server and add the new hard disk to the battle.
Create RAID
The next step is simple. You only need to build and format the two hard disks through the mdadm Command Group and then mount them to a specific directory. The operation is as follows:
- # Check the parameters of this command before performing the operation.
- -C # create a software RAID
- -L # specify the RAID level
- -N # specify the number of disks
- -X # specify the number of slave devices
- Mdadm-C/dev/md1-l 1-n 2/dev/sdb1/dev/sdc1
- Mdadm: array/dev/md1 started. # prompt that you have created successfully
- # View the md1 device details just created
- Mdadm -- detail/dev/md1
- /Dev/md1:
- Version: 1.2
- Creation Time: Wed Nov 12 16:19:53 2014 # Creation Time
- Raid Level: RAID 1 # Raid Level
- Array Size: 2095360 (2046.59 MiB 2145.65 MB) # Size of RAID disk space
- Used Dev Size: 2095360 (2046.59 MiB 2145.65 MB)
- Raid Devices: 2 # Number of disks
- Total Devices: 2
- Persistence: Superblock is persistent
- Update Time: Wed Nov 12 17:19:04 2014
- State: clean
- Active Devices: 2 # Number of Active Disks
- Working Devices: 2 # Number of Working Disks
- Failed Devices: 0 # Number of disks with errors
- Spare Devices: 0 # Number of Spare disks
- Name: server1: 1 (local to host server1)
- UUID: ae9a70dd: dc2917a7: de515e04: f82950a7
- Events: 21
- Number Major Minor RaidDevice State
- 0 8 17 0 active sync/dev/sdb1
- 1 8 33 1 active sync/dev/sdc1
Format and Mount
- Mkfs. ext4/dev/md1 # format as ext4
- Mkdir/raid1 # create the directory to be mounted
- Mount/dev/md1/raid1 # mount
- # Set the device of the disk array to automatically mount the device when it is started
- Echo "DEVICE/dev/sdb1/dev/sdc1">/etc/mdadm. conf
- Mdadm-Evs>/etc/mdadm. conf
- Echo "/dev/md1/raid1 ext4 defaults 0 0">/etc/fstab
At this point, all the work is done, done, and finished!