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:
Create a btrfs filesystem in each of them:
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.
)
)
The mount the first of the drives (the one containing the data I want to retain) using it's loopback device
The second drive can now be added.
)
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.
References
https://www.theinternetvagabond.com/2020/06/14/setting-up-btrfs.html