Suppose we have a software-based RAID1 compiled with mdadm for Linux:
# cat / proc / mdstat
Personalities: [raid1]
md0: active raid1 sdb [1] sda [0]
8387572 blocks super 1.2 [2/2] [UU]
And we got another hard drive that I would like to plug into this machine by expanding the available disk space without losing fault tolerance. switch from RAID1 to RAID5.
To do this, we stop the existing array with the command:
# mdadm --stop /dev/md0
If you boot from this raid, then of course it will not be possible to stop it and you will need to use some LiveCD ...
Then we overwrite the metadata of the old RAID1 by creating over it RAID5 from the same two disks:
# mdadm --create /dev/md0 --level 5 --raid-devices 2 /dev/sda /dev/sdb
The program will curse that these disks are already participating in RAID1, but we will safely continue the creation:
mdadm: / dev / sda raid array:
level = raid1 devices = 2 ctime = Wed Aug 4 08:28:45 2010
mdadm: / dev / sdb raid array appears:
level = raid1 devices = 2 ctime = Wed Aug 4 08:28:45 2010
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array / dev / md0 started.
Let's wait a bit while the rebild of the newly created raid passes:
md0: active raid5 sdb [2] sda [0]
8387072 blocks super 1.2 level 5, 512k chunk, algorithm 2 [2/1] [U_]
[> ....................] recovery = 4.2% (355076/8387072) finish = 2.2min speed = 59179K / sec
It turns out essentially the same RAID1.
After the process is over, let's add our new disk to the raid (as spare):
# mdadm --add /dev/md0 /dev/sdc
And expand the raid to three active drives:
# mdadm --grow /dev/md0 --raid-disks=3
We are waiting until the reshape raid is over:
md0: active raid5 sdc [3] sdb [2] sda [0]
8387072 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
[> ....................] reshape = 2.5% (212480/8387072) finish = 9.6min speed = 14165K / sec
After that, expand the re-created disk partition by checking it for errors before it (example for ext2 / 3):
# e2fsck -f /dev/md0
# resize2fs -p /dev/md0
Also, do not forget to update the config:
# mdadm --examine --scan >> /etc/mdadm.conf
and rebuild the initrd if necessary.
If during these operations there are no failures, then all data that was on RAID1 will be transferred to RAID5 without any loss. Checked by me personally! True to virtualka ...;)