How To Convert An ext3/ext4 Root File System To btrfs On Ubuntu 12.10

ext3 and ext4 file systems can be converted to btrfs. For non-root file systems, this can be done online (i.e., without reboot), while for root file systems we need to boot into some kind of rescue system or Live CD. This guide explains how to convert an ext3 or ext4 root file system into btrfs on Ubuntu 12.10 and how to roll back to ext3/ext4 again if desired.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

I'm using a system here with one large / partition (i.e., no /boot partition) and without LVM. During initial installation, it was installed with the option Guided - Use entire disk. For different partition schemes, the procedure might differ.

My hard drive is named /dev/sda in this tutorial, my system partition is /dev/sda1.

I will use an Ubuntu 12.10 Desktop Live-CD as the rescue system throughout this tutorial.

I will show two ways of doing the conversion: one where we simply convert the system partition and change /etc/fstab, and one where we create the subvolumes @ and @home according to Ubuntu's btrfs partition layout (see https://help.ubuntu.com/community/btrfs) - this is slightly more complicated, but a must if you want to use apt-btrfs-snapshot which requires this subvolume layout.

A note for Ubuntu users:

Because we must run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing

sudo su

2 Install btrfs-tools

On the original system, before we boot into the rescue system, install btrfs-tools so that the package is available when we chroot to the system partition in the rescue system (it is possible that we don't have a network connection for installing the package when we are chrooted into the system partition in the rescue system, that's why we should install it now):

apt-get install btrfs-tools

Now we must boot into some kind of rescue system with btrfs support. For example, you can insert the Ubuntu 12.10 Desktop CD into the CD drive (make sure it has the same architecture - i386 or x86_64 - as this system) and reboot:

reboot

3 Doing A Simple Conversion (No @ And @home Subvolumes)

In the rescue system, log in as root. Make sure that btrfs-tools are installed:

As you see, there's now a folder called ext2_saved which contains an image of our system partition before the conversion (with the original ext3 or ext4 file system). This image can be used to do a rollback later on.

Comment out the old / partition line and add a new one. Replace the UUID with the UUID from the blkid output, then replace ext4 (or ext3) with btrfs, and finally replace the mount options (e.g. errors=remount-ro) with the string defaults:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
#UUID=ad50ef37-797d-44ea-a8fa-ae61abe4d00f / ext4 errors=remount-ro 0 1
UUID=63accb30-95b9-4268-ae1e-6d0ad3ef3a9d / btrfs defaults 0 1
# swap was on /dev/sda5 during installation
UUID=4dc578f3-c65c-4013-b643-72e70455b21b none swap sw 0 0