Btrfs/System Root Guide

Converting to a btrfs Based System
This exercise is one example for re-basing a gentoo installation's root filesystem to use btrfs. In this case, the existing system is an mdadm based mirror set using two 2tb drives at /dev/sda and /dev/sdb. Two fresh 2tb drives have been added at /dev/sdc and /dev/sdd.

Existing Layout

 * Simple two way mdadm mirror (raid1)
 * 250mb /boot partition as ext3 with metadata=0.90
 * 75gb / partition as ext4 with metadata=0.90
 * 750gb /home partition as ext4 with metadata=1.2
 * 1tb+ /vm partition as ext4 with metadata=1.2

The use of the older metadata format for /boot and / partitions allows grub-0.97 to find and boot the system without needing to resort to an initial ram device.

grub.conf

fstab

New Layout

 * 250mb /boot partition as ext3 with metadata=0.90
 * 1.9gb+ btfs partition with raid1 metadata and data

We are keeping the /boot as a simple software mirror in order to stay with grub-0.97 and continue to avoid using an initial ram device. btrfs has been built into the kernel (not a module) along with lzo compression/decompression as that will be used to optimize space utilization and read performance on the system volumes. Likewise, the raid modules used by mdadm are also builtins.

kernel .config options

Note - Not all of the above lzo "hits" are applicable to the btrfs compression features. A number of the raid hits do not apply to mdadm.

Partitioning
cfdisk was used to partition /dev/sdc with the 250mb and remainder partitions by hand. sfdisk then can be used to apply the same scheme to /dev/sdd

partitioning

Setting up boot
Mirror Creation

The warning about /boot partition alignment might have been avoided with some more care with cfdisk. It will be interesting to see what happens when the btrfs filesystem is created. Grub must be installed on each of the new mirrors by hand as shown

/boot transfer

Transfer of /
We assume that a "hot" transfer of the system will be okay and thus do a remount of / to /mnt/rawroot to grab the basics without pulling in any additional baggage from /proc, udev and other mounts. The new btfs will have the rootfs as a subvolume. Other existing filesystem such as /home and /vm will become other subvolumes. We edit /etc/fstab on an interim basis to provide mountpoints for the new filesystem and its subvolumes. The compression and auto defragmentation features of btrfs may or may not be applicable for the underlying data. The lzo compressor has been turned off for /mnt/newdistfiles since it will be getting the contents of /usr/portage/distfiles where files are already compressed. The /mnt/newvm filesystem leaves out autodefrag as an option since it interferes with the performance of virtual machines and copy on write.

/etc/fstab additions

btrfs creation

We kick off the root fs transfer and come back after a cup of whatever.

root fs copy (roughly 30 mins)