If you are using Software RAID in Linux and assume that you have /dev/md0 as your RAID Device then you can use following set of commands to manage the RAID Device.
1. To get status and health of the device, you can use,
# mdadm --detail /dev/md0 /dev/md0: Version : 1.2 Creation Time : Tue Aug 22 19:50:32 2023 Raid Level : raid1 Array Size : 101376 (99.00 MiB 103.81 MB) Used Dev Size : 101376 (99.00 MiB 103.81 MB) Raid Devices : 3 Total Devices : 3 Persistence : Superblock is persistent Update Time : Wed Aug 23 13:11:49 2023 State : clean Active Devices : 3 Working Devices : 3 Failed Devices : 0 Spare Devices : 0 Consistency Policy : resync Name : m1.example.com:0 (local to host m1.example.com) UUID : 9c86fd7f:dce223fd:d40823e8:01b4a5cf Events : 39 Number Major Minor RaidDevice State 3 8 33 0 active sync /dev/sdc1 1 8 37 1 active sync /dev/sdc5 2 8 38 2 active sync /dev/sdc6
2. In above example, you can see three disks. Let us assume that /dev/sdc1 is having some issues then you can use following command to replace the faulty disk without loss of data. Run following commands.
# mdadm --manage /dev/md0 --fail /dev/sdc1 mdadm: set /dev/sdc1 faulty in /dev/md0
This command will mark the disk /dev/sdc1 as faulty.
3. Now remove the faulty device using following command.
# mdadm --manage /dev/md0 --remove /dev/sdc1 mdadm: hot removed /dev/sdc1 from /dev/md0
4. Now assume that you have new /dev/sdc1 then add this new disk in the array and check the rebuilding process.
# mdadm --manage /dev/md0 --add /dev/sdc1 mdadm: added /dev/sdc1
These are essential management commands for software RAID.