Task
1. Use four partitions to form RAID5.
2. Each partition is about 1GB in size. It is necessary to ensure that the capacity of each partition is the same.
3..1 partition is set as spare disk. The size of this spare disk is the same as that of other RAID required partitions.
4. Mount this RAID5 device to the /mnt/raid directory
#Mount a 20G separate hard drive (sdb) in advance. The partition code of the disk is 5-9
1. First use fdisk to create a disk device (use extended partitions to divide logical partitions)
fdisk /dev/sdb
Extended partition is set to 10GB
Then separate logical partitions from the extended partition, respectively (/dev/sdb5 /sdb6 /sdb/7 /sdb8) /sdb9)
The picture shows logical partition 5. Set the other four partitions in the same way, and finally save with w
View partition status
fdisk -l /dev/sdb
2. Use mdadm to create RAID (the steps are to uninstall first. Then stop /dev/md0)
yum source installation mdadm
yum install -y mdadm
umount /dev/md0 /media/md0 #取消挂载
mdadm -S /dev/md0
An error occurs. This is mainly because there is no md0 device file under /dev/. You need to use the mknod command to create one.
mknod /dev/md0 b 9 0 #b为块设备,9为主设备号,0为次设备号
problem solved
Create RAID using mdadm
mdadm --create --auto=yes /dev/md0 --level=5 --raid-devices=4 --spare-devices=1 /dev/sdb{5,6,7,8,9}
Check the details of the created RAID5
mdadm --detail /dev/md0
/dev/md0:
4. Format and mount using RAID
mdfs -t ext4 /dev/md0 #格式化/dev/md0
mkdir /mnt/raid #创建挂载点raid
mount /dev/md0 /mnt/raid #挂载md0到raid上
df #查看
5. Test the automatic disaster redundancy function of RAID5 (/dev/sdb9 automatically replaces /dev/sdb6)
mdadm /dev/md0 --fail /dev/sdb6
mdadm --detail /dev/md0
Replaced successfully.