An administrator has created a RAID 1 array using mdadm with two 1TB disks. After a disk failure, the array is in a degraded state. Which command should be used to replace the failed disk with a new one?
Trap 1: mdadm --add /dev/md0 /dev/sdc
The `--add` option alone does not reduce the existing mirror: it merely attaches /dev/sdc to /dev/md0 as a spare. Since /dev/sdb is still active and healthy, the RAID1 remains in a two-disk configuration, and the new disk will not participate in a rebuild. The old disk must first be explicitly marked as failed and removed so that the array enters a degraded state, allowing `--add` to trigger a recovery onto /dev/sdc.
Trap 2: mdadm --remove /dev/md0 /dev/sdb --add /dev/sdc
Without a preceding `--fail`, the `--remove` command is invalid: mdadm will reject the removal of a fully functional component because that would compromise the mirror's redundancy. Even if `--add` is appended, the kernel's md driver treats the operation as adding a spare rather than rebuilding a replacement. The sequence must start with `--fail` to update the array's state, and the whole compound command should use `--manage` to invoke the proper management interface.
Trap 3: mdadm --replace /dev/md0 --with /dev/sdc
There is no `--replace` operation in the standard mdadm CLI: the tool does not provide a direct 'replace' subcommand or flag. To swap a disk, you must issue a sequence of state changes via `--manage`, specifically `--fail`, then `--remove`, then `--add`. Relying on a nonexistent `--replace` option will simply cause mdadm to exit with an error and leave the array unchanged, so this command is not a valid replacement method.
- A
mdadm --add /dev/md0 /dev/sdc
Why it fails: The `--add` option alone does not reduce the existing mirror: it merely attaches /dev/sdc to /dev/md0 as a spare. Since /dev/sdb is still active and healthy, the RAID1 remains in a two-disk configuration, and the new disk will not participate in a rebuild. The old disk must first be explicitly marked as failed and removed so that the array enters a degraded state, allowing `--add` to trigger a recovery onto /dev/sdc.
- B
mdadm --manage /dev/md0 --fail /dev/sdb --remove /dev/sdb --add /dev/sdc
This is the correct replacement sequence for a RAID1 device: `--manage` with `--fail` marks /dev/sdb as faulty, which forces the array into a degraded mode; `--remove` then detaches it from the mirror, and `--add` attaches /dev/sdc as a new member, automatically starting a rebuild to restore full redundancy. Each operation is validated in order, ensuring the MD device never loses the required number of active components and that the new disk is used as a direct replacement.
- C
mdadm --remove /dev/md0 /dev/sdb --add /dev/sdc
Why it fails: Without a preceding `--fail`, the `--remove` command is invalid: mdadm will reject the removal of a fully functional component because that would compromise the mirror's redundancy. Even if `--add` is appended, the kernel's md driver treats the operation as adding a spare rather than rebuilding a replacement. The sequence must start with `--fail` to update the array's state, and the whole compound command should use `--manage` to invoke the proper management interface.
- D
mdadm --replace /dev/md0 --with /dev/sdc
Why it fails: There is no `--replace` operation in the standard mdadm CLI: the tool does not provide a direct 'replace' subcommand or flag. To swap a disk, you must issue a sequence of state changes via `--manage`, specifically `--fail`, then `--remove`, then `--add`. Relying on a nonexistent `--replace` option will simply cause mdadm to exit with an error and leave the array unchanged, so this command is not a valid replacement method.