将现有硬盘(分区)无损创建为RAID1

Posted felix-zp

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将现有硬盘(分区)无损创建为RAID1相关的知识,希望对你有一定的参考价值。

背景

如果现在有一块硬盘(分区)正在使用,如果要设置成RAID1,并不需要将数据拷出,然后创建RAID1。
可以先将此硬盘设置成降级RAID1,然后添加新硬盘再激活RAID1即可,整个过程数据无损。

参考:
https://debian-administration.org/article/238/Migrating_To_RAID1_Mirror_on_Sarge

正文

Migrating To RAID1 Mirror on Sarge
Posted by philcore on Thu 8 Sep 2005 at 21:03

Tags: filesystems, raid, raid1, sarge
A guide to migrating to RAID1 on a working Debian Sarge installation which was installed on a single drive.

I suggest reading the following links: Migrating to a mirrored raid using Grub, GRUB and RAID mini-HOWTO.

My setup:

/dev/sda == original drive with data
/dev/sdb == new 2nd drive.
(It is assumed that you have RAID1 enabled in your kernel.)

First of all install md tools:

apt-get install mdadm
change the system types on partitions you want to mirror on the old drive to fd (raid autodetect) using [s]fdisk. Don‘t change the swap partition! Your finished drive should resemble this output:

[[email protected] root]# sfdisk -l /dev/sda

Disk /dev/sda: 8942 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 242 243- 1951866 fd Linux raid autodetect
/dev/sda2 243 485 243 1951897+ fd Linux raid autodetect
/dev/sda3 486 607 122 979965 82 Linux swap / Solaris
/dev/sda4 608 8923 8316 66798270 5 Extended
/dev/sda5 608+ 1823 1216- 9767488+ fd Linux raid autodetect
/dev/sda6 1824+ 4255 2432- 19535008+ fd Linux raid autodetect
/dev/sda7 4256+ 4377 122- 979933+ fd Linux raid autodetect
/dev/sda8 4378+ 8923 4546- 36515713+ fd Linux raid autodetect
Now use sfdisk to duplicate partitions from old drive to new drive:

sfdisk -d /dev/sda | sfdisk /dev/sdb
Now use mdadm to create the raid arrays. We mark the first drive (sda) as "missing" so it doesn‘t wipe out our existing data:

mdadm --create /dev/md0 --level 1 --raid-devices=2 missing /dev/sdb1
Repeat for the remaining raid volumes md1,md2, etc....

mdadm --create /dev/md1 --level 1 --raid-devices=2 missing /dev/sdb2
Now that the volumes are ready create filesystems for the raid devices. My example shows using ext3, but pick the filesystem of your choice. Again, make sure you have kernel support for your selected filesystem.

mkfs.ext3 /dev/md0
mkfs.ext3 /dev/md1
etc...
Now mount the new raid volumes. I mount them under the /mnt directory:

mount /dev/md0 /mnt
cp -dpRx / /mnt

























以上是关于将现有硬盘(分区)无损创建为RAID1的主要内容,如果未能解决你的问题,请参考以下文章

PE下无损调整分区大小的方法

macos盘太小了,有没有无损分区软件

linux  centos8 本地数据盘无损扩容

linux用户家目录无损迁移到独立硬盘

DiskGenius无损调整分区大小

Linux 无损扩容磁盘