S S

CITY LINUX ®

Linux support on-site, on-line and in the cloud.

0793 572 8612

Systems Administration Notes.

Replacing bootable drive in RAID 1.


Replacing bootable drive in RAID 1.

Most things you read about replacing a drive in software RAID 1 stop at the point at which you synchronise mirrors in each metadrive.

So suppose, as recently happened to a client of mine, /dev/sda had been completely scrambled, probably by misguided intervention. Drive sdb is fine and 3 meta disks are running fine but with no mirror. If we look at the metadisk status we get something like this:

root@DEV [/boot/grub2]> cat /proc/mdstat
Personalities : [raid1]
md128 : active raid1 sdb3[2]
      603420352 blocks super 1.2 [2/2] [_U]
      bitmap: 0/5 pages [0KB], 65536KB chunk

md126 : active raid1 sdb2[1]
      372821824 blocks super 1.2 [2/2] [_U]
      bitmap: 2/3 pages [8KB], 65536KB chunk

md127 : active raid1 sdb1[1]
      255936 blocks super 1.0 [2/2] [_U]

unused devices: <none>

There appears to be nothing physically wrong with sda but it’s labled as a Sun disklabel and has a couple of silly partitions which are not being used.

In brief we delete those existing partions on the misconfigured disk sda and ensure that it has the same disk label type as sdb. To do this use fdisk /dev/sda. Select "d" as often as need be to delete each partion, then write the table to disk and exit with "w".

Reopen the drive with fdisk /dev/sda and use "o" to create a new empty DOS partition label. Write this back to disk too. (It might not be necessary to write back to disk twice, but I feel more comfortable seeing that each action has been successfully applied).

Now copy the partition table for sdb to sda.

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

Finally add the partitions to each disk array e.g.

mdadm  /dev/md128 -a /dev/sda3
mdadm  /dev/md126 -a /dev/sda2
mdadm  /dev/md127 -a /dev/sda1

The new partitions will sync and apart from a recommendation to check /proc/mdstat again that appears to be the end of story.

Unfortunately if one of those partions is a boot disk as in this case /dev/md127 it still aint going to boot. This is because Grub or Lilo is not installed on the MBR of the new disk.

You can check this out by searching the first block of the drive.

dd if=/dev/sdb bs=512  count=1|xxd|grep -i grub
1+0 records in
1+0 records out
512 bytes (512 B) copied, 5.0207e-05 s, 10.2 MB/s
0000170: be94 7de8 2e00 cd18 ebfe 4752 5542 2000  ..}.......GRUB .


dd if=/dev/sda bs=512  count=1|xxd|grep -i grub
1+0 records in
1+0 records out
512 bytes (512 B) copied, 5.0207e-05 s, 10.2 MB/s

Happily the remedy is simple

grub-install /dev/sda

Now which ever disk is nominated by the bios to boot should do so. If you can it would be as well to change add both disks to bootable devices shown in the BIOS.

Clifford W Fulford
26th October 2018.



The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.