I have a single disk that I want to create a Mirror of, Lets call this disk sda I have just bought another identicle size disk, which we can call sdb. sda and sdb have one partition called sda1 and sdb1 respectively.When creating a raid I don't want to wipe my sda clean and start again, I just want it to start mirroring with sdb. My train of thought was to do:mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=1 /dev/sda1... to create the array without sdb disk, then run something like (I'm thinking the following command out loud, because I am not sure how to achieve this step)mdadm /dev/md0 --add /dev/sdb1Note sdb1 is assumed to be formated similar to sda1Is this possible?
Can I create a software RAID 1 with one device
raid;mdadm;disk
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 missingmkfs -text3 /dev/md0Now, /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 rootmount /dev/md0 /mnt/bcd /mnt/a                    # or cd / if it's the root filesystemcp -dpRxv . /mnt/bEdit /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/sda1Since 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.