9

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 independtly, while keeping the most important data mirrored.

Thanks in advance

15

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.

  • 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 Sep 15 '17 at 13:14
  • 1
    @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 Sep 15 '17 at 20:18
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.