Remove disk (all partitions) from software RAID1 with mdadm and change layout of the disk

The following article is to show how to remove healthy partitions from software RAID1 devices to change the layout of the disk and then add them back to the array.
The mdadm is the tool to manipulate the software RAID devices under Linux and it is part of all Linux distributions (some don’t install it by default so it may need to be installed).

Software RAID layout

[root@srv ~]# cat /proc/mdstat 
Personalities : [raid1] 
md125 : active raid1 sda4[1] sdb3[0]
      1047552 blocks super 1.2 [2/2] [UU]
      bitmap: 0/1 pages [0KB], 65536KB chunk

md126 : active raid1 sdb2[0] sda3[1]
      32867328 blocks super 1.2 [2/2] [UU]
      
md127 : active raid1 sda2[1] sdb1[0]
      52427776 blocks super 1.2 [2/2] [UU]
      bitmap: 0/1 pages [0KB], 65536KB chunk

unused devices: <none>

STEP 1) Make the partitions faulty.

The partitions cannot be removed if they are not faulty.

[root@srv ~]# mdadm --fail /dev/md125 /dev/sdb3
mdadm: set /dev/sdb3 faulty in /dev/md125
[root@srv ~]# mdadm --fail /dev/md126 /dev/sdb2
mdadm: set /dev/sdb2 faulty in /dev/md126
[root@srv ~]# mdadm --fail /dev/md127 /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md127

Keep on reading!

grub2: grub-install: error: disk mduuid not found even after the partition has bios_grub on

This tutorial is for all of us that has done everything by the book with parted and still they receive an error when installing grub2 to the boot sector!

srv@local ~ # grub2-install /dev/sda
Installing for i386-pc platform.
grub2-install: error: disk `mduuid/51b39c2b565a6629d9efc9b3c39b44ff' not found. 

The solution is simple enough:

set the bios_grub on AGAIN even the parted reported it as ON

So you have a problem with your disks and booted to reinstall the grub and used parted from the rescue CD/DVD/USB and then you chroot to the OS you wanted to repair and execute

grub2-install or grub-install

you get the error above? But why parted reported this:

srv@local ~ # parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Model: DELL PERC H700 (scsi)
Disk /dev/sda: 480GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name     Flags
 1      1049kB  2097kB  1049kB                  primary  bios_grub
 2      2097kB  4096MB  4094MB  linux-swap(v1)  primary  raid
 3      4096MB  24.0GB  19.9GB  ext4            primary
 4      24.0GB  480GB   456GB   ext4            primary

(parted)

And still you get the error:

grub2-install: error: disk `mduuid/51b39c2b565a6629d9efc9b3c39b44ff' not found. 

Why it is unknown for us, but the solution was simple, just do SET the flag again – in our case in the chrooted environment we used the parted program from the distro we wanted to repair and the grub-install was then used from the same distro (in the chrooted environment). At first we used the parted from the rescue distro, but apparently they are some issues with the versions even the two parted program – that one from the chrooted environment and from the rescue distro reported the bios_grub as set ON.
It is possible to get this error after using

sgdisk

to duplicate the partition table of a disk (BTW ALWAYS use “-G, –randomize-guids” with sgdisk, after you duplicate the partition table of a disk or you’ll get into BIG troubles!).
So to write down the solution (in fact it’s like a workaround):

srv@local ~ # parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) set 1 bios_grub on
(parted) q
srv@local ~ # parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) set 1 bios_grub on
(parted) q
srv@local ~ # grub2-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
srv@local ~ # grub2-install /dev/sdb
Installing for i386-pc platform.
Installation finished. No error reported.

* If you are using UEFI enabled boot you probably need more options for the grub installation

Something like that for the grub2 installation (but it is specific for your distro – the path for efi directory, just find it under /boot and put the right path – nothing special!):

grub-install --recheck --target=x86_64-efi --efi-directory=/boot/efi/ /dev/sda