I've been experimenting with BTRFS and ZFS. Specifically, I have two identical drives, which I want to use as raid1 (mirror both drives). There is data on one of them, which I don't want to loose, so I have to add the second one to the raid.

Since I don't have much experience with both of these filesystems, I'm playing around with them using files as block devices. This allows practicing what I want to do without messing with my real drives or valuable data.

Here is how I got it to work with BTRFS. First, create a mountpoint and two 1GB files to be used as drives:

 mkdir mountpoint
 fallocate -l 1GB file1 
 fallocate -l 1GB file2

Create a btrfs filesystem in each of them:

 mkfs.btrfs ./file1
 mkfs.btrfs ./file2

At this point, we can already mount one of them as a filesystem the same way you would mount a real device, but adding a thes second one will fail with:

ERROR: ./file2 is not a block device

To prevent this, I set up loopback devices for both files. With losetup --all we can confirm that it worked and see which where used.

 losetup -f ./file1
 losetup -f ./file2

 losetup --all
/dev/loop1: [65026]:18350600 (/tmp/tmp.07BEcA3Cv2/file2)
/dev/loop0: [65026]:18350597 (/tmp/tmp.07BEcA3Cv2/file1)

The mount the first of the drives (the one containing the data I want to retain) using it's loopback device

 mount /dev/loop0 mountpoint

The second drive can now be added.

 btrfs device add /dev/loop1 mountpoint -f
Performing full device TRIM /dev/loop1 (953.67MiB) ...

The raid is now created, but not balanced yet. They are a raid0 though for now. That means the data and metadata is not yet replicated between the two files (drives). This can be done with this command, which might take a while depending on how big your drives are.

 btrfs balance -dconvert=raid1 -mconvert=raid1 ./mountpoint

References

https://www.theinternetvagabond.com/2020/06/14/setting-up-btrfs.html