Linux - how to replace the original disk with a new one in RAID 1 via mdadm
SITUATION: We need to replace the original / dev / sdb with a new one on a Linux server where two drives are set up in RAID1 managed via mdadm. How do we make such a raid field exchange?
# set fail / dev / sdb1
root@server:/#
# situation
root@server:/#
# remove /dev/sdb1 from /dev/md0
root@server:/#
# situation
root@server:/#
We shut down, remove the old sdb disk, mount the new sdb disk
# overwrite the disk (partition) layout from /dev/sdd to /dev/sdb
# situation
root@server:/#
# add /dev/sdb1 via mdadm to /dev/md0
root@server:/#
# situation - rebuild
root@server:/#
Remove the original / dev / sdb1 disk from mdadm RAID 1
# set fail / dev / sdb1
root@server:/#
mdadm --manage /dev/md0 --fail /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md0
# situation
root@server:/#
mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon Oct 16 14:09:35 2017
Raid Level : raid1
Array Size : 1953382464 (1862.89 GiB 2000.26 GB)
Used Dev Size : 1953382464 (1862.89 GiB 2000.26 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Wed Nov 7 06:52:35 2018
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 1
Spare Devices : 0
Consistency Policy : bitmap
Name : server:0 (local to host server)
UUID : e05778a4:a880b7bb:d25596aa:d6a9c4d3
Events : 10041
Number Major Minor RaidDevice State
- 0 0 0 removed
1 8 49 1 active sync /dev/sdd1
0 8 17 - faulty /dev/sdb1
# remove /dev/sdb1 from /dev/md0
root@server:/#
mdadm --manage /dev/md0 --remove /dev/sdb1
mdadm: hot removed /dev/sdb1 from /dev/md0
# situation
root@server:/#
mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon Oct 16 14:09:35 2017
Raid Level : raid1
Array Size : 1953382464 (1862.89 GiB 2000.26 GB)
Used Dev Size : 1953382464 (1862.89 GiB 2000.26 GB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Wed Nov 7 06:53:02 2018
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
Consistency Policy : bitmap
Name : server:0 (local to host server)
UUID : e05778a4:a880b7bb:d25596aa:d6a9c4d3
Events : 10042
Number Major Minor RaidDevice State
- 0 0 0 removed
1 8 49 1 active sync /dev/sdd1
Adding a new disk to mdadm
We shut down, remove the old sdb disk, mount the new sdb disk
# overwrite the disk (partition) layout from /dev/sdd to /dev/sdb
sfdisk -d /dev/sdd | sudo sfdisk /dev/sdb --no-reread
# situation
root@server:/#
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 87,9M 1 loop /snap/core/5548
loop1 7:1 0 87,9M 1 loop /snap/core/5662
loop2 7:2 0 87,9M 1 loop /snap/core/5742
sda 8:0 0 111,8G 0 disk
├─sda1 8:1 0 731M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 111,1G 0 part
└─sda5_crypt 253:0 0 111,1G 0 crypt
├─kubuntu--vg-root 253:1 0 110,1G 0 lvm /
└─kubuntu--vg-swap_1 253:2 0 980M 0 lvm [SWAP]
sdb 8:16 0 1,8T 0 disk
└─sdb1 8:17 0 1,8T 0 part
sdc 8:32 0 465,8G 0 disk
├─sdc1 8:33 0 100M 0 part
├─sdc2 8:34 0 97,6G 0 part
└─sdc3 8:35 0 368,1G 0 part
sdd 8:48 0 1,8T 0 disk
└─sdd1 8:49 0 1,8T 0 part
└─md0 9:0 0 1,8T 0 raid1
# add /dev/sdb1 via mdadm to /dev/md0
root@server:/#
mdadm --manage /dev/md0 --add /dev/sdb1
mdadm: added /dev/sdb1
# situation - rebuild
root@server:/#
cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdb1[2] sdd1[1]
1953382464 blocks super 1.2 [2/1] [_U]
[>....................] recovery = 0.0% (1803200/1953382464) finish=234.4min speed=138707K/sec
bitmap: 0/15 pages [0KB], 65536KB chunk
unused devices: < none>