How To Build and Install the Latest Version of btrfs-tools on Linux

Posted on in Categories , , , last updated November 2, 2015

Since Linux kernel version 2.6.29-rc1, Btrfs has been included in the mainline kernel. How do I download and build/compile the latest version of Btrfs on Linux?

Btrfs has two parts as follows:

  1. btrfs.ko – Kernel module (driver) for Linux. Usually located at /lib/modules/4.2.0/kernel/fs/btrfs/btrfs.ko and must be supported by Linux kernel.
  2. brtfs-tools – The sources of the userspace utilities.

The main Btrfs features

Btrfs (“Better FS”) is a new filesystem with powerful features similar to Sun/Oracle’s excellent ZFS. These include snapshots, multi-disk striping and mirroring (software RAID), checksums, incremental backup, and on-the-fly compression that can give a significant performance boost as well as save space. Btrfs appears to be the future of Linux filesystems. For more information see the official page here.

In this tutorial you will learn how to build and install the latest version of userspace utilities (brtfs-tools) on a Debian or Ubuntu Linux based server.

Use latest kernel with btrfs

Since Linux kernel v2.6.29-rc1, Btrfs has been included in the mainline kernel. I recommend that you use latest Linux kernel version to get most out of Btrfs. See how to compile the latest version of the Linux kernel on a Linux operating systems for more info.

Install required software

Type the following apt-get command to install build tools:
$ sudo apt-get install git install asciidoc xmlto --no-install-recommends
$ sudo apt-get install uuid-dev libattr1-dev zlib1g-dev libacl1-dev e2fslibs-dev libblkid-dev liblzo2-dev

Download the latest stable version of brtfs-tools

Type the following git command (no need to root till you compile and build brtfs-tools):
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
Sample outputs:

Fig.01: btrfs-progs git repository
Fig.01: btrfs-progs git repository

Build brtfs-tools

Type the following command for preparing a build for compilation and verifying functionality:
$ cd btrfs-progs
$ ./autogen.sh

Sample outputs:

Fig.02: buildconf in action
Fig.02: buildconf in action

Next type ‘./configure‘ and ‘make‘ to compile.
$ ./configure && make
Sample outputs:

checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
....
..
....
config.status: creating Documentation/Makefile
config.status: creating version.h
config.status: creating config.h
 
	btrfs-progs v4.2
 
	prefix:            /usr
	exec prefix:       ${prefix}
 
	bindir:            ${exec_prefix}/bin
	libdir:            ${exec_prefix}/lib
	includedir:        ${prefix}/include
 
	compiler:          gcc
	cflags:            -g -O1 -Wall -D_FORTIFY_SOURCE=2
	ldflags:           
 
	documentation:     yes
	backtrace support: yes
	btrfs-convert:     yes
 
	Type 'make' to compile.
 
    [CC]     ctree.o
    [CC]     disk-io.o
    [CC]     radix-tree.o
....
...
    [ASCII]  btrfs-property.xml
    [XMLTO]  btrfs-property.8
    [GZ]     btrfs-property.8.gz
rm btrfs-quota.8 btrfs-balance.xml btrfs-restore.xml btrfs-scrub.8 mkfs.btrfs.8 btrfs-check.8 btrfs-map-logical.8 btrfs-select-super.xml btrfs-scrub.xml mkfs.btrfs.xml btrfs-map-logical.xml btrfs-inspect-internal.8 btrfs-debug-tree.8 btrfs-inspect-internal.xml btrfs-debug-tree.xml btrfs-filesystem.8 fsck.btrfs.8 btrfs-filesystem.xml btrfs-convert.xml btrfs-replace.8 btrfstune.xml fsck.btrfs.xml btrfs-show-super.8 btrfs-replace.xml btrfs-show-super.xml btrfs-quota.xml btrfs-send.xml btrfs.xml btrfs-device.8 btrfs-image.8 btrfs-convert.8 btrfs-device.xml btrfs-image.xml btrfs-mount.5 btrfs-select-super.8 btrfs-rescue.8 btrfs-check.xml btrfs.8 btrfs-qgroup.8 btrfs-rescue.xml btrfs-mount.xml btrfs-qgroup.xml btrfs-property.8 btrfs-subvolume.8 btrfs-property.xml btrfs-restore.8 btrfstune.8 btrfs-receive.8 btrfs-subvolume.xml btrfs-receive.xml btrfs-find-root.8 btrfs-send.8 btrfs-find-root.xml btrfs-balance.8

Installation

