btrfs RAID1 boot

Installation


If you have an intel matrix equipped board (aka fakeraid) it's tempting to try and use it. However, recent Linux distros have issues  with dmraid and using admdm is currently hit or miss.


An alternative is to use btrfs right in the installer these days, then add additional disks post-install.


  • Layout a disk with two partitions. One for your install, and one for swap
  • Make the large partition btrfs and mount it as /
  • Proceed with the isntall

After installation, copy the partition to the second disk with 


sudo sfdisk -d /dev/sda > parts

sudo sfdisk  /dev/sdb < parts


Add the second disk and re-balance


sudo btrfs device add /dev/sdb1 / 

sudo btrfs balance start -dconvert=raid1 -mconvert=raid1 /


Edit your GRUB config so you can actually boot when you have a failed disk


sudo vim /etc/default/grub


#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

GRUB_CMDLINE_LINUX_DEFAULT="rootflags=degraded,subvol=@"


sudo grub-mkconfig -o /boot/grub/grub.cfg


Install grub again 


sudo grub-install /dev/sda

sudo grub-install /dev/sdb


You can now unplug one of your HDDs and the system will boot.



Recovering


If you unplug and then replug in a HDD for testing,  things will look normal. But be sure to run a scrub because the filesystem is inconsistent. Btrfs has no concept of a dirty volume and happily just adds the old disk back in again.  I _hope_ this is by design and the filesystem accommodates changes somehow intelligently.


sudo btrfs scrub start /


The proper way to do this with wondering what's going on is to delete the missing disk and rebalance


(Note: not actually tested this yet)

sudo btrfs device delete missing /mnt
sudo btrfs device add /dev/sdc1 /
btrfs fi balance /


Or possibly convert to non raid1 then back



Links


http://youarego.blogspot.com/2012/07/btrfs-mirroring-on-root.html

http://wiki.archlinux.org/index.php/Kernel_parameters#GRUB

Comments