CentOS 7 software RAID1 - replace disk and make it bootable

General support questions
Post Reply
ommb
Posts: 3
Joined: 2015/01/15 11:09:20

CentOS 7 software RAID1 - replace disk and make it bootable

Post by ommb » 2021/03/27 17:55:07

Hi,
I have a system with CentOS 7 running on software raid1 (with 2 disks - /dev/sda and /dev/sdb). One of the disks has recently showing warning about "unreadable sectors detected". Currently the warnings stopped, but I would like to add an additional disk (/dev/sdc) to the arrays so if in the future this disk will have problems I will simply remove it from the array.

I'm not an expert sysadmin and I will replace/add a disk to a software raid1 for the first time and I have a question that I can't find any answer. So I kindly ask here if anybody knows it :)

On the HowToForge I have found a how-to "How to replace a failed harddisk in Linux software RAID" https://www.howtoforge.com/tutorial/lin ... -harddisk/

The 2 disks (/dev/sda and /dev/sdb) are MBR formatted.

lsblk shows:

Code: Select all

sda               8:0    0 931,5G  0 disk  
├─sda1            8:1    0 104,9G  0 part  
│ └─md127         9:127  0 104,9G  0 raid1 /
├─sda2            8:2    0   4,2G  0 part  
│ └─md126         9:126  0   4,2G  0 raid1 [SWAP]
└─sda3            8:3    0 822,4G  0 part  
  └─md122         9:122  0 822,3G  0 raid1 
    └─home      253:0    0 822,3G  0 dm    /home
sdb               8:16   0 931,5G  0 disk  
├─sdb1            8:17   0 104,9G  0 part  
│ └─md127         9:127  0 104,9G  0 raid1 /
├─sdb2            8:18   0   4,2G  0 part  
│ └─md126         9:126  0   4,2G  0 raid1 [SWAP]
└─sdb3            8:19   0 822,4G  0 part  
  └─md122         9:122  0 822,3G  0 raid1 
    └─home      253:0    0 822,3G  0 dm    /home
The root partition is on array /dev/md127:

Code: Select all

/dev/md127:
           Version : 1.0
     Creation Time : Thu Feb 19 10:36:09 2015
        Raid Level : raid1
        Array Size : 110016384 (104.92 GiB 112.66 GB)
     Used Dev Size : 110016384 (104.92 GiB 112.66 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Sat Mar 27 15:33:06 2021
             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : bitmap

              Name : localhost:root
              UUID : 1367078e:180a0666:a35a921d:fe6ddbc2
            Events : 48815

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1
fdisk -l /dev/sda and /dev/sdb shows:

Code: Select all

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x0002bce4

  Naprava Zagon    Začetek       Konec     Bloki    Id  Sistem
/dev/sdb1   *        2048   220035071   110016512   fd  Linux raid autodetect
/dev/sdb2       220035072   228837375     4401152   fd  Linux raid autodetect
/dev/sdb3       228837376  1953523711   862343168   fd  Linux raid autodetect

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x0001c30f

  Naprava Zagon    Začetek       Konec     Bloki    Id  Sistem
/dev/sda1   *        2048   220035071   110016512   fd  Linux raid autodetect
/dev/sda2       220035072   228837375     4401152   fd  Linux raid autodetect
/dev/sda3       228837376  1953523711   862343168   fd  Linux raid autodetect

According to the How-To when I will put a new disk and start the system I should run:

Code: Select all

sgdisk -R /dev/sdc /dev/sda
sgdisk -G /dev/sdc
and then of course add the partitions of the new disk to the appropriate arrays.

I would like to know it this will also make my new disk (/dev/sdc) bootable or should I run some addition commands to make it bootable (grub-install /dev/sdc)?

Best regards,
ommb

tunk
Posts: 1205
Joined: 2017/02/22 15:08:17

Re: CentOS 7 software RAID1 - replace disk and make it bootable

Post by tunk » 2021/03/27 20:15:55

To see if you have some hardware problems, you could install
smartmontools and run this to see if there's any SMART errors:
smatrctl -a /dev/sda | more
smatrctl -a /dev/sdb | more

ommb
Posts: 3
Joined: 2015/01/15 11:09:20

Re: CentOS 7 software RAID1 - replace disk and make it bootable

Post by ommb » 2021/03/27 21:14:25

Dear tunk,
thank you for your reply. I prefer a GUI program GSmartControl (because I can afford a GUI on this system).
Anyway that was not my question.
I would like to know if I will be able to boot from the new disk (/dev/sdc) after the commands

Code: Select all

sgdisk -R /dev/sdc /dev/sda
sgdisk -G /dev/sdc
and after the array will be fully synced? Or do I have to execute any other commands (like grub-install /dev/sdc or something else) to be able to boot from the /dev/sdc?

As you can immagine, I would like to be able to boot the system again from any of the disks when the array will be synced ;)

