2

I have Raid 1

/dev/sda /dev/sdb

as md0

then now I want to expand for Raid5

So, my idea is

sudo mdadm --add /dev/md0 /dev/sdd

sudo mdadm --grow /dev/md0 --level=raid5 --raid-devices=3

In these processes.

The contents in the HDD will be deleted or not??

2 Answers 2

3

Yes it's perfectly possible, and can be done even on a live system.

IMPORTANT NOTE: your data won't survive a disk failure during the conversion process, so make sure you have a backup.

Here's a demonstration using some files.

# Two "disks", probably called /dev/loop0 ($a) and /dev/loop1 ($b)
dd bs=1M count=100 </dev/zero >/tmp/img.a
a=$(losetup --show --find /tmp/img.a)

dd bs=1M count=100 </dev/zero >/tmp/img.b
b=$(losetup --show --find /tmp/img.b)

# Create RAID 1
mdadm --create /dev/md0 --metadata=1.2 --level=raid1 --raid-devices=2 $a $b

# See what is going on
cat /proc/mdstat

# Add a filesystem and mount it
mkfs -t ext4 -L md /dev/md0

mkdir -p /mnt/dsk
mount /dev/md0 /mnt/dsk

Now we'll grow the disk array

# Another disk, probably /dev/loop2 ($d)
dd bs=1M count=100 </dev/zero >/tmp/img.d
d=$(losetup --show --find /tmp/img.d)

# Add it as a spare
mdadm --add /dev/md0 $d

# Convert from RAID 1 to RAID 5
mdadm --grow /dev/md0 --level=raid5 --raid-devices=3

# See what is going on
cat /proc/mdstat

When you have confirmed to yourself that the process is indeed safe, you can repeat the process with your real disks. Do you have a backup?

a=/dev/sda b=/dev/sdb` d=/dev/sdd
0
2

Growing RAID1 to RAID5 works fine, (but you should still have backups just in case.)

sudo mdadm --add /dev/md0 /dev/sdd

This command would add /dev/sdd to your /dev/md0 RAID1 as a spare drive.

Other than mdadm metadata, nothing will be written to it (unless one of the other drives failed, so the spare would be used to restore redundancy).

sudo mdadm --grow /dev/md0 --level=raid5 --raid-devices=3

This command would grow your 2-disk RAID1 to a 3-disk RAID5. This process reshapes / relocates all data (from previous 2-drive mirror to 3-drive RAID5 layout). During this process, whatever was on /dev/sdd before will be overwritten by contents of /dev/md0. Data on device /dev/md0 won't change at all except for additional capacity once growing is done. You'll have to grow the filesystem to utilize the added capacity.

You can combine both commands into one:

mdadm --grow /dev/md0 --level=5 --raid-devices=3 --add /dev/sdd

In general, --grow is supposed to be safe and retain data. mdadm should warn you when trying to do dangerous operations (such as shrinking) or when additional steps are necessary (such as providing a backup file).

You lose data when you --create (like mkfs), or when too many drives --fail, or when messing with the member drives in other ways.

You'll also lose whatever is on /dev/sdd since you're growing your RAID with it, so /dev/sdd gets overwritten with whatever currently is on /dev/md0.

If --grow lost data, there would be no point in using it at all, you'd just --create a new one in the first place.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.