Linux – Creating RAID0 with Existing and Empty Disk

centos7linuxraid0

I have a CentOS 7.7 server which has a vhd /dev/sdc mounted (format-type= btrfs); it contains data.

I attached a empty vhd to the VM, /dev/sdd (I didn't partition this disk using fdisk)

lsblk command lists the attached disk but no mount point.

used,
mdadm --create /dev/md0 --level 0 --raid-devices=2 --name=/data-disk /dev/sdc /dev/sdd

Output:

mdadm: cannot open /dev/sdc: Device or resource busy

Question:

  • Will the data from the disk /dev/sdc get wiped out when I try to create a RAID0 array?

  • I can issue umount /dev/sdc and issue the mdadm --create command, but is that a proper approach to do this.

=== in case of successful RAID0 creation ===

Below command would be executed:

mkfs.btrfs /dev/md0

Editing the /etc/fstab, with the uuid info

===

Trying to add two disks to RAID0, one is already setup as backup, which has data. The new one is attached, could see the disk using lsblk, but

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdc      8:32   0    100G  0 disk /cass_backup
sdd      8:48   0    100G  0 disk

df -h

/dev/sdc        100G  82G  20G  20% /data_disk

How does the distribution of data between mounted and unmounted disk done?
Do I need to mount the new one (/dev/sdd) first?

Best Answer

Transforming a single disk to a RAID0 array will break your filesystem. More precisely you would first need to carefully distribute the data of /dev/sdc onto both disks.

You can create a RAID1 array more easily, since RAID1 has identical data on both disks: cf. Converting a single drive system to RAID.

Fortunately you are using btrfs, which combines the power of a filesystem, RAID and LVM. So add the second disk to your btrfs and convert it to a RAID0 array.

Edit: In your case the conversion to RAID0 is as simple as: mounting your original btrfs filesystem (let say on /mnt). Expand the filesystem:

mount /dev/sdc /mnt
btrfs device add /dev/sdd /mnt
btrfs balance start -dconvert=raid0 -mconvert=raid0 /mnt

The data on /dev/sdd will be lost, but data from /dev/sdc will remain.

Related Topic