Replacing A Failed Hard Drive In A Software RAID1 Array

1 Preliminary Note

In this example I have two hard drives, /dev/sda and /dev/sdb, with the partitions /dev/sda1 and /dev/sda2 as well as /dev/sdb1 and /dev/sdb2.

/dev/sda1 and /dev/sdb1 make up the RAID1 array /dev/md0.

/dev/sda2 and /dev/sdb2 make up the RAID1 array /dev/md1.

/dev/sda1 + /dev/sdb1 = /dev/md0
/dev/sda2 + /dev/sdb2 = /dev/md1

/dev/sdb has failed, and we want to replace it.

 

2 How Do I Tell If A Hard Disk Has Failed?

If a disk has failed, you will probably find a lot of error messages in the log files, e.g. /var/log/messages or /var/log/syslog.

You can also run

cat /proc/mdstat

and instead of the string [UU] you will see [U_] if you have a degraded RAID1 array.

 

3 Removing The Failed Disk

To remove /dev/sdb, we will mark /dev/sdb1 and /dev/sdb2 as failed and remove them from their respective RAID arrays (/dev/md0 and /dev/md1).

First we mark /dev/sdb1 as failed:

mdadm --manage /dev/md0 --fail /dev/sdb1

The output of

cat /proc/mdstat

should look like this:

server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid5] [raid4] [raid6] [raid10]
md0 : active raid1 sda1[0] sdb1[2](F)
      24418688 blocks [2/1] [U_]
 
md1 : active raid1 sda2[0] sdb2[1]
      24418688 blocks [2/2] [UU]
 
unused devices: <none>

Then we remove /dev/sdb1 from /dev/md0:catda

mdadm --manage /dev/md0 --remove /dev/sdb1

The output should be like this:

server1:~# mdadm --manage /dev/md0 --remove /dev/sdb1
mdadm: hot removed /dev/sdb1

And

cat /proc/mdstat
server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid5] [raid4] [raid6] [raid10]
md0 : active raid1 sda1[0]
      24418688 blocks [2/1] [U_]
 
md1 : active raid1 sda2[0] sdb2[1]
      24418688 blocks [2/2] [UU]
 
unused devices: <none>

Now we do the same steps again for /dev/sdb2 (which is part of /dev/md1):

mdadm --manage /dev/md1 --fail /dev/sdb2
cat /proc/mdstat
server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid5] [raid4] [raid6] [raid10]
md0 : active raid1 sda1[0]
      24418688 blocks [2/1] [U_]
 
md1 : active raid1 sda2[0] sdb2[2](F)
      24418688 blocks [2/1] [U_]
 
unused devices: <none>
mdadm --manage /dev/md1 --remove /dev/sdb2
server1:~# mdadm --manage /dev/md1 --remove /dev/sdb2
mdadm: hot removed /dev/sdb2
cat /proc/mdstat
server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid5] [raid4] [raid6] [raid10]
md0 : active raid1 sda1[0]
      24418688 blocks [2/1] [U_]
 
md1 : active raid1 sda2[0]
      24418688 blocks [2/1] [U_]
 
unused devices: <none>

Then power down the system:

shutdown -h now

and replace the old /dev/sdb hard drive with a new one (it must have at least the same size as the old one – if it’s only a few MB smaller than the old one then rebuilding the arrays will fail).

 

4 Adding The New Hard Disk

After you have changed the hard disk /dev/sdb, boot the system.Advertisement

The first thing we must do now is to create the exact same partitioning as on /dev/sda. We can do this with one simple command:

sfdisk -d /dev/sda | sfdisk /dev/sdb

You can run

fdisk -l

to check if both hard drives have the same partitioning now.

Next we add /dev/sdb1 to /dev/md0 and /dev/sdb2 to /dev/md1:

mdadm --manage /dev/md0 --add /dev/sdb1
server1:~# mdadm --manage /dev/md0 --add /dev/sdb1
mdadm: re-added /dev/sdb1
mdadm --manage /dev/md1 --add /dev/sdb2
server1:~# mdadm --manage /dev/md1 --add /dev/sdb2
mdadm: re-added /dev/sdb2

