27

I have a dedicated server with 3 SSD drives in RAID 1. Output of cat /proc/mdstat:

    Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md4 : active raid1 sdc4[2] sdb4[1] sda4[0]
      106738624 blocks [3/3] [UUU]
      bitmap: 0/1 pages [0KB], 65536KB chunk

md2 : active raid1 sdc2[2] sda2[0] sdb2[1]
      5497792 blocks [3/3] [UUU]
      
md1 : active raid1 sda1[0] sdc1[2] sdb1[1]
      259008 blocks [3/3] [UUU]
      
unused devices: <none>

¿How can a drive be safely removed from the soft raid without loosing any data? I would like to remove a drive from the array in order to reformat it and use it independently, while keeping the most important data mirrored.

2 Answers 2

55

You've got a three-way mirror there: each drive has a complete copy of all data. Assuming the drive you want to remove is /dev/sdc, and you want to remove it from all three arrays, you'd perform the following steps for /dev/sdc1, /dev/sdc2, and /dev/sdc4.

Step 1: Remove the drive from the array. You can't remove an active device from an array, so you need to mark it as failed first.

mdadm /dev/md1 --fail /dev/sdc1
mdadm /dev/md1 --remove /dev/sdc1

Step 2: Erase the RAID metadata so the kernel won't try to re-add it:

wipefs -a /dev/sdc1

Step 3: Shrink the array so it's only a two-way mirror, not a three-way mirror with a missing drive:

mdadm --grow /dev/md1 --raid-devices=2

You may need to remove the write-intent bitmap from /dev/md4 before shrinking it (the manual isn't clear on this), in which case you'd do so just before step 3 with mdadm --grow /dev/md4 --bitmap=none, then put it back afterwards with mdadm --grow /dev/md4 --bitmap=internal.

3
  • Does this preserve the data on the disk which you remove? I.e. can you afterwards access the data which was on the RAID from the separate disk too?
    – Nobody
    Commented Sep 15, 2017 at 13:14
  • 3
    @Nobody, if you want to read the data off the removed drive, you should skip step 2. Virtually all the data is still there after running wipefs (it only erases a few key bytes required for filesystem recognition), but reading it becomes an exercise in data recovery rather than just a matter of plugging the drive in.
    – Mark
    Commented Sep 15, 2017 at 20:18
  • Note that [n/n] only implies n copies for RAID1. For RAID10, it just means that all n disks are present. The number of copies is printed nearby in the /proc/mdstat output. Commented Aug 19, 2022 at 9:25
0

man mdadm:

   -r, --remove
          remove listed devices.  They must  not  be  active.   i.e.  they
          should be failed or spare devices.

          As well as the name of a device file (e.g.  /dev/sda1) the words
          failed, detached and names like set-A can be given to  --remove.
          The  first  causes  all failed device to be removed.  The second
          causes any device which is no longer  connected  to  the  system
          (i.e  an  'open'  returns  ENXIO) to be removed.  The third will
          remove a set as describe below under --fail.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .