0%

Linux: key points of raid

RAID stands for “Redundant Array of Independent Disks”.

The RAID levels

Raid 0: stripe mode,no redundancy in this level,not safe for storage.
Raid 1: mirror mode,having redundancy and good at backup.
Raid 1+0:it is the combination of RAID-1 and RAID-0.
Raid 5: at least 3 disks, can stand max 1 disk broken
Raid 6:at least 4 disks, can stand max 2 disks broken

config file

/etc/mdadm.conf
/proc/mdstat

Create

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@client ~]# mdadm --create /dev/md0 --auto=yes --level=5 --raid-devices=3 --chunk=64 /dev/sdb{2,3,4}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@client ~]# mkfs.xfs /dev/md0
meta-data=/dev/md0 isize=512 agcount=8, agsize=65456 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=523648, imaxpct=25
= sunit=16 swidth=32 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=16 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@client mnt]# mkdir raid_md0
[root@client mnt]# mount /dev/md0 /mnt/raid_md0/
[root@client mnt]# df -h /dev/md0
Filesystem Size Used Avail Use% Mounted on
/dev/md0 2.0G 33M 2.0G 2% /mnt/raid_md0

check the status

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@client ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb4[3] sdb3[1] sdb2[0]
2095104 blocks super 1.2 level 5, 64k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>
[root@client ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Raid Level : raid5
Array Size : 2095104 (2046.00 MiB 2145.39 MB)
Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent

State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 64K

Name : client.centos7.study:0 (local to host client.centos7.study)
UUID : add4f325:d589a29e:1f234b1b:309885ff
Events : 18

Number Major Minor RaidDevice State
0 8 18 0 active sync /dev/sdb2
1 8 19 1 active sync /dev/sdb3
3 8 20 2 active sync /dev/sdb4

If mount md0 permanently, need to know md0 UUID

1
2
3
4
5
6
7
8
9
[root@client mnt]# mdadm  --detail /dev/md0  |grep -i uuid
UUID : add4f325:d589a29e:1f234b1b:309885ff
[root@client mnt]# vim /etc/mdadm.conf
ARRAY /dev/md0 UUID : add4f325:d589a29e:1f234b1b:309885ff
[root@client mnt]# blkid /dev/md0
/dev/md0: UUID="acf71d8f-8027-49fc-b3dd-fe6d89f3491f" TYPE="xfs"
[root@client mnt]# vim /etc/fstab
UUID="acf71d8f-8027-49fc-b3dd-fe6d89f3491f" /mnt/raid_md0 xfs defaults 0 0
[root@client mnt]# mount -a

Close raid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
[root@client mnt]# umount /dev/md0
[root@client ~]# mdadm --manage /dev/md0 --fail /dev/sdb2
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: set /dev/sdb2 faulty in /dev/md0
[root@client ~]# mdadm --manage /dev/md0 --fail /dev/sdb3
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: set /dev/sdb3 faulty in /dev/md0
[root@client ~]# mdadm --manage /dev/md0 --fail /dev/sdb4
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: set /dev/sdb4 faulty in /dev/md0
[root@client ~]# mdadm --detail /dev/md0
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
/dev/md0:
Version : 1.2
Creation Time : Wed Jul 17 11:37:14 2019
Raid Level : raid5
Array Size : 2095104 (2046.00 MiB 2145.39 MB)
Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent

Update Time : Wed Jul 17 12:53:53 2019
State : clean, FAILED
Active Devices : 0
Failed Devices : 3
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 64K

Number Major Minor RaidDevice State
- 0 0 0 removed
- 0 0 1 removed
- 0 0 2 removed

0 8 18 - faulty /dev/sdb2
1 8 19 - faulty /dev/sdb3
3 8 20 - faulty /dev/sdb4
[root@client ~]# mdadm --manage /dev/md0 --remove /dev/sdb2
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: hot removed /dev/sdb2 from /dev/md0
[root@client ~]# mdadm --manage /dev/md0 --remove /dev/sdb3
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: hot removed /dev/sdb3 from /dev/md0
[root@client ~]# mdadm --manage /dev/md0 --remove /dev/sdb4
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: hot removed /dev/sdb4 from /dev/md0
[root@client ~]# mdadm --detail /dev/md0
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
/dev/md0:
Version : 1.2
Creation Time : Wed Jul 17 11:37:14 2019
Raid Level : raid5
Array Size : 2095104 (2046.00 MiB 2145.39 MB)
Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
Raid Devices : 3
Total Devices : 0
Persistence : Superblock is persistent

Update Time : Wed Jul 17 12:55:39 2019
State : clean, FAILED
Active Devices : 0
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 64K

Number Major Minor RaidDevice State
- 0 0 0 removed
- 0 0 1 removed
- 0 0 2 removed
[root@client ~]# mdadm --stop /dev/md0
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: stopped /dev/md0
[root@client ~]# mdadm --detail /dev/md0
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and add4f325:d589a29e:1f234b1b:309885ff
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: cannot open /dev/md0: No such file or directory
[root@client ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
unused devices: <none>
[root@client ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 29.9G 0 disk
├─sdb1 8:17 0 2G 0 part
│ ├─thin_vg-thinpool_tmeta 253:4 0 4M 0 lvm
│ │ └─thin_vg-thinpool-tpool 253:6 0 1G 0 lvm
│ │ ├─thin_vg-thinpool 253:7 0 1G 0 lvm
│ │ └─thin_vg-annathin1 253:8 0 10G 0 lvm
│ └─thin_vg-thinpool_tdata 253:5 0 1G 0 lvm
│ └─thin_vg-thinpool-tpool 253:6 0 1G 0 lvm
│ ├─thin_vg-thinpool 253:7 0 1G 0 lvm
│ └─thin_vg-annathin1 253:8 0 10G 0 lvm
├─sdb2 8:18 0 1G 0 part
├─sdb3 8:19 0 1G 0 part
└─sdb4 8:20 0 1G 0 part
sdc 8:32 0 40G 0 disk
sr0 11:0 1 1024M 0 rom
[root@client ~]# vim /etc/mdadm.conf
#ARRAY /dev/md0 UUID : add4f325:d589a29e:1f234b1b:309885ff
[root@client ~]# vim /etc/fstab
#UUID="acf71d8f-8027-49fc-b3dd-fe6d89f3491f" /mnt/raid_md0 xfs defaults 0 0