Now both arays (/dev/md0 and /dev/md1) will be synchronized. Run

cat /proc/mdstat

to see when it’s finished.

During the synchronization the output will look like this:

server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid5] [raid4] [raid6] [raid10]
md0 : active raid1 sda1[0] sdb1[1]
      24418688 blocks [2/1] [U_]
      [=>...................]  recovery =  9.9% (2423168/24418688) finish=2.8min speed=127535K/sec
 
md1 : active raid1 sda2[0] sdb2[1]
      24418688 blocks [2/1] [U_]
      [=>...................]  recovery =  6.4% (1572096/24418688) finish=1.9min speed=196512K/sec
 
unused devices: <none>

When the synchronization is finished, the output will look like this:

server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid5] [raid4] [raid6] [raid10]
md0 : active raid1 sda1[0] sdb1[1]
      24418688 blocks [2/2] [UU]
 
md1 : active raid1 sda2[0] sdb2[1]
      24418688 blocks [2/2] [UU]
 
unused devices: <none>

That’s it, you have successfully replaced /dev/sdb!

Source: https://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array

Pro správnou funkci je třeba přidat GRUB, aby server startoval i z nového disku (pro případ havarie puvodniho disku).

Nyní stačí:

grub2-install /dev/sdx

kde x=písmedo požadovaného disku (a, b, atd.)

 

 

=========== DOPLNĚNÍ ===========

 

Zařízení Zaveditelný Začátek Konec Sektory Velikost ID Druh
/dev/sda1 * 2048 957227007 957224960 456.4G fd Linux RAID samorozpoznatelný
/dev/sda2 957227008 976771071 19544064 9.3G fd Linux RAID samorozpoznatelný

Začátek Konec Sektory Velikost
976771072 3907029167 2930258096 1.4T

======================
https://serverfault.com/questions/499051/mdadm-mdadm-cannot-open-dev-sda1-device-or-resource-busy

Měl jsem stejný problém. Vadný disk byl vyměněn (po selhání a odebrání z pole RAID 1), ale poté jej nebylo možné přidat zpět. Zdroj byl neustále zaneprázdněn.

VYŘEŠENO NÁSLEDUJÍCÍ…

Problém byl v tom, že systém namapoval můj nový disk jako md126 a md127 (nejsem si jistý proč). Takže jsem měl tyto dva další disky, které se ukázaly nepřipojené, ale přítomné v cat /proc/mdstat.

Když jsem udělal mdadm –stop /dev/md*, odstranilo to položky md126 a md127. Poté chyba při používání zdroje zmizela a když jsem provedl mdadmin –manage /dev/md0 –add /dev/sdb1, fungovalo to. jé 🙂
===============

MÁM 3907027119 SEKTORŮ
PRO SWAP POTŘEBUJI 19544064
ZBÝVÁ MI 3887483055

POUŽIJU 3887483000 SEKTORŮ. – BUDE TO STAČIT?

==================
PANELY Z FEDORA SILVERBLUE PROFIL:

How To Resize RAID Partitions (Shrink & Grow) (Software RAID)

Replacing A Failed Hard Drive In A Software RAID1 Array

How To Resize RAID Partitions (Shrink & Grow) (Software RAID)

 

Shrnutí:
fdisk -načíst oddíly
fdisk vytvořit oddíly
nastavit bootovací oddíl
nezapomenout zapsat
odstranit automaticky připojený raid příkazem mdadm –stop /dev/md*
přidat pomocí mdadm partišny do raidu
zkontrolovat synchronizaci watch /cat/proc/mdstat
nacpat tam grub grub-install nebo grub2-install /dev/sdx
Hotovo!

Pokud se dávaly větší disky, je třeba pak zvětšit raidové pole a souborový systém.
U Ext4 to jde za běhu:

How to resize RAID1 array with mdadm?