Best regards
ommb

ommb
Posts: 3
Joined: 2015/01/15 11:09:20

Re: CentOS 7 software RAID1 - replace disk and make it bootable

Post by ommb » 2021/05/02 19:36:21

Dear all,
I finally added a new disc to an existing array and make the system bootable form all the 3 drives.

A little background - when I added the third disc to my system it was not recognized as /dev/sdc, but as /dev/sda and the previously
/dev/sda became /dev/sdb
/dev/sdb became /dev/sdc

I do not know why this has happened, but probably because I have an old MOBO which is a sort of hybrid between BIOS and UEFI. The MOBO can recognize discs bigger than 2TB, but can only boot from disc <2TB with MBR partitioning.

So the new situation was like this:
/dev/sda (new, unformatted disc)
/dev/sdb (old /dev/sda, already part of RAID 1 array)
/dev/sdc (old /dev/sdb, already part of RAID 1 array)

The MOBO was configured to boot from /dev/sdb (old /dev/sda).

After installing this new disc I did the following:

Set again the SCT Error Recovery Control parameters to 15 seconds to all the discs (I do not know why all the disc had this again disabled)

Code: Select all

smartctl -l scterc,150,150 /dev/sda
smartctl -l scterc,150,150 /dev/sdb
smartctl -l scterc,150,150 /dev/sdc
Copy MBR partitions from /dev/sdb to /dev/sda

Code: Select all

sfdisk -d /dev/sdb | sfdisk /dev/sda
Check if everything is OK (/dev/sda paritions = /dev/sdb)

Code: Select all

fdisk -l
Installed GRUB on the new disc *

Code: Select all

grub2-install /dev/sda
* this was not not enough, see below

Erase the superblock *

Code: Select all

mdadm --zero-superblock /dev/sda1
mdadm --zero-superblock /dev/sda2
mdadm --zero-superblock /dev/sda3
* later I realized that this was not necessary, because the superblocks did not exists (it gave me some errors) :roll:

Added the partitons from the new disc to the array:

Code: Select all

mdadm --manage /dev/md126 --add /dev/sda1
mdadm --manage /dev/md127 --add /dev/sda2
mdadm --manage /dev/md122 --add /dev/sda3
Started the command to grow the arrays:

Code: Select all

mdadm --grow /dev/md126 --raid-devices=3
mdadm --grow /dev/md127 --raid-devices=3
mdadm --grow /dev/md122 --raid-devices=3
The synchronization of the arrays started - I had to wait the system to finish the sychronization :(
After the arrays were synced and showing that everything with the arrays is OK I restarted the system.

And then come the real surprise - the system was not able to boot from /dev/sdb and /dev/sdc - fortunately it was able to boot from /dev/sda.
So I installed Grub to the sdb and sdc:

Code: Select all

grub2-install /dev/sdb
grub2-install /dev/sdc
and tested to boot from all the 3 discs - with success :mrgreen:

So the correct command to boot from all the 3 discs should be:

Code: Select all

grub2-install /dev/sda
grub2-install /dev/sdb
grub2-install /dev/sdc
Now I have a RAID 1 system that is synced over three discs and is able to boot from all 3 discs.

Hopefully this will help to somebody.

Best regards,
ommb

Post Reply