6

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)

enter image description here enter image description here

4

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.

  • Thanks, I'll look into this and share any news if I succeed. – king_julien Jan 16 '14 at 7:09
  • 1
    I've tried to get this working like ten times already in different ways. But I never managed to get write access to the raid volume and got weird error messages when trying to get there. Anyway, thanks for the link. – king_julien Jan 16 '14 at 8:21
  • 1
    I think I got it working after all: 1) sudo btrfs filesystem show to get the device names 2) sudo mkfs.btrfs -m raid1 -d raid1 /dev/sdd1 /dev/sdd2 3) Goto /media. A new volume has shown up. 4) sudo chown julien:julien 35b7e180-117c-4ecd-8852-d25c6cb724a8 5) sudo chmod 700 35b7e180-117c-4ecd-8852-d25c6cb724a8 6) Now unmount and remount the volume and you have write permissions in nautilus. – king_julien Jan 16 '14 at 9:15
  • When mounting the volume two disks show up, but if I click on either of them only the 'first' one is mounted. When I copy files to the disk, from another external drive I see that write speed to the RAID volume is twice than the read speed from the other external drive. This looks good. I still have to figure out how to rename the RAID volume and try to flip a bit to see if the auto-selfhealing works. – king_julien Jan 16 '14 at 9:19
  • 2
    As for self-healing: How to monitor BTRFS filesystem raid for errors – basic6 Feb 14 '17 at 12:35
5

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:

  1. 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.

    enter image description here

  2. 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
    
  3. Create the RAID:

    $ sudo mkfs.btrfs -L RAID-Datensicherung -m raid1 -d raid1 /dev/sdc1 /dev/sdc2
    
  4. 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
    
  5. 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.

enter image description here

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.

enter image description here

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.

  • 2
    Look at @Oli's question again. I answered about how to do an offline edit of a file to simulate on-disk corruption. – Jim Salter Feb 12 '14 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.