How to create an external selfhealing btrfs USB HDD RAID 1 array?
The hardware is an external 2TB bus powered USB disk.
What I want is a RAID1 setup of 2x 1TB btrfs.
Is this possible? How?
__
Motivation
The motivation for me to use RAID1 btrfs is because I just read an article talking about how such a setup would repair corrupted files automatically when the checksum on one volume fails.
Example of what can happen with a .jpeg
by just flipping one bit (I used vim for this. :%!xxd -b
)
Solution 1:
This answer is a guide for showing how I got this going.
My setup is:
- 1 external USB drive (1 enclosure with 1 drive)
How to:
-
I created a GPT parition table with two equal sized primary btrfs partitions using
gparted
. Name the partitions whatever you want, the names will get lost anyway when creating the RAID. -
Get the device ids:
$ sudo btrfs filesystem show Label: none uuid: 607b4153-7aa9-444d-bc15-c5fe9038f255 Total devices 2 FS bytes used 28.00KB devid 1 size 1.82TB used 2.03GB path /dev/sdc *** Some devices missing Label: 'Max' uuid: b6647427-9f27-4157-b47b-77f74054b885 Total devices 1 FS bytes used 28.00KB devid 1 size 931.49GB used 2.04GB path /dev/sdc1 // first one Label: 'Moritz' uuid: d0eaf97d-249e-4b7c-88a5-b60cc2d489d9 Total devices 1 FS bytes used 28.00KB devid 1 size 931.49GB used 2.04GB path /dev/sdc2 // second one
-
Create the RAID:
$ sudo mkfs.btrfs -L RAID-Datensicherung -m raid1 -d raid1 /dev/sdc1 /dev/sdc2
-
Since you can't write to it yet, you need to become the owner of the new device and change the permissions. Mount the device in nautiilus or however and then:
$ cd /media $ sudo chown julien:julien RAID-Datensicherung $ sudo chmod 700 RAID-Datensicherung
- Once you unmount and remount the device again, you can copy files via drag-and-drop.
When mounting the device in nautilus two volumes show up, but only one of them will show as mounted.
Once you copy files to the disk from another external drive you'll see that write speed to the RAID volume is twice than the read speed from the other external device because of the raid mirroring.
I still have to find out how to check if the self-healing works and will update this answer accordingly.
Update 1
User @Oli is asking the related question about flipping just one bit. Just like him, I need to do this stealthy, i.e. no timestamps of my interaction or anything like that.
If you change one bit while the file-system is mounted, the change is registered and immediately mirrored. The changed/'corrupted' file is seen as a mere update - not as bitrot.
Solution 2:
I assume you use 2 external drives or 1 enclosure housing 2 or more drives. Theoretically it shouldn't matter if the devices are connected via USB or SATA, btrfs should be able to assemble the array once it finds the individual drives/partitions.
You should have a look at the btrfs kernel wiki. The first usecase seems to cover what you asked for:
mkfs.btrfs -m raid1 -d raid1 /dev/sda1 /dev/sdb1
But I'm not sure about the selfhealing part. I only know that from ZFS.