The simple answer to the question in the title is "Yes". But what you really want to do is the next step, which is getting the existing data mirrored.
It's possible to convert the existing disk, but it's risky, as mentioned, due the the metadata location. Much better to create an empty (broken) mirror with the new disk and copy the existing data onto it. Then, if it doesn't work, you just boot back to the un-mirrored original.
First, initialize /dev/sdb1
as the new /dev/md0
with a missing drive and initialize the filesystem (I'm assuming ext3, but the choice is yours)
mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdb1 missing
mkfs -text3 /dev/md0
Now, /dev/sda1
is most likely your root file system (/
) so for safety you should do the next step from a live CD, rescue disk or other bootable system which can access both /dev/sda1
and /dev/md0
although I have successfully done this by dropping to single user mode.
Copy the entire contents of the filesystem on /dev/sda1
to /dev/md0
. For example:
mount /dev/sda1 /mnt/a # only do this if /dev/sda1 isn't mounted as root
mount /dev/md0 /mnt/b
cd /mnt/a # or "cd /" if it's the root filesystem
cp -dpRxv . /mnt/b
Edit /etc/fstab
or otherwise ensure that on the next boot, /dev/md0
is mounted instead of /dev/sda1
. Your system is probably set to boot from /dev/sda1
and the boot parameters probably specify this as the root device, so when rebooting you should manually change this so that the root is /dev/md0
(assuming /dev/sda1
was root). After reboot, check that/dev/md0
is now mounted (df
) and that it is running as a degraded mirror (cat /proc/mdstat
). Add /dev/sda1
to the array:
mdadm /dev/md0 --add /dev/sda1
Since the rebuild will overwrite /dev/sda1
, which metadata version you use is irrelevant. As always when making major changes, take a full backup (if possible) or at least ensure that anything which can't be recreated is safe.
You will need to regenerate your boot config to use /dev/md0
as root (if /dev/sda1
was root) and probably need to regenerate mdadm.conf
to ensure /dev/md0
is always started.
--add
, and you need to be careful, but it's not very complicated. See How to set up disk mirroring in Ubuntu? (I can't propose that question as a duplicate because of the new rules.)