Table of Contents

BTRFS as root filesystem

System overview

  1. /dev/sda1 4.08GB ext4 “/” used 1.56GB, free 2.53GB
  2. /dev/sda2 10.91GB extended
    1. /dev/sda5 524MB swap
    2. /dev/sda6 10.40GB ext4 “/home” 321MB used, 10.09GB free

Boot from live-cd

Btrfs support is heavily developed in Linux Kernel. So do not use old kernel.

I was using gparted-live-0.22.0-1-amd64.iso (NOTE: to match your existing system architecture (i586, amd64, etc)) Which contains:

  1. Kernel 3.16.0-4-586
  2. btrfs utils version 3.17

Update to kernel 4

Edit /etc/apt/sources and add sid release

apt-get update
apt-get install linux-image-amd64
apt-get install btrfs-tools
update-initramfs -u

Check btrfs-tools version

/bin/btrfs version

Converting dirs into subvolumes

To make backups, snapshots, moving much easier and faster, every directory you want to backup by snapshot should be a subvolume. Also root filesystem should be created in separate subvolume not in btrfs root.

To distinguish volumes from directories we will use @ character at beginning of subvolume name. This is Ubuntu naming convention for subvolumes.

Proposed subvolumes structure (where / is BTRFS root)

Mount BTRFS filesystem (BTRFS root) to /mnt/btrfs.

root

subdirectories

fstab

Do not use errors=remount-ro option which is not valid for BTRFS. Example working fstab file:

/etc/fstab
UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63	/		btrfs		defaults,subvol=@,compress=no				0	0
UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63	/var		btrfs		defaults,subvol=@var,compress=no			0	0
UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63	/var/log	btrfs		defaults,subvol=@varlog,compress=no			0	0
UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63	/home		btrfs		defaults,subvol=@home,compress=no			0	0
UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63	/mnt/btrfs	btrfs		noauto,defaults,subvolid=5,compress=no			0	0

To prevent systemd to halt system during startup if device is not found (nofail and x-systemd.device-timeout):

/etc/fstab
UUID=<the_device_uuid> /mount/point btrfs nofail,x-systemd.device-timeout=10,noatime,compress=lzo,autodefrag 0 0

NOTE: do not use autodefrag - it consumes lots of cpu