Wednesday, May 18, 2011

Mirrored / (root) btrfs on Ubuntu 11.04

btrfs (Pronounced "Butter FS") is a new, copy-on-write (COW) filesystem for Linux.  It includes advanced features such as subvolumes, writable snapshots, and integrated, multi-device support.  See the btrfs site for a complete feature list and documentation (which was used during this setup).

I do not recommend using btrfs on a production system, as it is under heavy development, does not have a utility to repair filesystem errors, and could use some performance improvement.   However, I wanted to test and follow the development progress, so I am using it on a system where data loss is not a concern.  I also wanted to use btrf's multi-device support on root.  My installation process:
  • Boot from an Ubuntu 11.04 installation/Live CD. 
  • Select Try Ubuntu
  • Once the loaded, double-click the desktop icon Install Ubuntu 11.04
  • Select appropriate settings language and packages
  • For Allocate drive space, select Something else
  • Create a new partition table on your first drive
    • Click Add... to add partition
    • Type for the new partition: Primary
    • New partition size in megabytes: [preferably 8589 or more MB]
    • Use as: btrfs journaling filesystem 
    • Mount point: /
  • Create additional partitions as desired, for swap space, data that you want to reside on a more filesystem, etc.
  • Click Install Now
Once it has finished partitioning, open a terminal (Applications -> Accessories -> Terminal). Stop the installation, copy the partition table from the first drive to the second (my example: first = /dev/sda, second = /dev/sdb), and create the btrfs filesystem on / (my example: partition 1) with raid1 for both metadata and data:

$ sudo su
# pkill ubiquity
# sfdisk -d /dev/sda | sed -e s/sda/sdb/ | sfdisk --force /dev/sdb
# mkfs.btrfs -m raid1 -d raid1 /dev/sda1 /dev/sdb1
# exit

Note: Please be careful with the device names and partitions as to not destroy information on other disks and partitions you may have!

Restart the installation, and proceed using the first drive (be sure to not reformat!).  btrfs will mount and mirror regardless of the device selected as the target root.  Following the installation and initial reboot, install grub on the second harddrive so it will boot when the first drive fails:

$ sudo grub-install /dev/sdb
$ exit

Have fun testing snapshots, subvolumes, and more!

1 comments:

  1. u dont need to re-install the os
    do the step above
    just put two drives into the system, and copy everything to the btrfs
    drives
    $ sudo su
    # pkill ubiquity
    # sfdisk -d /dev/sda | sed -e s/sda/sdb/ | sfdisk --force /dev/sdb
    # mkfs.btrfs -m raid1 -d raid1 /dev/sda1 /dev/sdb1
    # exit
    mount the filesystem now to a temporary dir
    mount /dev/sda /tmp/mntroot
    rsync -auHxv --exclude=/proc/* --exclude=/sys/* --exclude=/tmp/* /* /tmp/mntroot

    isntall grub on Btrfs
    sudo grub-install /dev/sda
    sudo grub-install /dev/sdb
    on both drives because if one fails at start you are not able to start the machine
    reboot and type e to edit the grub lines
    on set=root use the btrfs uuid the same uuid on the root= line
    then type b to boot from your btrfs drives
    after startin up type update-grub
    that will make your machine booting permanent from it
    i recommend to use two separate partitions for swap, a raid0 one, it doesnt make sense to mirror swap

    ReplyDelete