Doc /

Using BTRFS RAID

Some details about BTRFS use, errors from the user and recovery from these errors.

System

Laptop (ASUS 550) with two ssd, one in a caddy (=do not boot).

RAID 1 mirror

My first goal was to make root system more solid. The initial install was 100Gb BTRFS partition.

Main doc source: https://btrfs.wiki.kernel.org/index.php/Using_Btrfs_with_Multiple_Devices#Adding_new_devices.

What I didn't make for sure at first: the /mnt at the end of the example only means that the command works on a mounted file system, here mounted on /mnt. It's possible to use these commands on root active system (running), then the line ends with "/" (no mnt).

In my case, I created a new 100Gb partition on the second ssd (caddy). Fort some reason, when the caddy is inserted the disk become /dev/sda (and the other sdb), so never use /dev in permanent file like fstab, as the caddy is removable. So the internal disk is either sda or sdb depending of the caddy presence. My two partition where /dev/sda2 (new) and /dev/sdb2 (/). The command become:

 btrfs device add /dev/sda2 /
 btrfs balance start -dconvert=raid1 -mconvert=raid1 /

May take some time. RAID 1 is mirror.

It's probably a good idea to run mkinitrd after this.

This did run a lot of time without problem.

Use "btrfs fi show" to see the two BTRFS partitions working together.

Clone

At some time I wanted to clone my disks with clonezilla (see elsewhere on this wiki). Clonezilla can't cope with RAID on two disks, so I had to break the RAID first. This is easy.

 btrfs device delete /dev/sdXY /

But there, I missed a detail: when breaking the RAID, I didn't get two identical disks but one OK and one garbage. Because I was a bit tired at the moment, I removed the /dev/sdb2 bootable partition and ended with unbootable system. This sent me on some bad decisions, recovered with some work time. Nothing lost.

So be kind enough to remove the unbootable part and keep the bootable one.

Recovering from error, BTRFS part

Finally not that difficult, once the problem was understood. Simply rebuild the RAID and remove the correct disk.

Could probably be done from a rescue system.

Mount the working non bootable partition. To know which, use "lsblk -f", the non working partition is shown as blank.

 mount /dev/sda2 /mnt

Add the empty (bootable) one:

 btrfs device add /dev/sdb2 /mnt
 btrfs filesystem balance /mnt

Then remove the non bootable one to keep the now bootable and working one.

 btrfs device remove /dev/sda2 /

Chance is you get a message

 error removing device '/dev/sda2': unable to go below two devices on raid1

and so convert to RAID 0

 btrfs balance start --force -mconvert=raid0 /mnt/2

This could probably be done on the first command (not tested).

And finally you get a bootable root.

Final fix

After some work on partitions, it may be that your partition system is not exactly the one you had at first. May be the /etc/fstab is no more right. If so you start on admin mode, and can go to fstab and, for example, comment out the problematic partitions that prevent booting.