MD127? How to Rename a RAID Array with mdadm

📅 July 26, 2019
“What? My RAID array device is named /dev/md127? How do I change it to /dev/md2?”

If you have used software RAID on Linux with mdadm, then you will have probably have noticed that a second RAID array created will often receive the device name /dev/md127 instead of something more logical like /dev/md1 or /dev/md2 for consistency.

This article shows how to change the default /dev/md127 into /dev/md2 (or whatever you prefer) for a name that makes better sense.

The Second RAID Array

Let’s assume that we have already created a RAID array using mdadm with the device name /dev/md1, and it is running fine. No problems.

We have a few extra drives nearby, so we create a second RAID array using mdadm. Even though we want its device to be named /dev/md2 (makes sense, doesn’t it?), Linux seems to have a mind of its own and insists upon naming it /dev/md127.

Two RAID-1 arrays created with mdadm in Linux. The first is usually /dev/md1 while the second is sometimes /dev/md127.

Nothing changes this default name. Reassemble. Reboot. Run mdadm –details /dev/md127 to check. Reboot. Remount. Nothing seems to work.

I encountered this issue and tried to resolve it, but much of the information I encountered provided instructions for the older mdadm superblock version 0.9, which does not work for the newer 1.2 superblock format that I was using with Linux Mint 19.1.

This article assumes that we are using mdadm superblock version 1.2 or higher, and this version requires a different set of steps than those for version 0.9.

The process involves,

  • Stopping the array
  • Reassembling the array with a new name
  • Editing /etc/mdadm/mdadm.conf
  • Updating initramfs
  • Rebooting.

Step 1. Viewing the RAID Array Details

First, view the details of all RAID arrays. There are two ways to do this.


sudo mdadm --detail /dev/*


sudo mdadm -Esv

Both return different results, so run both. –detail will show the device as /dev/md1 for an array, but -Esv will show the same array as /dev/md/1. We might need some info from these commands later, so it is worthwhile knowing they exist.

sudo mdadm –detail /dev/* will show output similar to this. Useful for a quick look if you are lost.

You should see /dev/md127 listed somewhere. Or, you might want to change an existing array. Take note of its device name. For the rest of this article, we will assume /dev/md127 and change it to /dev/md2.

Step 2. Stop the Array

We need to stop the array we wish to change.

sudo mdadm --stop /dev/md127

Step 3. Reassemble the array with a new name

While we can use text names to better help identify the array, like piggywiggy, superdrive, or butterwax, let’s use the number 2 so we will have /dev/md2 as the second array on the system.

sudo mdadm --assemble --update=name --name=2 /dev/md2 /dev/sdh /dev/sdi

This has a number of important parts:

  • –update=name – We are going to set the name of the array in the array’s superblock. Other fields exist, but name is the one that changes the name.
  • –name=2 – The name to use. 2, in this example.
  • /dev/md2 – The array’s device name is to be /dev/md2.
  • /dev/sdh and /dev/sdi – The member drives. With more drives in the system, expect higher letters.

We are essentially assembling an array and specifying the new name in the process.

Step 4. Edit mdadm.conf

We are not finished yet! If you reboot now, you will lose the changes and revert to /dev/md127. We need to edit mdadm’s configuration file located in /etc/mdadm/mdadm.conf. Open this file in a text editor with superuser privileges for editing.

sudo xed /etc/mdadm/mdadm.conf

(xed is used here, but use whatever text editor you like.)

There will be a line for each array on your system that looks something like this:

# definitions of existing MD arrays
ARRAY /dev/md/1 metadata=1.2 UUID=b0435f6d:12345678:12b162f4:0d5995d2 name=sunbeam:1
ARRAY /dev/md/2 metadata=1.2 UUID=54b094ea:87654321:21b0ff87:0d7c817c name=pancakepower:2

We need to change the name here if it does not look like this. /dev/md/1 is array /dev/md1, and /dev/md/2 is /dev/md2. Make sure that /dev/md/2 (with the forward slash) contains the 2, the UUID matches that of the second array, and the name field contains a 2 after the colon at the end of the line.

Above, sunbeam and pancakepower are the names of two different Linux computers. Both arrays are present on a Linux system named sunbeam.

“Why are there two different array names?”

This happens when an array is created on one system and then physically installed to a different system. In this case, the second array was created using mdadm on a system named pancakepower. (Oh, yeah! Pancake Power!) The RAID array’s superblock stores the array name. Since the array was originally created on a system named pancakepower, this name was stored in the array’s superblock as the default system name. The array was moved to a system named sunbeam, but the superblock name remained the same.

When we see sunbeam:1, the first part, sunbeam, is the name of the computer, and the second part, 1, is the name of the array. thus, sunbeam:1 is the first RAID array on the computer named sunbeam — at least, that is the goal.

Regardless of where the arrays were created, change both ARRAY lines so that the computer name part is the same as the name of the system. Then, after the colon, use 1 for the array and 2 for the second array. It should read something like this:

# definitions of existing MD arrays
ARRAY /dev/md/1 metadata=1.2 UUID=b0435f6d:12345678:12b162f4:0d5995d2 name=sunbeam:1
ARRAY /dev/md/2 metadata=1.2 UUID=54b094ea:87654321:21b0ff87:0d7c817c name=sunbeam:2

Note: If the the second array line does not appear, then you must add it manually. If it does exist and contains the /dev/md127 somewhere in some form, change it as shown above. This can vary by system.

Save the file, but before closing it, scroll to the top and note the comment that reads,

# !NB! Run update-initramfs -u after updating this file.
# !NB! This will ensure that initramfs has an uptodate copy.

We will do this next. Close the file.

Step 5. Update initramfs

sudo update-initramfs -u

This step was necessary on my system. I discovered that I had to edit mdadm.conf and update initramfs to make the changes persist between reboots. Both steps were required.


Check the Array

Upon logging back in, both arrays should be named what you chose. Use whatever device listing you prefer. Disks also works.

sudo fdisk -l

sudo mdadm --detail /dev/*

sudo mdadm --detail /dev/md2

sudo mdadm -Esv

You should see /dev/md2 (or /dev/md/2 depending upon the command) instead of /dev/md127.

If so, then good. Check /proc/mdstat.

watch cat /proc/mdstat

Pending Resync

If you see that a sync operation is pending, then you need to double check that the names in /etc/mdadm/mdadm.conf are correct. I had this problem when using text names for arrays (sunbeam:cloud for /dev/md2), so I reverted to numeric array names (sunbeam:2 for /dev/md2) and the pending resync disappeared.


Hopefully, this article helps resolve one of the more obscure issues involving mdadm. Many issues can arise, including a failed hard drive, so be sure to consult the man page (man mdadm) for additional help.

Have fun!


, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: