RAID Recovery™
Recovers all types of corrupted RAID arrays
Last updated:

Remove mdadm RAID Devices – How to do it?

The mdadm utility is the most straightforward command-line tool for creating RAID on Linux-based systems. With mdadm, you can set up various RAID levels and delete them whenever you decide to discontinue using the storage. But how do you remove mdadm RAID devices? It requires stopping the RAID first and executing a few commands. There are numerous reasons to remove an mdadm device, such as rebuilding the array or setting up a different RAID level. This article provides comprehensive steps for removing an mdadm RAID level on Linux systems without losing your vital files. Be sure to create a full backup before proceeding with this guide.

Ready to get your data back?

Need to repair software or hardware RAID? To start recovering data from RAID drive, press the FREE DOWNLOAD button to get the latest version of DiskInternals RAID Recovery® and begin the step-by-step recovery process. You can preview all recovered files absolutely for free. To check the current prices, please press the Get Prices button. If you need any assistance, please feel free to contact Technical Support. The team is here to help you get your data back!

How to Remove mdadm Software RAID Devices in Nine (9) Detailed Steps

Step 1: Check the RAID details

First things first, you need to check the RAID details and view every information about the device. Here is the command to check your mdadm RAID device details. For this article, we are trying to remove the RAID array /dev/md1.

$ mdadm --detail /dev/md1

The output will show details about the /dev/md1 RAID array; here is where you can confirm if the RAID is still in good condition for any action to take place.

Step 2: Unmount and Remove all Filesystems

Next, you have to unmount any filesystem configured in the RAID array. If there are multiple filesystems, you have to remove them one after another. This is possible and straightforward using the “umount” command or “lvremove” for removing logical volumes.

$ umount /dev/md1

Removing a Logical Volume

$ lvremove /dev/test1/install-images

The essence of unmounting active filesystems in a mdadm RAID you want to remove is to prevent file corruption or irrecoverable data loss.

Step 3: Identify the mdadm RAID Device

In this step, we need to identify the exact drives used in the RAID array; only when you know the exact drives in your array can you successfully remove them. When this command is triggered, ensure to note down the drive details of the mdadm RAID you want to uninstall. Here’s the command to trigger this action:

cat /proc/mdstat

You will get the full details of the drives in your RAID array; if you use more than two drives, you will all of that in the output.

Step 4: Stop the RAID Device and Remove it From /etc/mdadm/mdadm.conf

Here comes one of the important procedures to take in removing a mdadm RAID device. You have to stop the RAID first, before removing a device.

$ mdadm --stop /dev/md1

This will stop the RAID array from working. However, after this command comes out successfully, don’t be in haste to physically remove any drive from the computer. You have to complete the entire procedure before removing a physical drive from the host PC.

Additionally, you should edit the mdadm configuration file to remove references to the stopped RAID array. This will further ensure a seamless outcome with a low probability of facing a data loss case.

$ nano /etc/mdadm/mdadm.conf

The command above will remove configuration references from the RAID device you want to remove.

Step 5: Remove mdadm RAID Device

With the previous steps achieved successfully, you can now remove the mdadm RAID device. Sometimes, you may get an error when you type the “remove” command; but, when this error occurs, it simply means you need to delete the superblocks labels, and this is an easy task. The mdadm command to remove a RAID device is:

$ mdadm --fail /dev/sdf1 --remove /dev/sdf1

(This command removes one specified drive from the RAID array, if you’re removing all the drives, use $ mdadm --remove /dev/md1)

Note: to remove a single drive from your array, you need to mark the drive as a “failed” one and then proceed to remove it. This does not necessarily mean that the drive was faulty, you just did that so that the system can unmount the drive without the RAID array being affected. However, this depends on the RAID level you had set up and the number of disks in the rack; some RAID levels require at least three disks to function, so if you’re left with just three disks on such RAID levels, removing one of them will definitely fail the entire RAID.

Step 6: Remove the Superblocks

The mdadm utility uses md superblocks as a header to assemble and manage RAID component devices in an array. So, even when you remove a device from the array, the superblocks might still be active, and this will prevent you from using those “removed” RAID disks for another RAID configuration.

You have to manually remove superblocks for the drives you just removed from the mdadm RAID array. This implies that if you have up to four disks in your RAID array, and you removed the RAID array entirely, you have to remove superblocks for the entire four drives – you just have to keep commenting the drives in the command. But if you removed just one device, then comment out the superblock for that device.

$ mdadm --zero-superblock /dev/sdf1

Here, we removed only sdf1 from the RAID array, so we have to comment out its superblock. If you removed multiple drives, comment them in the command. For any disk you fail to remove its superblock, you won’t be able to reuse the disk in any future configuration.

This step is often overlooked by some, but it is actually very important since mdadm does not automatically clear its member drive’s superblock even when the drive has been removed from an array. This is something you must do manually.

