In this blog post we discuss on Converting to Raid1 Setup on Existing Centos7 Install, specifically means convert existing single disk CentOS 7 system into a two disk RAID1 system without loosing data or reinstall the system. RAID 1 produces a mirrored set, which can tolerate a single disk failure. The GRUB2 bootloader is also configured in such a way that the system will still be able to boot if any of the hard drives fails.
Before starting lets familiar with our current system Configurations. Feel free to refer this article if you own a centos 7, centos 6 or even the newer version centos 8.
We are adding a second identical disk /dev/sdb for raid 1 setup. The raid will be a Linux software raid managed by “mdadm” . If the “mdadm” command is not available, install it using yum command. So attach the new disk in to the server mother board before proceeding with below steps.
Now lets get started. Create identical partition scheme as current disk /dev/sda
Check changes or see the difference using below command.
Changes partition type to Linux RAID autodetect. To do so, “fdisk” the specific hard disk.
Verify the result using below command.
Now we are going to create a degraded RAID1. Which means we Create RAID1 devices in degraded state because the one disk is missing. The /dev/sda which is currently installed with OS and used to boot up.
In our case we have three partitions. So we are doing it for all partitions in new disk /dev/sdb
Check the result with:
Create the file-systems on the new RAID devices partitions.
Now we need to Manually replicate the existing data on existing /dev/sda partitions to new software RAID partitions. For that Mount both / and /boot
Copy Existing data using rsync command
During rsync we got error like below
Noticed similar errors reported as bug in below link.
What I understood is the error status rsync command is trying to synchronise the attributes on destination partition to match to attributes on the source partition by removing “extra” attributes. But rsync command has no privilege to perform it even if we run it as root user.
In my case the permission denied are for files inside /run folder. In my understanding /run/ is often implemented as a tmpfs ( mount | fgrep run ) and data in those directories won’t survive a reboot (which is a good thing). Which means /run include as a temporary filesystem (tmpfs) which stores volatile runtime data.
So I ignored the rsync errors and proceed with the next steps.
Now mount System information
Chroot into /mnt partition for /dev/sdb disk
Edit fstab with new drive UUID information
Now Open /etc/fstab file and add entries like below.
Now create a mdadm.conf from current RAID configuration:
Backup,Update the current initrd and rebuild the initramfs with the new mdadm.conf:
Now edit grub and add some default parameters to grub.
Make new grub config
Install grub on new disk /dev/sdb
At this point we are going to reboot the system choosing new disk /dev/sdb from bios. If all worked out system will boot with new disk /dev/sdb. After that check mount points and raid status using below commands.
In our case, we switched the disk ports so after reboot new disk become /dev/sda and old disk become /dev/sdb. So don’t get confuse with the screenshot results, if you opted to boot from new disk from bios instead of disk port swap, in that case the mdstat command results will show the new disk as /dev/sdb itself.
Now we need add old disk to the raid array. So Change partition type to “Linux raid autodetect” for old disk.
Now Add old disk to raid 1 array. (In our case its sdb)
Check rebuild status using below command and see if it running.
Reinstall grub on old disk ( In our case its /dev/sdb)
This concluded the raid1 setup on existing centos 7.4 install. Once the rebuild completed, the mdstat result will show like below and from that we can confirm its completed and running fine. Try to reboot it again and see if there any issues encountering. Put your suggestions and thoughts in the comment box.