Installation instructions
安装说明

The Btrfs utility programs require the following libraries/tools to build:
Btrfs 实用程序需要以下库/工具才能构建:

  • libuuid - provided by util-linux, e2fsprogs/e2fslibs or libuuid
    libuuid - 由 util-linux、e2fsprogs/e2fslibs 或 libuuid 提供

  • libblkid - block device id library
    libblkid - 块设备 ID 库

  • liblzo2 - LZO data compression library
    liblzo2 - LZO 数据压缩库

  • zlib - ZLIB data compression library
    zlib - ZLIB 数据压缩库

  • libzstd - ZSTD data compression library version >= 1.0.0
    libzstd - ZSTD 数据压缩库版本 >= 1.0.0

For the btrfs-convert utility:
对于 btrfs-convert 实用程序:

  • e2fsprogs - ext2/ext3/ext4 file system libraries, or called e2fslibs
    e2fsprogs - ext2/ext3/ext4 文件系统库,或称为 e2fslibs

  • libreiserfscore - reiserfs file system library version >= 3.6.27
    libreiserfscore - reiserfs 文件系统库版本>= 3.6.27

Optionally, the checksums based on cryptographic hashes can be implemented by external libraries. Builtin implementations are provided in case the library dependencies are not desired.
可选地,基于加密哈希的校验和可以由外部库实现。如果不希望使用库依赖项,则提供内置实现。

  • libgcrypt >= 1.8.0

  • libsodium >= 1.0.4

  • libkcapi >= 1.0.0

  • Botan >= 2.19.0

  • OpenSSL >= 3.2.0

Optionally, multipath device detection requires libudev and running udev daemon, as it’s the only source of the path information. Static build has a fallback and does not need static version of libudev.
可选地,多路径设备检测需要 libudev 和运行 udev 守护程序,因为它是路径信息的唯一来源。静态构建具有回退,并且不需要 libudev 的静态版本。

  • libudev

For zoned device support, the system headers installed in /usr/include/linux must be 5.10 or newer.
对于分区设备支持,/usr/include/linux 中安装的系统头文件必须是 5.10 版本或更新版本。

Generating documentation:
生成文档:

  • sphinx

Please note that the package names may differ according to the distribution.
请注意,软件包名称可能根据发行版而有所不同。

Building from sources 从源代码构建 

To build from git sources you need to generate the configure script using the autotools:
要从 git 源代码构建,您需要使用 autotools 生成配置脚本:

$ ./autogen.sh

To build from the released tarballs:
从发布的 tarballs 构建:

$ ./configure $ make $ make install

To install the libbtrfsutil Python bindings:
安装 libbtrfsutil Python 绑定:

$ make install_python

You may disable building some parts like documentation, btrfs-convert or backtrace support. See ./configure --help for more.
您可以禁用构建一些部分,如文档、btrfs-convert 或回溯支持。有关更多信息,请参阅 ./configure --help。

Specific CFLAGS or LDFLAGS should be set like
应设置特定的 CFLAGS 或 LDFLAGS,例如

$ CFLAGS=… LDFLAGS=… ./configure --prefix=/usr

and not as arguments to make. You can specify additional flags to build via variables EXTRA_CFLAGS and EXTRA_LDFLAGS that get appended to the predefined values of the respective variables. There are further build tuning options documented in the Makefile.
而不是作为 make 的参数。您可以通过 EXTRA_CFLAGS 和 EXTRA_LDFLAGS 变量指定附加的构建标志,这些标志将附加到各自变量的预定义值上。在 Makefile 中还有进一步的构建调优选项记录。

$ make EXTRA_CFLAGS=-ggdb3

The build utilizes autotools, dependencies for generating the configure scripts are:
构建过程使用 autotools,生成 configure 脚本所需的依赖项为:

  • autoconf, autoheader

  • automake, aclocal automake,aclocal

  • pkg-config

Statically built binaries
静态构建的二进制文件

The makefiles are ready to let you build static binaries of the utilities. This may be handy in rescue environments. Your system has to provide static version of the libraries.
makefiles 已准备好,让您构建实用程序的静态二进制文件。这在救援环境中可能很方便。您的系统必须提供库的静态版本。

$ make static $ make btrfs.static $ make btrfs-convert.static

The resulting binaries have the ‘.static’ suffix, the intermediate object files do not conflict with the normal (dynamic) build.
生成的二进制文件具有“.static”后缀,中间目标文件与正常(动态)构建不冲突。

There are pre-built static binaries for download available at the latest release (under Assets), https://github.com/kdave/btrfs-progs/releases .
最新版本发布时提供了可下载的预构建静态二进制文件(在“资产”下),https://github.com/kdave/btrfs-progs/releases 。

All-in-one binary (busybox style)
一体化二进制文件(busybox 风格)

Since version 5.2 it’s possible to build a single binary that can act as other standalone tools, based on the file name:
从版本 5.2 开始,可以构建一个单一二进制文件,可以充当其他独立工具,基于文件名:

$ make btrfs.box $ mv btrfs.box btrfs $ ln -s btrfs mkfs.btrfs

The list of built-ins can be obtained by
内置列表可以通过以下方式获得

$ btrfs help --box

The basic set will always contain: mkfs.btrfs, btrfs-image, btrfs-convert.
基本集合始终包含:mkfs.btrfs、btrfs-image、btrfs-convert。

32bit build on 64bit host
64 位主机上的 32 位构建 

The combination of 32bit build on 64bit host could work but depends on the libraries that must provide the 32bit versions, or even 32bit static versions. This is fairly uncommon on contemporary distributions and building 32bit versions on a 32bit host is recommended.
在 64 位主机上进行 32 位构建的组合可能有效,但取决于必须提供 32 位版本或甚至 32 位静态版本的库。这在当代发行版中相当不常见,建议在 32 位主机上构建 32 位版本。

References: * https://btrfs.readthedocs.io * https://btrfs.wiki.kernel.org (outdated)
参考资料:* https://btrfs.readthedocs.io * https://btrfs.wiki.kernel.org(已过时)