If the superblock is not cleared and you use this “removed” device in a computer where the mdadm RAID is configured, the mdadm installation will try to automatically add the drive to its previous array and cause a fatal storage error which would lead to data loss.

Step 7: Verify RAID Device Was Removed

Apparently, you will want to confirm if what you did worked as expected. To find out if your mdadm RAID device(s) have been successfully removed from the system – along with the configurations, here is the command:

cat /proc/mdstat

The output should be different from what it showed the first time you ran this command before the “removal.”

Step 8: Overwrite Disks With Random Data (Optional)

For any reason at all, if you wish to overwrite the data on the drive you just removed from a mdadm RAID array, it is possible using the dd command, but of course, this means you will lose the previous data saved on the drive.

dd if=/dev/urandom bs=4096 of=/dev/sdf1

Note: for Ubuntu 22.04+ and Debian 11+, you can use /dev/random. This especially works on NVMe drives.

Step 9: Change the Number of Devices for the RAID Array (Optional)

Here is another optional step and it’s potentially risky as any typo in the command may lead to irreversible data loss. However, this method is to instruct the system to adjust the number of drives in an existing RAID after you have removed or added a new drive.

If you don’t instruct the system to change the number of drives in the array, it will always mark a “removed” drive as “missing” upon each system restart. Let’s say you had four drives in your RAID and you removed one – now left with 3 drives, here’s how to reconfigure the array to use only the three drives.

$ mdadm --grow --raid-devices=3

Note: it may just be advisable to recreate the array with 3 drives as this step is array-specific.

To add a new member drive to the array, connect the new drive to the system and still use the “–grow” command.

$ mdadm --add /dev/md1 /dev/sdc <--- /dev/sdc is the new drive to add

$ mdadm --grow --raid-devices=4

Note: Make sure you run a full backup of your data before trying out this particular step. You can’t use this option to switch RAID levels; for example, switch from RAID 1 to RAID 0 or RAID 5. To switch RAID levels, stop the existing RAID, unmount, and delete it entirely, and then create the new RAID. Either way, make BACK UP FIRST!

How to Recover RAID on Linux (MDADM)?

Thinking of how to recover data from your Linux RAID array? Well, there are several possible scenarios that could lead to RAID data loss. However, most of these scenarios can be recovered using a professional RAID data recovery solution like DiskInternals RAID Recovery.

DiskInternals RAID Recovery is a multi-feature RAID data recovery solution for Windows OS and Linux OS. It supports all known Linux OS filesystems, as well as Windows filesystems. Using the software, you can recover data from failed RAID drives, disk images, VMDK files, and inaccessible RAID volumes.

Video Preview

The DiskInternals RAID Recovery software supports RAID 0 – 6 and also supports nested RAIDs like RAID 10, RAID 01, RAID 60, RAID 50, and others. It is a powerful tool for IT professionals and system admins – regularly updated for improved performance and inclusion of new RAID recovery features.

Main Features of DiskInternals RAID Recovery:

  • Mounts virtual drives as local drives and make them accessible from File Explorer
  • Restores data from Linux, Apple, UNIX, and NAS RAID drives
  • Recovers lost files from RAID-enabled motherboards from Intel, NVidia, or VIA.
  • Creates free disk images

How to Use:

  • Remove the RAID drives and connect them to a Windows OS computer
  • Download and install DiskInternals RAID Recovery on the Windows PC; this software can run on Windows 7-11 or Windows Server 2003-2019.
  • Launch the RAID Recovery software.
  • If you want to run the recovery manually, close the “Recovery Wizard,” otherwise, follow the Wizard’s automatic prompts, which is quite faster.
  • Select the Linux drive to recover from, identify the RAID array, and choose a Recovery Mode. Well, it is advisable to select Full Recovery mode – although it’ll take longer, it ensures complete and effective results.
  • Once you launch the recovery scan, DiskInternals RAID Recovery will automatically check the status of the RAID array, file system, controller, and disks, before proceeding to attempt the data recovery.
  • When the scan completes, you will see both lost and existing files on the hard drive; the lost files will be marked with a red asterisk. (Note: the scan may take long hours depending on the total data size on the hard drive).
  • The recovered files will be available as “Read Only,” and you can preview most of them. The preview is to confirm they are the ones you want to recover. With this confirmation done, to save the files back, you must need to upgrade to the paid version of DiskInternals RAID Recovery.

Conclusion

You can remove a single drive or multiple drives from a mdadm RAID on Linux. However, for each drive you remove from the array, ensure to clear the superblocks, otherwise, the drive won’t be usable for another RAID setup and you may lose all your data on the device. It is important to pay attention to every step explained in this article when removing a mdadm RAID device.

Finally, you may want to keep DiskInternals RAID Recovery handy in case of any data loss scenario that may occur after you’re done with the drive removal. Also, you should make regular backups of the data you save to a RAID array, and before you make any advanced changes to the array, do an immediate full backup.

FAQ

Related articles

FREE DOWNLOADVer 7.0, WinBUY NOWFrom $149 249.00