First, make sure older version is removed from your system:
$ sudo apt-get --purge remove btrfs-tools
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-compiler-gcc-4.8-x86 linux-headers-3.16.0-4-amd64 linux-headers-3.16.0-4-common linux-kbuild-3.16
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  btrfs-tools*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 3,099 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 154332 files and directories currently installed.)
Removing btrfs-tools (3.17-1.1) ...
update-initramfs: deferring update (trigger activated)
Purging configuration files for btrfs-tools (3.17-1.1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for initramfs-tools (0.120) ...
update-initramfs: Generating /boot/initrd.img-4.2.0
Processing triggers for libc-bin (2.19-18+deb8u1) ...

Finally, install the latest version, enter:
$ sudo make install
Sample outputs:

    [LN]     libbtrfs.so.0
    [LN]     libbtrfs.so
    [LD]     libbtrfs.so.0.1
Making install in Documentation
/usr/bin/install -c -d -m 755 /usr/share/man/man5
/usr/bin/install -c -d -m 755 /usr/share/man/man8
/usr/bin/install -c -m 644 btrfs-mount.5.gz /usr/share/man/man5
# the source file name of btrfs.5 clashes with section 8 page, but we
# want to keep the code generic
/bin/mv /usr/share/man/man5/btrfs-mount.5.gz /usr/share/man/man5/btrfs.5.gz
/usr/bin/install -c -m 644 btrfs.8.gz btrfs-convert.8.gz btrfs-debug-tree.8.gz btrfs-find-root.8.gz btrfs-image.8.gz btrfs-map-logical.8.gz btrfs-show-super.8.gz btrfs-select-super.8.gz btrfstune.8.gz fsck.btrfs.8.gz mkfs.btrfs.8.gz btrfs-subvolume.8.gz btrfs-filesystem.8.gz btrfs-balance.8.gz btrfs-device.8.gz btrfs-scrub.8.gz btrfs-check.8.gz btrfs-rescue.8.gz btrfs-inspect-internal.8.gz btrfs-send.8.gz btrfs-receive.8.gz btrfs-quota.8.gz btrfs-qgroup.8.gz btrfs-replace.8.gz btrfs-restore.8.gz btrfs-property.8.gz /usr/share/man/man8
ln -s -f btrfs-check.8.gz /usr/share/man/man8/btrfsck.8.gz
ln -s -f btrfs-rescue.8.gz /usr/share/man/man8/btrfs-zero-log.8.gz
/usr/bin/install -c -m755 -d /usr/bin
/usr/bin/install -c btrfs mkfs.btrfs btrfs-debug-tree btrfs-map-logical btrfs-image btrfs-zero-log btrfs-find-root btrfstune btrfs-show-super btrfs-select-super btrfs-convert /usr/bin
/usr/bin/install -c fsck.btrfs /usr/bin
# btrfsck is a link to btrfs in the src tree, make it so for installed file as well
ln -s -f btrfs /usr/bin/btrfsck
/usr/bin/install -c -m755 -d /usr/lib
/usr/bin/install -c libbtrfs.so.0.1 libbtrfs.a /usr/lib
cp -a libbtrfs.so.0 libbtrfs.so /usr/lib
/usr/bin/install -c -m755 -d /usr/include/btrfs
/usr/bin/install -c -m644 send-stream.h send-utils.h send.h rbtree.h btrfs-list.h crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h extent_io.h ioctl.h ctree.h btrfsck.h version.h /usr/include/btrfs

Verification

To see version info, enter:
$ btrfs version
Sample outputs:

btrfs-progs v4.2

Here is my Linux kernel version:
$ uname -mrs
Sample outputs:

Linux 4.2.0 x86_64

What next?

See how to create btrfs device and use it on Linux based system.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

4 comment

  1. Thanks for this overview, Vivek.

    BTW, I am surprised to see that such a basic system function has to be manually installed.
    I wonder why Debian, for instance, has no standard package for btrfs.

    Do you happen to know why?

    __Philippe

    1. Philippe,

      Debian has pretty old package called btrfs-tools v3.19 (or may be older version). There is no support for Debian v7.x. Same with Ubuntu LTS. Btrfs is pretty much stable with 4.x series kernel and btrfs-tools v4.x. Upcoming Debian 9.x/CentOS 8.x will have stable updated 4.x kernel and BTRFS tools.

      HTH.

  2. Is It possible to leave package btrfs-tools? or install on it.. ?

    by accident I install once again btrfs-tools with openmediavoult on previously installed btrfs-tools from surceases but btrfs version still reports v4.9.1

    apt-get is hard to force to install another packages (openmediavoult) without btrfs-tools…

Leave a Comment