Setup soft raid 0 on live ubuntu 16.0.4/ debian -8/9 system without downtime

In this tutorial I am using debian 9 system with two disks, /dev/vda and /dev/vdb which are identical in size.
/dev/vdb is currently unused, and /dev/vda has the following partition:

See info

After completing this guide I will have the following situation:

The current situation:

Output

Output

Disk /dev/vdb doesn’t contain a valid partition table

Installing mdadm

First of all install md tools:

In order to avoid reboot, let’s load few kernel modules:

Now:

Preparing the second disk

To create a software RAID1 on a running system, we have to prepare the second disk added to the system (in this case /dev/vdb) for RAID1, then copy the contents from the first disk (/dev/vda) to it, and finally add the first disk to the RAID1 array.

Let’s copy the partition table from /dev/vda to /dev/vdb so that the both disks have the exactly same layout:
for mbr

for gpt

And the output of the command:

Change the partitions type on /dev/vdb to Linux raid autodetect:

To make sure that there are no remains from previous RAID installations on /dev/vdb, we run the following commands:

If you receive the following error messages then there are no remains from previous RAID installations, which is nothing to worry about:

Creating RAID arrays

Now use mdadm to create the raid arrays. We mark the first drive (vda) as «missing» so it doesn’t wipe out our existing data:

See status

The output above means that we have two degraded arrays ([U] or [U] means that an array is degraded while [UU] means that the array is ok).

Create the filesystems on RAID arrays (ext4 on /dev/md0 and swap on /dev/md1)

Output

Adjust mdadm configuration file which doesn’t contain any information about RAID arrays yet:

Display the content of /etc/mdadm/mdadm.conf:

Adjusting The System To RAID1

Let’s mount /dev/md0:

See current mount:

After changing the UUID values the /etc/fstab should look as follows:

Next replace /dev/vda1 with /dev/md0 in /etc/mtab:

Setup the GRUB2 boot loader.

Create the file /etc/grub.d/09_swraid1_setup as follows:

Make sure you use the correct kernel version in the menuentry (in the linux and initrd lines).

Output

#Update grub configuration and adjust our ramdisk to the new situation:

add line

Make grub update

Shell output

Copy files to the new disk

Copy the files from the first disk (/dev/vda) to the second one (/dev/vdb)
!!!!!!!!!!!!!!!CAREFULL!!!!!!!!!!!!!!!!!!!!!!!

Preparing GRUB2 (Part 1)

Install GRUB2 boot loader on both disks (/dev/vda and /dev/vdb):

Output

Now we reboot the system and hope that it boots ok from our RAID arrays:

Preparing /dev/vda

If everything went well, you should now find /dev/md0 in the output of:

Output

The output of:

Output

Change the partitions type on /dev/vda to Linux raid autodetect:

See disk usage

Output

Now we can add /dev/vda1 and /dev/vda2 to the respective RAID arrays:

Output

Take a look at:

Then adjust /etc/mdadm/mdadm.conf to the new situation:

Display the content of /etc/mdadm/mdadm.conf:

Preparing GRUB2 (Part 2)

Now it’s safe to delete /etc/grub.d/09_swraid1_setup

Update our GRUB2 bootloader configuration and install it again on both disks (/dev/vda and /dev/vdb)

Reboot the machine

Repair soft raid 0 on debian 8/9 / ubuntu 16.04

See status md

Add disk to raid

See sync status

Output

Waiting for sync

Done

Добавить комментарий

Войти с помощью: 

Ваш e-mail не будет опубликован. Обязательные поля помечены *

 

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.