5

I have a healthy RAID5 array with 5 disks:

# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid5 sdb1[6] sdd1[0] sdh1[5] sdf1[2] sde1[1]
      31255166976 blocks super 1.2 level 5, 512k chunk, algorithm 2 [5/5] [UUUUU]
      bitmap: 0/59 pages [0KB], 65536KB chunk

unused devices: <none>

I would like to move one disk to a different physical slot on the server, without shutting down the server. (the slots do support hot-swapping)

Can I safely unmount the array, move the disk and re-mount the array, without it going into degraded mode?

mivk
  • 3,446
  • 29
  • 31

1 Answers1

8

Unmounting (filesystems) is not sufficient.

You'd have to stop the array then re-assemble it afterwards:

mdadm --stop /dev/md0
# re-arrange / hotplug drives
mdadm --stop /dev/md0 # (*)
mdadm --assemble /dev/md0

It makes sense to check journalctl / dmesg, and/or cat /proc/partitions / lsblk, to make sure the drives got re-detected fine before attempting to assemble it.

(*) On many modern Linux systems, there is some md auto assembly magic going on in udev (/usr/lib/udev/rules.d/*md-raid*.rules) so you might end up with a stale /dev/md0 if you only hotplug a single drive.

In that case you actually have to stop it again before assembling — or re-trigger udev rules for drives that didn't get hotplugged, or use mdadm's incremental assembly commands to complete it, but stopping it a 2nd time is simpler, so that's why mdadm --stop is used twice both before and after hotplugging a drive.

In some cases mdadm.conf is too verbose and restricts the devices or lists individual drives for each array. This can prevent successful assembly, so if there are still problems, it would be the next place to check. Keep your mdadm.conf as simple as possible (it really only needs to know the UUID for each array).


If you have extra drives available, and don't mind resyncing the array, you can do the whole process online, w/o losing redundancy using mdadm --replace mechanism. This way you could swap slots without unmounting or stopping anything.

frostschutz
  • 47,228
  • 5
  • 112
  • 159
  • 2
    Worked perfectly! I couldn't do the `--replace` because there are no free slots. That was how I ended up with the drive in the wrong place: had to temporarily remove a less important drive to be able to replace a failing one. Besides, it took 12 hours to "--replace" a 8TB drive, – mivk Dec 15 '21 at 14:09