Skip to content

Commit c331516

Browse files
author
root
committed
mdadm management instructions v1
1 parent 3358610 commit c331516

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# mdadm
2+
### _Configuring Software raid ([link](https://www.thegeekdiary.com/redhat-centos-managing-software-raid-with-mdadm/))_
3+
4+
We need to make sure all disks have the same partition layout:
5+
```
6+
sfdisk -d /dev/sdb | sfdisk /dev/sdc
7+
```
8+
9+
Now create the RAID device using mdadm
10+
```
11+
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
12+
```
13+
14+
Format the drive and mount it (dir will need to exist)
15+
```
16+
mke2fs -j /dev/md0 && mount /dev/md0 /data01
17+
```
18+
19+
Add fstab entry so persists across reboots
20+
```
21+
/dev/md0 /data01 ext4 defaults 0 0
22+
```
23+
24+
### Verifying the config
25+
26+
/proc/mdstat is a file maintained by the kernel which contains the real time information about the RAID arrays and devices.
27+
```
28+
cat /proc/mdstat
29+
```
30+
31+
If you want some more detailed info use mdadm
32+
```
33+
mdadm --detail /dev/md0
34+
```
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Managing mdadm
2+
3+
### Add and remove devices
4+
5+
To add a device
6+
```
7+
mdadm --add /dev/md0 /dev/sdd
8+
```
9+
10+
To remove a device (-f fail device, -r remove device)
11+
```
12+
# mdadm --manage /dev/md0 -f /dev/sdd
13+
# mdadm --manage /dev/md0 -r /dev/sdd
14+
```
15+
16+
### Replacing failed mirror disk ([link](https://www.thegeekdiary.com/replacing-a-failed-mirror-disk-in-a-software-raid-array-mdadm/))
17+
18+
Before removing raid disks we need to run the following command to write all disk caches to the disk
19+
```
20+
sync
21+
```
22+
23+
Mark as failed
24+
```
25+
mdadm --manage /dev/md0 --fail /dev/sdb1
26+
```
27+
28+
Check /proc/mdstat to make sure the disk has been marked as failed (F)
29+
```
30+
# cat /proc/mdstat
31+
32+
Personalities : [linear] [multipath] [raid0] [raid1] [raid5] [raid4] [raid6] [raid10]
33+
34+
md0 : active raid1 sda1[0] sdb1[2]**(F)**
35+
36+
976773168 blocks [2/1] [U_]
37+
38+
The \*\*(F)\*\* shows the disk has failed
39+
40+
We can now physically remove the disk and replace
41+
```
42+
_Remove and replace disk_
43+
```
44+
45+
We now need to copy the partition table to the newly replaced disk
46+
```
47+
sfdisk -d /dev/sda | sfdisk /dev/sdb
48+
```
49+
50+
Create a mirror of the disk
51+
```
52+
mdadm /dev/md0 --add /dev/sdb1
53+
```
54+
55+
Test the setup
56+
```
57+
mdadm --detail /dev/md0
58+
```
59+
60+
Finally check the progress of the recovery
61+
```
62+
cat /proc/mdstat
63+
```

0 commit comments

Comments
 (0)